## What Is Function Calling?
Function calling lets AI models request the execution of external functions, bridging the gap between language understanding and real-world actions.
### The Function Calling Loop
- Define — Describe available functions with JSON Schema
- Generate — The model decides which function(s) to call and with what arguments
- Execute — Your code runs the actual function
- Return — Send the result back to the model
- Respond — The model incorporates the result into its response
### Schema Design
Good schemas are the foundation of reliable function calling:
```json { "name": "search_products", "description": "Search the product catalog by name, category, or price range. Returns matching products with details.", "parameters": { "type": "object", "properties": { "query": { "type": "string", "description": "Search term or product name" }, "category": { "type": "string", "enum": ["electronics", "clothing", "books", "home"] }, "min_price": { "type": "number", "description": "Minimum price in USD" }, "max_price": { "type": "number", "description": "Maximum price in USD" }, "in_stock": { "type": "boolean", "default": true } }, "required": ["query"] } } ```
### Description Best Practices
- Be specific about what the function does and returns
- Include example values in parameter descriptions
- Document edge cases and limitations
- Use enums to constrain values wherever possible