Function schema
You describe each tool with a name, a description and a JSON schema for its parameters.
Last updated
Analogy
An OpenAPI spec for one endpoint, written for a model instead of a frontend dev.
Code example
const tools = [{ type: "function", function: { name: "getOrder", description: "Get an order's status by order ID", parameters: { type: "object", properties: { id: { type: "string" } }, required: ["id"], }, },}];In an agent
The schema tells the agent exactly which arguments to produce, so your code receives predictable input.
Practice
Interview questions
- How does function / tool calling work?
- Describe each tool with a name, a description and a JSON schema for its parameters.
- The model returns which tool to call and with what arguments. It never executes code itself.
- Your code validates the arguments, runs the function, and sends the result back as a tool message.
- The model then continues with the result in context.
Questions people ask
How do I describe a function for OpenAI tool calling?
Give each tool a type of function, a name, a description, and a parameters object written as JSON schema: the property names, their types and which ones are required. The model uses this to decide when to call the tool and to produce arguments in exactly the shape your code expects.
Can I write tool schemas with Zod instead of raw JSON schema?
Yes. Libraries such as LangChain's tool helper, and Zod's own JSON schema export, turn a Zod object into the JSON schema the model needs. The bonus is that the same Zod schema can then validate the arguments the model sends back, so you describe and check the input in one place.