Function calling (or tool use) lets a language model request that your code run a function, such as looking up an order or checking the weather.
How It Works
- You describe available tools with names, descriptions and JSON Schema parameters.
- The model decides whether a tool would help and returns a structured tool call with arguments.
- Your code executes the function.
- You send the result back, and the model uses it to continue.
Best Practices
- Write clear tool descriptions, including when to use each tool.
- Use precise parameter schemas with enums and descriptions.
- Validate arguments before executing.
- Return concise, informative results and errors.
- Require confirmation before actions with side effects.
Controlling Tool Use
APIs often let you let the model decide, force a specific tool, or disable tools.
Parallel Calls
Models may request several tool calls at once; execute them concurrently when independent.
Structured Output
Function calling is also a reliable way to get structured data, even if the "tool" just records the output.
Security
Treat tool arguments as untrusted input, and limit what tools can do.