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. Chat Completions nests each function under function. Responses uses top-level name, description, and parameters fields on each function tool. Anthropic uses input_schema on /v1/messages. Responses also accepts free-form custom tools with type: "custom". Custom calls use custom_tool_call and custom_tool_call_output items instead of the function-call item types. Namespace tools group function or custom tools under type: "namespace"; namespaced function calls include a namespace field that must be preserved in later requests. For complete Responses function and custom tool loops, see the Responses API reference.
Last modified on October 5, 2026