Function calling is the mechanism that lets a model ask for code to be run.
You describe the functions available with a name, a purpose and a parameter schema.
The model reads those descriptions the way it reads any other part of the prompt.
When it judges one is needed, it returns a structured call rather than prose.
The call names the function and supplies the arguments as data.
Your code receives that, decides whether to run it, and runs it.
The result is fed back into the conversation and the model continues.
The model never executes anything, which is the important safety property.
Everything that actually happens goes through your code and your permissions.
The arguments are generated text and may be nonsense, so validate every one.
A model asked to delete records may produce a filter matching everything.
Schemas with enumerations, ranges and required fields catch much of that.
Return errors as readable text, since the model can often correct itself and retry.
This one mechanism is what separates a chat model from an agent.
It is also the surface where prompt injection turns into real-world action.