Objectives: LO-6.1, LO-6.2, LO-6.3
Prerequisites: Module 5, and the content blocks and cost formula from
Module 2
Time: about 6 hours: 2 for this reading, 2.5 for Lab 6, and 1.5 for the
practice
Totaling a repair estimate needs intermediate work before the answer; routing a plain ticket needs little. This module covers three ways to give a model room for that work and keep the result checkable. The first is thinking, with the effort setting that controls it. The second is an explanation in tagged sections, and the third is a chain of separate requests. In Lab 6 you choose an effort level and write an extractor that fails loudly. Then you build a three-step chain with a stand-in model and compute how its errors compound.
Why reasoning before the answer helps¶
Module 1 showed that a model writes one token at a time, and each token joins the context for the next. A model that writes its answer first commits to it before any intermediate work. A model that writes the steps first can use them when it writes the answer.
Wei and colleagues called those steps a chain of thought. They put a few worked examples with intermediate steps in the prompt, and large models did better on arithmetic, commonsense, and symbolic reasoning tasks. A model with 540 billion parameters, given eight such examples, reached state-of-the-art accuracy on GSM8K, a set of math word problems. The authors describe the ability as emerging in sufficiently large models.
Current Claude models do this work themselves. Anthropic’s
thinking documentation says that
when thinking is active, Claude works through the problem before answering, in thinking content
blocks that come before the text blocks. Thinking tokens are billed as output tokens, even when
the thinking text isn’t returned, and they count toward max_tokens.
On Claude Opus 5.5, Sonnet 5.5, and Haiku 5.5, a request with no thinking field gets adaptive
thinking: the model decides when and how much to think. On Opus 5.5 it can’t be turned off. The
Opus 5.5 migration guide
says that a request setting thinking: {"type": "disabled"} returns a 400 error, which means the
API rejects it. It also warns that code reading the answer from content[0] breaks, because a
thinking block can come first. Pick out the text blocks by type, as Module 2 did.
Worked example: what a thinking block costs¶
Here are the main fields of an illustrative response from Opus 5.5, in the documented shape. A person wrote it for this course; no model produced it.
{
"content": [
{"type": "thinking", "thinking": "", "signature": "..."},
{"type": "text", "text": "<answer>billing</answer>"},
],
"stop_reason": "end_turn",
"usage": {"input_tokens": 220, "output_tokens": 310},
}The thinking field is empty because current models default to display: "omitted"; the
signature holds an encrypted copy of the thinking, which later turns pass back unchanged. The
visible answer is a few tokens, yet usage reports 310 output tokens, almost all of them
thinking. At Opus 5.5’s $4 input and $20 output prices per million tokens, Module 2’s formula
gives
Output, mostly thinking, is 6,200 of those 7,080 millionths of a dollar. And
response["content"][0]["text"] raises a KeyError: the first block has no text.
Choose an effort level from measurements¶
Effort is a request setting, output_config.effort, that tells the model how many tokens to
spend on its response. Anthropic’s
effort documentation lists five
levels: low, medium, high, xhigh, and max. Opus 5.5 and Haiku 5.5 default to medium;
most other models, Sonnet 5.5 among them, default to high. The page also says:
Effort affects every output token: thinking, the answer’s text, and tool calls.
Effort is a signal, not a budget. At a lower level the model still thinks on hard problems, only less. The thinking page adds that
max_tokensis the strict limit.Measure on your own task. For Opus 5.5 and Sonnet 5.5, the page says to run an effort sweep on your own evaluations rather than reuse an earlier model’s setting.
To spend fewer thinking tokens on Opus 5.5, the migration guide says, lower the effort. Here is a request that sets effort:
request = {
"model": "claude-sonnet-5-5",
"max_tokens": 4000,
"output_config": {"effort": "medium"},
"messages": [{"role": "user", "content": "Total this work order: ..."}],
}An effort sweep is a small experiment. Write its rules before you see results, so you can’t pick the level you hoped for and then find a reason:
Write each requirement as a threshold, such as a minimum accuracy and a maximum median latency. Latency is the time to the full response; half the requests beat the median.
Write the rule for choosing among the levels that pass, such as least cost, with ties broken by lower latency.
Measure every level on the same labeled cases.
Drop each level that misses a threshold, then apply the rule. If none is left, report that. Then change the prompt, the model, or the requirement on purpose.
Worked example: effort for repair estimates¶
Handbook section H07 says a work order names the requested service and parts. Suppose a program asks Sonnet 5.5 to total each work order for the customer. The thresholds are a correct total on at least 95% of labeled work orders and a median latency of at most 6 seconds. The rule picks the cheapest level that meets both. The table is illustrative, written for the course; no model was measured. Each request has 800 input tokens, and the output tokens include thinking.
| Effort | Correct totals | Median latency | Output tokens per request | Cost per 1,000 requests |
|---|---|---|---|---|
low | 81% | 1.9 s | 150 | $3.10 |
medium | 93% | 3.8 s | 450 | $6.10 |
high | 96% | 5.2 s | 900 | $10.60 |
xhigh | 97% | 9.6 s | 2,000 | $21.60 |
The costs use Sonnet 5.5’s $2 input and $10 output prices: for high, one request costs
(800 × 2 + 900 × 10) / 1,000,000 = 0.0106 dollars.
lowandmediummiss the 95% floor.xhighis the most accurate, but its 9.6-second median misses the 6-second ceiling.highis the only level left, so the program uses it.
Two cautions remain. On 200 work orders, 96% and 93% are 192 and 186 correct; Module 7 shows how to tell whether a gap that size is real. And the measurements belong to one model and one prompt, so change either and the sweep runs again. Lab 6’s Exercise L6.1 applies these steps to another table, and practice Exercise P6.1 changes a requirement.
Ask for an explanation you can check¶
Sometimes you need to see why the model chose its answer: a reviewer must approve it, or a test failed. Two different things can answer “why”:
The model’s thinking stays in thinking blocks. The thinking page says their text is never the raw reasoning: with
display: "summarized"it is a summary, written by a different model.An explanation in the answer is text the model writes for the reader, in the form the prompt asks for.
Don’t ask a current model to copy its internal reasoning into the answer. Anthropic’s
refusals page lists
Opus 5.5, Sonnet 5.5, and Haiku 5.5 among the models that may refuse such a request, with
stop_reason "refusal" and stop_details.category "reasoning_extraction". A common trigger,
it says, is a <thinking> or <reasoning> section filled in before the answer. The page advises
asking instead for a short explanation or the evidence behind a result. Anthropic’s
prompting best practices
keep the older technique, reasoning written out before an <answer> section, as a fallback for
when thinking is off.
Worked example: evidence and an answer¶
Ticket T12 in data/tickets.json reads “The quote and the final charge differ,” and its label is
billing. A prompt that asks for checkable evidence:
Route the ticket to the queue that owns the customer's current request: repair, billing, or
account.
<ticket>The quote and the final charge differ</ticket>
Reply with exactly two sections and nothing else:
<evidence>the words from the ticket that decide the queue, copied exactly</evidence>
<answer>one queue name: repair, billing, or account</answer>An illustrative reply, written for the course:
<evidence>the final charge differ</evidence>
<answer>billing</answer>Code can check both parts: the evidence appears in the ticket, and the answer is a queue name that matches the label. A reviewer reads four words instead of guessing.
An extractor has a narrower job: find exactly one answer section and return its text. It should reject each of these illustrative replies:
| Reply | Why the extractor rejects it |
|---|---|
<evidence>…</evidence> and then Billing. | No answer section, so nothing is where code looks |
<answer> with only spaces before </answer> | The section is empty |
<answer>billing</answer> and later <answer>account</answer> | Code can’t tell which section the model meant |
<answer>billing with no closing tag | Unclosed, often because the reply hit max_tokens |
Fail loudly: raise an exception with a message, never return a guess. Suppose the extractor
returned "repair" whenever it found no answer. A malformed reply to a billing ticket would become
a well-formed wrong label. An evaluation would then count a content error and hide the format
problem, which Module 3 tracks separately. An exception lets the caller retry, log the reply, or
send the ticket to a person.
Check stop_reason before extracting, as Module 2 did. And extraction checks shape only:
<answer>account</answer> for T12 extracts cleanly and is wrong. Module 8’s structured outputs
can replace this parsing for a fixed output contract. Lab 6’s Exercise L6.2 builds the extractor,
and practice Exercise P6.2 asks you to break one.
Split a task into a chain¶
A chain is a sequence of requests in which each step’s output becomes part of the next step’s input. The prompting best practices say that with adaptive thinking, Claude handles most multistep reasoning in one request. Chaining still helps when you need to inspect intermediate outputs or enforce a fixed sequence of steps. Their most common pattern is self-correction: draft, review the draft against criteria, then refine. Each step is a separate call, so a program can log, evaluate, or branch between steps.
Give each step one job and its own output contract, such as an <answer> section. Keep data in
tags, as Module 4 did. Extract and check each output before the next step uses it. And pass
forward the original input along with the earlier results.
Worked example: a three-step approval request¶
Handbook section H07 says to ask for approval before adding any paid service. A work order reads: “Customer asked for a brake adjustment. The mechanic found a worn chain.” The shop wants a message asking the customer to approve a chain replacement.
Extract. Given the work order, list the requested and the additional services. Illustrative output:
<answer>requested: brake adjustment; additional: chain replacement</answer>.Draft. Given the work order, the policy, and step 1’s list, write the message.
Review. Given the work order, the policy, the list, and the draft, return
approved, orrejectedwith a reason.
Step 2’s prompt carries the original work order along with step 1’s result:
<work_order>Customer asked for a brake adjustment. The mechanic found a worn chain.</work_order>
<policy>Ask for approval before adding any paid service.</policy>
<services>requested: brake adjustment; additional: chain replacement</services>
Write a two-sentence message to the customer that asks them to approve each additional service.
Put the message in <answer> tags.Why does every step get the work order? Suppose step 1 misses the chain and lists no additional services. Step 2 writes a message that asks for nothing, and a review step that sees only the list and the draft finds them consistent. A review step that sees the work order can notice the worn chain and reject. Lab 6’s chain has the same shape with other steps: classify, draft, and check.
A chain also costs more. In an illustrative plan on Sonnet 5.5, one combined call takes 500 input
and 300 output tokens, for $0.004. The three steps take 500 and 40, 700 and 260, and 950 and 30,
because each resends the work order. Together they cost (2,150 × 2 + 330 × 10) / 1,000,000 =
$0.0076. The calls run one after another, so their latencies add too.
How errors compound¶
A chain is right only if every step is right. A step’s conditional success rate is the share of runs it gets right among the runs in which every earlier step was right. The chance that all steps are right is the product of those rates.
Worked example. Three steps succeed at conditional rates 0.98, 0.95, and 0.90. After step 1, 0.98 of runs are right; after step 2, 0.98 × 0.95 = 0.931; after step 3, 0.931 × 0.90 = 0.8379. The chain is right on about 84% of runs, less than its weakest step’s 90%.
The rates must be conditional. In a two-step chain, say step 1 is right 95% of the time. Step 2 is right 90% of the time after a correct step 1, and 20% after a wrong one, because the original input sometimes lets it recover. Over all runs, step 2 is right 0.95 × 0.90 + 0.05 × 0.20 = 0.865 of the time. Both steps are right 0.95 × 0.90 = 0.855 of the time. Multiplying the overall rates, 0.95 × 0.865 ≈ 0.822, is wrong, because step 2’s failures depend on step 1’s. To measure a conditional rate, give the step labeled inputs whose earlier steps are known to be right.
Now add a check that rejects 60% of bad runs and, for this example, accepts every good one. Of all runs, 1 − 0.8379 = 0.1621 are bad. The check rejects 0.1621 × 0.6 ≈ 0.097 of all runs, and 0.1621 × 0.4 ≈ 0.065 slip through. No run became correct: about 84% are still right, and about 10% now need a retry or a person. A real check also rejects some good runs, and Module 7 measures both rates. Lab 6’s Exercise L6.4 computes these numbers, and practice Exercises P6.3 and P6.4 apply them.
Common misconceptions¶
“More effort always gives better results.” It spends more tokens, which costs money and time. In the worked example,
xhighwas the most accurate and still failed: its 9.6-second median exceeded the 6-second ceiling. It also cost twice as much ashighfor one more point.“A
<thinking>section in the answer shows how the model decided.” Current models may refuse to write one, and thinking blocks never return the raw reasoning. Evidence can be checked: T12’s quoted words are in the ticket. An account of a decision can’t be checked that way.“If the extractor returns an answer, the answer is right.”
<answer>account</answer>for T12 extracts cleanly and sends a billing ticket to the wrong queue. Compare with the label too.“A chain is as reliable as its weakest step.” It is less reliable. Steps at 0.98, 0.95, and 0.90 give 0.8379, below 0.90, because each step’s failures add to the earlier ones.
“A check step fixes the errors it finds.” It turns some wrong results into rejected ones. In the worked example, none of the rejected 10% became right, and 6.5% of runs passed while wrong.
Summary¶
Writing intermediate steps before the answer helps on multistep tasks. Current Claude models do it in thinking blocks, which come before the text, are billed as output, and count toward
max_tokens.Effort sets how many tokens a response spends, thinking included. Write the requirements first, measure every level on the same labeled cases, and measure again for a new model or prompt.
Ask for evidence that can be checked against the input, not for the model’s internal reasoning, and put the final answer in its own tagged section.
Extract exactly one nonempty answer section and raise an exception otherwise. Extraction checks shape, not correctness.
A chain passes earlier results and the original input forward. Its all-correct rate is the product of conditional success rates, and a check turns some errors into rejections, not into correct results.
Self-check¶
Answer each question before you open its answer.
LO-6.1. What would rule out the high level in the worked example?
Answer
Any requirement it misses: a latency ceiling below 5.2 seconds, an accuracy floor above 96%, or a cost cap below
$10.60per 1,000 requests. Each would leave no level at all, becausehighis the only one that met both original requirements. The right report is then “no level qualifies”, not the nearest miss.LO-6.2. What if there are two final answer tags?
Answer
Reject the result as ambiguous by raising an exception. The two sections may disagree, and code can’t know which one the model meant, so taking the first would hide the problem.
LO-6.3. If a two-stage chain has conditional success rates 0.9 and 0.8, what is its all-correct rate?
Answer
0.9 × 0.8 = 0.72. Multiplying is right because 0.8 is the second stage’s rate on runs where the first stage was right.
LO-6.1. A response from Opus 5.5 shows a one-word answer but reports 400 output tokens. Is the count wrong?
Answer
No. Thinking tokens are billed as output even when the thinking text is omitted, so most of the 400 are thinking. To spend fewer, lower the effort.
LO-6.2, LO-6.3. A prompt for Sonnet 5.5 asks the model to fill in a
<reasoning>section before answering, and a chain’s review step sees only the draft. What would you change?Answer
Ask for the evidence behind the answer instead of its reasoning, because the model may refuse with the category
"reasoning_extraction". Give the review step the original input too: only the input shows what the draft should have said.
Further reading¶
Anthropic, Thinking. How thinking blocks appear in a response, what they cost, and which settings each model accepts.
Anthropic, Effort. The five levels, each model’s default, and where to start an effort sweep on each model.
Anthropic, Refusals and fallback. The
"reasoning_extraction"refusal, the prompts that trigger it, and what to ask for instead.Anthropic, Prompting best practices. Its sections on thinking and on chaining prompts give the current advice in one place.
Wei and colleagues, “Chain-of-Thought Prompting Elicits Reasoning in Large Language Models,” NeurIPS 2022, Wei & others (2022). The paper that named chain-of-thought prompting and measured its gains on arithmetic, commonsense, and symbolic reasoning tasks.
- Wei, J., & others. (2022). Chain-of-Thought Prompting Elicits Reasoning in Large Language Models. Advances in Neural Information Processing Systems (NeurIPS), 35. 10.52202/068431-1800