CONCEPT Separate the reasoning from the deliverable
Plain CoT (5.1) improves accuracy but leaves the reasoning mixed into the visible response.
That's fine when a human reads the whole thing — but in an application you usually want to ship the answer
and drop the scratch work. Structured CoT solves this: instruct Claude to do its reasoning
inside <thinking> tags and put the final result inside <answer> tags. Now the
two are on clearly labelled seams, so your code can parse out the answer and strip the reasoning.
CONCEPT Why XML tags specifically
Claude is trained to respect XML-style tags as structural delimiters, so a <thinking>…</thinking>
block is unambiguous to a regex or XML parser — far more robust than trying to guess where "the reasoning" ends
and "the answer" begins in free prose. The same tag discipline shows up in few-shot examples: wrap the reasoning
of each example in <thinking> and Claude generalizes that pattern to its own responses.
<answer> block. The <thinking> block is retained for debugging/logging but
never shown to the user.thinking parameter. Native extended thinking (5.3) returns reasoning
in separate content blocks you never have to tag or regex out. Don't conflate the two.DIAGRAM One response, two extraction paths
answer in <answer>'"] --> R["Model response
<thinking>…</thinking><answer>…</answer>"] R --> PARSE{"Parser splits
on tags"} PARSE -->|"<answer> block"| SHIP["🟢 Ship to user"] PARSE -->|"<thinking> block"| LOG["🔵 Log / debug only
(stripped from output)"] classDef ok fill:#d4edda,stroke:#28a745,color:#155724; classDef mid fill:#cfe2ff,stroke:#0d6efd,color:#084298; classDef gate fill:#ffe8cc,stroke:#ff9f40,color:#9a4a0a; class SHIP ok; class LOG mid; class PARSE gate;
CODE Prompt + extract the answer, drop the reasoning
The prompt fixes the output shape; a small parser reads the <answer> block and discards
the rest.
# Prompt tells Claude exactly where to reason and where to answer. system = """Solve the problem. Do all reasoning inside <thinking> tags. Put ONLY the final result inside <answer> tags. Nothing outside the tags.""" resp = client.messages.create( model="claude-opus-4-8", max_tokens=2000, system=system, messages=[{"role": "user", "content": "A train leaves at 2pm going 60mph..."}], ) text = resp.content[0].text # Strip the reasoning: keep only what's inside <answer>…</answer>. import re m = re.search(r"<answer>(.*?)</answer>", text, re.DOTALL) final = m.group(1).strip() if m else text # ship 'final'; log the thinking block
TRADE-OFFS Structured tags vs. plain CoT vs. native thinking
| Plain CoT (5.1) | Structured tags (5.2) | Extended thinking (5.3) | |
|---|---|---|---|
| Reasoning location | Mixed into response | In <thinking> in the response body | Separate thinking content blocks |
| How you strip it | Hard — no clean seam | Parse/regex the tags | Ignore the thinking blocks — already separate |
| Extra tokens billed | Yes (reasoning) | Yes (reasoning) | Yes (thinking tokens) |
| Requires prompt engineering | Yes | Yes (tag contract) | No — native thinking param |
EXAM TRAPS
<thinking> tags equal the native thinking feature. →
They're a prompting convention in the normal response. Native extended thinking uses the
thinking parameter and returns separate blocks.<thinking>/<answer>, or your parser will miss stray
preamble.PRACTICE
Q1 · Why wrap reasoning in <thinking> and the result in <answer>?
So the two are on labelled seams your code can parse. You extract the <answer>
block to ship and strip the <thinking> block from what the user sees — reasoning room for the
model, a clean deliverable for the app.
Q2 · Does the tag pattern stop the reasoning tokens from being billed?
No. The reasoning is still generated and billed as output tokens; the tags only make it easy to separate and discard from the shown response. To keep reasoning in dedicated blocks entirely, use native extended thinking (5.3).
Q3 · How is structured-tag CoT different from the thinking parameter?
Structured tags are prompted — reasoning lives in the normal response body inside XML
tags you defined. The thinking parameter is a native capability that returns reasoning in
separate thinking content blocks, no tagging or regex required.