Function Calling
Function calling is the ability of a language model to request execution of a predefined external function with structured arguments, instead of trying to answer from its own parameters alone.
Key takeaways
- Function calling lets models request external tool execution with structured arguments.
- The application validates, executes, and returns results; the model decides which tool to use.
- Schema quality directly determines call correctness and downstream reliability.
Function calling lets a developer describe external tools as schemas. When the model determines a tool is needed, it returns a structured call with the tool name and arguments. The application executes the function and feeds the result back to the model for the next step.
That single capability turns chat models into agents. The model does not need to know how to query a database, call an API, or run code. It only needs to recognize when those actions are useful and emit a correctly structured request. The application owns execution, retries, and error handling.
Think of it like this. Think of a concierge who cannot open doors or run errands directly, but can write precise instructions for staff who can. The concierge decides what is needed; the staff execute it.
How it works
The developer registers functions with JSON schemas describing names, parameters, and descriptions. At inference, the model may return a special structured response requesting one of those functions. The application validates the arguments, executes the function, and appends the result to the conversation. The model then continues with the new information.
Common mistakes
"Function calling is built into the model." The schema and execution are application responsibilities. "More tools is better." Too many tools confuse tool selection and raise latency. "The model validates arguments." Schemas guide generation; runtime code must still validate inputs.
Trade-offs
Enables reliable external actions, but requires disciplined schema design and robust execution wrappers. Great for structured workflows; risky when tool descriptions are ambiguous or side effects are irreversible.