Back to DocsRecipe

Function Calling

Give your model tools — let it decide when to fetch live data, query a database, or trigger an action. Function calling bridges structured outputs with real-world execution.

How it works

  1. 1Define a JSON schema describing each tool — name, parameters, and description.
  2. 2Send the schema alongside your prompt. The model returns a structured call request when it needs a tool.
  3. 3Execute the function in your runtime, feed the result back, and let the model compose the final answer.

Example schema

{
  "name": "get_weather",
  "description": "Fetch current weather",
  "parameters": {
    "type": "object",
    "properties": {
      "city": { "type": "string" }
    },
    "required": ["city"]
  }
}

Best practices

  • Keep tool descriptions short and unambiguous.
  • Validate all parameters before execution.
  • Return concise, structured results — the model handles prose.
  • Set a timeout on every external call to avoid hanging the pipeline.