Lesson 33.4 · 4 of 6 · 5 min read · Reviewed 24 Nov 2026
tool_choice: auto, any, a named tool, none
By the end, you can
- Pick the right tool_choice for a step.
- Use a forced tool to get structured output.
tool_choice controls whether Claude must, may or must not use tools on a given request.
| Value | What happens | Typical use |
|---|---|---|
{"type": "auto"} |
Claude decides whether to call a tool. This is the default when tools are present. | Assistants and agents |
{"type": "any"} |
Claude must call one of the provided tools, its choice. | A step that must take an action |
{"type": "tool", "name": "x"} |
Claude must call tool x. |
Structured extraction: define a tool whose schema is the output you want |
{"type": "none"} |
Claude may not call tools, even though they are defined. | A final summarising turn |
Forcing a tool for structured output
A common pattern: define a record_invoice tool whose input_schema is exactly the JSON you want, then set tool_choice to that tool. Claude’s “input” to the tool is your structured data. Chapter 14 builds on this with validation and retries.
Model support
Forced choice (any or a named tool) works on many models and you’ll see it in a lot of existing code and exam scenarios. The newest Claude models reject it with an error, and accept only auto and none. On those models:
- Use
autoand say plainly in the prompt which tool to call and when. - Mark the tool
strict: trueso its input always matches the schema. - If you only forced a tool to get JSON back, use structured outputsStructured outputs: Making a model return data that matches a defined schema, such as JSON with required fields and types. instead (chapter 14).
Check the model’s docs before relying on forced choice.
A trade-off
When a tool is forced, Claude goes straight to the call without writing explanatory text first. If you want reasoning before the action, leave tool_choice on auto and instruct the model in the prompt.
On other providers
The same three choices exist elsewhere under other names. OpenAI’s tool_choice takes auto, required, none, or one named function. Gemini’s function callingTool use: Letting a model call functions you define, by returning a structured request your code executes. config takes the modes AUTO, ANY (optionally limited to named functions) and NONE. Whether a model also accepts forcing alongside reasoning differs by model, so check the docs for the exact model.
Key points
- auto lets Claude decide; any forces some tool; tool forces a named tool; none forbids tools.
- Forcing a named tool is a reliable way to get structured output.
- Forcing skips Claude's free-text reasoning before the call, so use it deliberately.
Compare four tool_choice settings
See what auto, any, a named tool and none each do to the same request, including which ones the newest models reject.
You will have: A four-row table of stop reasons and the tools called under each tool_choice.
Steps
- Run the starter with auto only.
- Add any, a named save_note, and none.
- Run it and read each row.
- Note which setting you would use for a final summary turn, and which for structured extraction.
Done when
- auto calls get_weather.
- any and the named setting are rejected with a clear error, as on the newest Claude models.
- none ends with end_turn and calls no tools.
Open in the Playground No API key needed.
Starter code (Python)
# Send the same request with four tool_choice settings and compare what comes back.
# Like the newest Claude models, the simulator rejects "any" and named tools. Catch the error and read it.
import anthropic
client = anthropic.Anthropic()
tools = [
{"name": "get_weather", "description": "Current weather for one city. Use when asked about the weather now.",
"input_schema": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}},
{"name": "save_note", "description": "Save a short note for the user. Use only when they ask to remember something.",
"input_schema": {"type": "object", "properties": {"text": {"type": "string"}}, "required": ["text"]}},
]
choices = {
"auto": {"type": "auto"},
# TODO: add "any", a named tool {"type": "tool", "name": "save_note"}, and "none"
}
for label, choice in choices.items():
try:
r = client.messages.create(
model="claude-sonnet-5-5", max_tokens=300, tools=tools, tool_choice=choice,
messages=[{"role": "user", "content": "What's the weather in Paris?"}],
)
except anthropic.BadRequestError as e:
print(f"{label:<16} rejected: {str(e)[:70]}")
continue
called = [b.name for b in r.content if b.type == "tool_use"]
print(f"{label:<16} stop_reason={r.stop_reason:<9} tools called: {called or 'none'}")
Show a solution
# Send the same request with four tool_choice settings and compare what comes back.
# Like the newest Claude models, the simulator rejects "any" and named tools. Catch the error and read it.
import anthropic
client = anthropic.Anthropic()
tools = [
{"name": "get_weather", "description": "Current weather for one city. Use when asked about the weather now.",
"input_schema": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}},
{"name": "save_note", "description": "Save a short note for the user. Use only when they ask to remember something.",
"input_schema": {"type": "object", "properties": {"text": {"type": "string"}}, "required": ["text"]}},
]
choices = {
"auto": {"type": "auto"},
"any": {"type": "any"},
"named save_note": {"type": "tool", "name": "save_note"},
"none": {"type": "none"},
}
for label, choice in choices.items():
try:
r = client.messages.create(
model="claude-sonnet-5-5", max_tokens=300, tools=tools, tool_choice=choice,
messages=[{"role": "user", "content": "What's the weather in Paris?"}],
)
except anthropic.BadRequestError as e:
print(f"{label:<16} rejected: {str(e)[:70]}")
continue
called = [b.name for b in r.content if b.type == "tool_use"]
print(f"{label:<16} stop_reason={r.stop_reason:<9} tools called: {called or 'none'}")
Do it Force a tool for extraction in the Playground. No API key needed.