Function Schema
Why Function Schema Is Needed
Letting an Agent call a tool isn't about "writing code for the model," but about "telling the model what this tool does and how to use it."
The model doesn't read your code directly — it relies on the description you provide to determine:
- When this tool should be used
- What parameters to pass
- What format parameters should be in
Function Schema is this "user manual" — its quality directly determines whether Tool Calling is correct.
What Is Function Schema
One-line definition: Function Schema is a structured description of a tool's capabilities, serving as the "parameter contract" when the model calls a tool.
A typical Schema looks like this:
{
"name": "get_weather",
"description": "Query current weather for a specified city",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name, e.g., Beijing, Shanghai"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Temperature unit"
}
},
"required": ["city"]
}
}When the model sees this Schema, it knows:
- The tool is called
get_weatherand is for checking weather - The required parameter is
city unitcan only becelsiusorfahrenheit
How to Do It: How to Write Good Schema
Descriptions should clarify use cases: Don't just write "fetch data" — explain clearly when to use it.
Parameter names should be specific: city is better than input, invoice_id is better than id.
Only set truly necessary fields as required: otherwise the model is more likely to fail due to missing parameters.
Use enums when possible: clearly constrain finite options with enum.
Don't nest too deeply: deeper nested structures mean more errors from the model.
Remember this: Function Schema is primarily written for the model to read, not the program — its core value is helping the model accurately understand "when to use it, and how."
Related terms: Tool Calling
Related Products