Skip to main content
Tool calling lets a model request application-owned functions. Your code executes each request, validates the arguments, and sends the result back to the model.

OpenAI tool loop

Define tools in the Chat Completions format:
When the model requests a tool, finish_reason is tool_calls. Preserve the assistant message and return one tool message for every requested call.

Anthropic tool loop

Anthropic uses tool_use and tool_result content blocks:

Production rules

  • Treat model-generated arguments as untrusted input.
  • Validate arguments against the tool schema before execution.
  • Apply authentication and authorization in the tool implementation.
  • Set timeouts and output-size limits.
  • Require confirmation before destructive or high-impact actions.
  • Return concise, structured errors so the model can recover.
  • Execute calls in parallel only when they are independent.
Tool schemas follow the selected endpoint. Use OpenAI function definitions on /v1/chat/completions and Anthropic tools on /v1/messages.
Last modified on September 9, 2026