All guides

Function calling guide

Define tool schemas, validate arguments, and handle retries safely.

Intermediate13 min readMay 26, 2025
FunctionsReasoningTools
Key takeaways
  • Use strict schemas for every tool.
  • Validate and sanitize tool arguments.
  • Capture tool responses for audit logs.

Define tools with schemas

Write explicit JSON schemas so the model knows required fields, types, and enum values.

{
  "name": "create_ticket",
  "description": "Create a support ticket",
  "parameters": {
    "type": "object",
    "properties": {
      "title": { "type": "string" },
      "priority": { "type": "string", "enum": ["low", "medium", "high"] }
    },
    "required": ["title", "priority"]
  }
}

Validate arguments

Run schema validation before executing a tool. Reject or repair invalid inputs.

Use a retry policy

Retry tool calls with exponential backoff and clear error messages. Avoid infinite loops.