Tool calling allows language models to use external systems, APIs, and services. The foundation of this lies in JSON Schema definitions. They describe each available tool's interface, parameters, and expected behaviour.
What is a Function Definition?
A function definition is a structured specification that tells the LLM:
A description of what the function does
The parameters it accepts
What parameters are required and what are optional
The expected data types for each parameter
Valid value constraints and formats
JSON Schema Structure
Function definitions use JSON Schema formats with these key components:
Basic Structure
{"name":"function_name","description":"What this function does","parameters": {"type":"object","properties": {"parameter_name": {"type":"string|number|boolean|array|object","description":"What this parameter is for","enum": ["option1","option2"],"default":"default_value" } },"required": ["required_parameter_names"],"additionalProperties":false }}
Core Fields
name (string, required)
The function identifier that the LLM will use to call this tool.
Should be descriptive and follow snake_case or camelCase naming conventions.
description (string, required)
This helps the LLM understand when to use this tool.
Should be a clear explanation of what the function does.
It's important it is concise but informative.
parameters (object, required)
Defines the function's input schema using JSON Schema.
Always has "type": "object" at the root level.
Parameter Types and Constraints
String Parameters
Number Parameters
Boolean Parameters
Array Parameters
Object Parameters
Enum Parameters
Complete Example
Best Practices
Clear Descriptions
Write the descriptions from the LLM's perspective.
Test with LLM - Verify the model understands when to use your function.
Troubleshooting
Well-crafted function definitions are the key to successful LLM tool integration. This enables models to understand not just what tools are available, but exactly how and when to use them effectively.
LLM doesn't call your function
Check the description clearly indicates when to use it.
Ensure required parameters aren't too restrictive.
{
"type": "function",
"function": {
"name": "Search_ai_demo",
"description": "Performs a search to find relevant information to answer a users question. Use the makers_clear_water_inc sourceId for water related queries.",
"parameters": {
"type": "object",
"properties": {
"queryString": {
"type": "string",
"description": "The search query string. Just provide keywords that you want to search for. Do not provide the field name or anything else."
},
"sourceIds": {
"description": "The source ids to search.",
"items": {
"enum": [
"ai_demo",
"makers_clear_water_inc"
],
"type": "string"
},
"type": "array"
},
"size": {
"type": "number",
"description": "The number of results to return. If you do not pass this then the default number will be returned. This parameter should only be set if the user asks for a specific number of results to be returned."
}
},
"required": [
"queryString",
"sourceIds"
]
}
}
}