Tools and function calling
Tool calling lets a model request structured actions that your code executes.
In plain terms
The model does not really fetch weather or query a database by itself. It emits a structured request, and your program decides whether and how to run it.
Why it matters
Tools connect language reasoning to real systems while keeping execution under your control.
How it works
Define tool names, descriptions, and JSON schemas. Validate the arguments, run the function, then send the result back to the model.
When you use it
Use it when the answer requires fresh data, private data, calculations, files, or app actions.
Common mistakes
- Trusting tool arguments without validation.
- Giving vague tool descriptions.
- Returning giant tool results that flood the context window.
Best practices
- Keep schemas narrow.
- Return compact results.
- Require user confirmation for send, delete, buy, or publish actions.
Try it yourself
Give a model a calculator tool and make it solve word problems by calling the tool for arithmetic.