Module 2 · Reasoning techniques

Chain-of-thought and extended thinking

6 min read

A language model produces its answer token by token, without going back (lesson 1.1). If it must write the result of a three-step calculation from the very first token, it can only guess it. If it first writes the steps, each intermediate result becomes context for what follows: written reasoning is extra computation. That is the idea of chain-of-thought, and of its descendant built into recent models: extended thinking. This lesson measures it, then shows how to tune it with Claude.

The experiment

100 multi-step arithmetic problems, of four kinds, with verifiable integer answers:

Un entrepôt reçoit 36 cartons de 9 chaises chacun. 31 chaises sont abîmées et renvoyées.
Combien de chaises reste-t-il ?                                                     → 293
Un stock compte 614 mugs. Lundi on en vend 58, mardi 81, puis on reçoit une livraison qui
multiplie par 4 le stock restant. Combien de mugs y a-t-il ensuite ?                → 1900

(A warehouse receives 36 boxes of 9 chairs, 31 chairs are returned: how many are left? A stock of 614 mugs, minus 58 and 81 sold, then a delivery that multiplies the remaining stock by 4: how many now?) Three instructions added to the question:

DIRECT = "Réponds uniquement par le nombre final, sans aucune explication."
COT = ("Raisonne étape par étape en écrivant chaque calcul, puis donne la réponse finale sur la dernière ligne, "
       "sous la forme « Réponse : N ».")
STRUCTURED = ("Écris ton raisonnement entre les balises <raisonnement> et </raisonnement>, en posant chaque "
              "calcul, puis la réponse finale seule entre <reponse> et </reponse>.")

(Direct: "answer only with the final number, no explanation"; chain-of-thought: "reason step by step writing each calculation, then give the final answer on the last line as 'Réponse : N'"; structured: "write your reasoning between <raisonnement> tags, posing each calculation, then the final answer alone between <reponse> tags".)

InstructionAccuracyOutput tokensBoxes × chairs − damagedPercentage discountStock × deliveryDuration × quantity
Direct answer0.0040.000.000.000.00
Chain-of-thought0.601860.920.840.360.28
Structured reasoning0.731691.000.720.760.44

What these numbers say

Without reasoning, the model guesses. Not a single right answer out of a hundred: 83 instead of 131, 660 instead of 510. It is not a format problem — the output is indeed a number —, it is a calculation problem: the result of three operations cannot "come out" in one go.

Writing the steps changes everything: 60%. The gain comes from the short problems (two operations: 92%); problems with three or four operations, or that require converting hours into minutes, remain hard for a model of this size.

Structuring the reasoning adds 13 points, with slightly shorter answers. The tags cleanly separate the reasoning from the answer: the final answer is found without ambiguity, and the model seems to organize its steps better. On the stock problems (three operations), the structured version doubles the score.

The price is visible: 170 to 190 output tokens instead of 4. In production, these are billed tokens and response time — to be reserved for tasks that need them.

Extracting the answer

A free-form reasoning often ends with a sentence ("So there are 293 chairs left."). The code must find the answer reliably: that is the role of the imposed format ("Réponse : N", or the <reponse> tag).

def extract_answer(text: str) -> int | None:
    """La réponse finale : dans <reponse>, après « Réponse : », sinon le dernier nombre du texte."""
    for pattern in (r"<reponse>\s*(.*?)\s*</reponse>", r"[Rr]éponse\s*:\s*\**\s*([^\n]*)"):
        match = re.search(pattern, text, re.S)
        if match:
            text = match.group(1)
            break

Separating reasoning and answer has another advantage: you can show the answer to the user and keep the reasoning for review, without mixing them.

Extended thinking in Claude models

Recent models reason on their own, before answering, in a separate thinking space. With Claude Opus 5.5, this reasoning is always on and adaptive: the model decides how much effort to spend depending on the difficulty. You no longer set a token budget; you set an effort level:

response = client().messages.create(
    model=config.CLAUDE_MODEL,
    max_tokens=4000,
    ...
    output_config={"effort": effort},  # low | medium | high | xhigh | max
)
EffortUse
lowSimple, high-volume tasks: classification, extraction, routing
mediumOpus 5.5's default: most tasks
high, xhighLong reasoning, analysis of complex documents, hard code
maxThe hardest problems, when cost and latency matter little

Three practical consequences for your prompts:

  • No need to ask "think step by step" of a model that already reasons: set the effort. The chain-of-thought instruction remains useful for models without built-in reasoning (small models, older models), like the lab's.
  • The reasoning is not the answer: by default, the reasoning text is not returned on recent models (you can ask for a summary). If you need a readable justification, ask for it explicitly in the answer — for example "cite the passage that justifies your answer".
  • More effort costs more: thinking tokens are billed as output tokens. Measure on your task whether high actually brings anything over medium.

When reasoning does not help

Reasoning improves multi-step tasks: calculation, logic, analysis of conditions, planning. It helps little, or even hurts, on recognition tasks: classifying a ticket, extracting a name, translating a sentence. On those, it adds cost and latency, and sometimes errors (the model "overthinks" an obvious answer). The rule: measure with and without, on the real task.

Key takeaways

  • Written reasoning is computation: on multi-step problems, 0% without reasoning, 60% with it, 73% with structured reasoning.
  • Separate reasoning and answer (tags or "Réponse : N") to extract the answer reliably.
  • Reasoning multiplies output tokens by 40 here: reserve it for multi-step tasks.
  • With Claude Opus 5.5, reasoning is adaptive and set through output_config.effort, not through an instruction.
  • Measure: on recognition tasks, reasoning costs without adding anything.

Practice

  1. Run examples/02_reasoning.py and read three wrong reasonings: where is the error?
  2. Add an instruction "check each calculation before moving to the next" to the structured reasoning and measure the effect.
  3. With an API key, compare Claude's low, medium and high efforts on twenty problems: accuracy, tokens and duration.

Resources