25.8 Strict tool use or structured output
- Approved by
- Panaversity ·
In everyday life. In a restaurant, a waiter writes two kinds of paper. The order slip goes to the kitchen, and something is cooked because of it. The bill comes to your table at the end, and nothing is cooked because of it: it is a record of what happened. A waiter who wanted a written record would not send the kitchen an order for a dish nobody will eat.
What you will learn. You practice this in Lab 25, Task 3.
- What is the difference between strict tool use and a structured output?
- What happens when I force a tool?
- If I cannot force the tool, how do I know it was called?
- What does each choice cost?
Why it matters. The API can hold a shape in two places. Choose the wrong one on a current model, and every request is rejected.
At work. The extraction step now uses both kinds. When the model calls get_invoice, it is asking the portal's code to do something: fetch one invoice. When it returns the fields, it is handing over data for the due-date code. The builder has seen an older way to get the data, in tutorials. You define a tool whose inputs are the invoice's fields, force the model to call it, and read the inputs as the answer. The builder tries it on the lab's model, claude-sonnet-5-5, and the API rejects the request.
What is the difference between strict tool use and a structured output?
Strict tool use holds the inputs of a tool call, and a structured output holds the final answer. For strict tool use, you add "strict": true to the tool's definition, beside its name, description and input schema. The API then guarantees two things: the inputs follow the tool's schema, and the tool's name is always one you defined.1 21.2 taught it.
A structured output is 25.7's subject. The two are different features with different switches, and one request can use both.2
| You want | Use | What the API holds |
|---|---|---|
| The model to ask your code to do something: fetch, look up, write | Strict tool use: "strict": true on the tool | The tool's name and its inputs |
| The model's final answer as data your code will read | A structured output: output_config.format | The text of the final answer |
The schema of a structured output applies only to what the model writes as its answer. It does not apply to tool calls, to tool results or to the model's thinking.2 So the two do not overlap. In the extraction step, get_invoice is a strict tool, and the invoice's fields are a structured output.
Ask one question to choose: will something happen because of this JSON, or will code only read it? An action is a tool. Data is the answer.
What happens when I force a tool?
On current Claude models the API rejects the request. 21.2 taught tool choice. The models are Claude Fable 5.2, Claude Mythos 5.2, Claude Opus 5.5, Claude Sonnet 5.5, Claude Fable 5.1 and Claude Mythos 5.1. On these, a request whose tool choice is any or tool, the two values that force a call, returns a 400 error.3 The documentation says what to do on these models. Use auto with strict tool use, or use structured outputs when you need an answer in a fixed JSON shape.3
Other models, such as Claude Opus 5 and Claude Haiku 5.5, accept a forced tool, but a forced call skips thinking.3 There is one more case. With manual extended thinking, a setting where your request turns the model's thinking on and sets its size, any and tool are rejected too.3
You will still meet the old way. One of Anthropic's own cookbook examples for extracting JSON still forces a tool, on Claude Haiku 5.5, where it is accepted.4 Read such an example as written for the model it names.
If I cannot force the tool, how do I know it was called?
Your code checks. With auto, the model decides whether to call get_invoice. Anthropic's notes for Claude Haiku 5.5 name one risk. With thinking off, the model might skip a tool call it needs when an output format is also set.5 A person who read an answer would have asked "did you read the invoice?" The code asks the same thing on purpose: an answer that arrives with no get_invoice call before it is not accepted, and goes to needs_review. It is stopped at the first gate, the one that reads the stop reason. When the stop reason says the model has finished, the code looks for the call before it parses anything (25.10).
What does each choice cost?
- Strict tools and structured outputs share limits. A request may carry at most 20 strict tools, and a schema with many optional fields can be refused as too complex.2 The extraction's one tool and eight fields are far inside these limits.
autois a request, not an order. You pay for it with the check above.- Forcing, where it is accepted, costs the thinking. On a model such as Claude Haiku 5.5 a forced call is allowed and fair for a simple job. It also ties the code to that model, because a current model rejects the same request (above).
A strict get_invoice call always has a well-formed invoice number. Whether that invoice exists is for the tool's own code to check, as in 21.2. The same limit for the answer is 25.9's subject.
The operating rule: an action is a strict tool, and data is a structured output. Leave tool choice on auto, and let your code check that the tool was called.
Do this now. Ask your coding agent to find every forced tool in your code. Copy this line:
List every request our code sends to a model. For each, say which model it names, whether it sets a tool choice and to what, and whether it uses a tool only to get JSON back. Mark each request that would return a 400 error on claude-sonnet-5-5. Change nothing.
Check: for every marked request, say whether its JSON is an action or data. Each one that is data should become a structured output.
Check yourself
Question 1 / 7
0 answered
The extraction step calls get_invoice and then returns the invoice's fields. Which feature holds which?
Sources
- Owner
- Panaversity