Overview
Tool use, also called function calling or tool calling, lets a model ask for a function to be run and then continue from the result. You send tool definitions (name, description, input JSON Schema); the model returns a structured call, your code runs it, and you send back the output.
In the Claude API the call is a tool_use block (id, name, input) with stop_reason: "tool_use", and the output goes back as a tool_result block carrying the matching tool_use_id (set is_error: true on failure). In OpenAI’s Responses API the call is a function_call item and the output is a function_call_output item, both tied by call_id. Repeating this exchange until no call is requested is the agent-loop. Server tools such as web search run on the provider’s side.
Rules that matter:
- Validate arguments before executing; the caller owns permissions, rate limits, and logging.
- Set
strict: trueon the tool definition (Claude and OpenAI both support it) so arguments always match the schema. - Return all results from parallel calls in one user message.
- Return concise results and clear error text, never stack traces.
- Write narrow tools with precise descriptions; description quality decides which tool the model picks.
- Forced
tool_choice(anyor a named tool) returns a 400 on Claude Fable 5.1, Opus 5.5, and Sonnet 5.5; useautowith an instruction, or structured outputs.
Example
// Model emits:
{"type": "tool_use", "id": "toolu_01", "name": "get_weather", "input": {"city": "Oslo"}}
// Your code returns:
{"type": "tool_result", "tool_use_id": "toolu_01", "content": "Partly cloudy, 12 C"}Related
- tool-use-and-function-calling
- mcp-tool-design
- mcp
- structured-output
- agent-loop
- prompt-injection: tool results are untrusted input.