Function Schema
Definition
A JSON Schema definition that describes function parameters for LLM tool use, enabling models to generate properly formatted function calls.
A function schema is a JSON Schema definition that describes the parameters, types, and constraints of a function that an LLM can call, enabling reliable tool use in AI agents and applications.
Why It Matters
Function schemas bridge the gap between natural language understanding and structured function execution. They matter because:
- Type safety: Parameters have defined types (string, number, array, etc.)
- Validation: Required fields and constraints are enforced
- Documentation: Descriptions help the model understand when to use each function
- Reliability: Consistent argument format for downstream processing
Without proper schemas, LLMs might generate invalid function calls, missing parameters, or wrong types, breaking your application.
Implementation Basics
A function schema includes:
- Name: Unique identifier for the function
- Description: When and why to use this function
- Parameters: JSON Schema object defining arguments
- Required: Array of mandatory parameter names
Example schema:
{
"name": "search_products",
"description": "Search for products by query and optional filters",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "Search query text"
},
"category": {
"type": "string",
"enum": ["electronics", "clothing", "home"]
},
"max_price": {
"type": "number",
"description": "Maximum price in dollars"
}
},
"required": ["query"]
}
}
Best practices:
- Write clear descriptions for each parameter
- Use enums for categorical values
- Set sensible defaults for optional parameters
- Include examples in descriptions for complex types
Function schemas are the contract between your LLM and your application logic, so invest time in making them precise.
Source
Function calling allows you to describe functions to the model
https://platform.openai.com/docs/guides/function-calling