Back to guide
Markdown view
# Function calling guide

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

- Date: May 26, 2025
- Reading time: 13 min
- Level: Intermediate
- Tags: Functions, Reasoning, Tools

## 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.

```json
{
  "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.