The Anthropic tool shape
Anthropic tool definitions go in the tools array on the messages request. Each entry is a flat object with three fields: name, description, and input_schema. The schema itself is plain JSON Schema — Anthropic supports a broad subset.
FAQ
- What's different from OpenAI's shape?
- Anthropic uses
{ name, description, input_schema }— a flat object — while OpenAI wraps in{ type: "function", function: { ... } }. The schema body itself is identical JSON Schema. - Does Anthropic support strict / structured outputs?
- Anthropic's tool calls are strongly schema-guided but not labelled "strict" the way OpenAI does. The model produces JSON conforming to the schema with high reliability. For hard guarantees, validate the model output yourself with ajv or similar.
- How do I force the model to call a specific tool?
- Set
tool_choice: { type: "tool", name: "your_tool_name" }on the messages request. Useanyto force one of the tools, orauto(default) to let the model decide. - Where do tool results go?
- You append a
usermessage with content typetool_result, referencing the originaltool_use_id. See Anthropic's tool-use docs for the exact shape.
Common pitfalls
- Wrapping the schema as
{ "type": "function", "function": ... }— that\'s OpenAI\'s shape, not Anthropic\'s. - Forgetting that tool results are
usermessages withtool_resultcontent blocks, nottoolrole messages. - Skipping
description— Claude is heavily reliant on it for tool selection. - Naming tools with whitespace or starting with a digit; sticks to
[a-zA-Z0-9_].