Learn
Reasoning & coding

How do thinking tags work in reasoning models?

The short answer

A think block is a delimiter around a model's reasoning channel: the model writes working notes inside it and the final answer outside. It is a convention baked into a chat template, not a universal standard. Getting it right means matching the exact format the model was trained on and parsing it with a state machine rather than a regex.

On this page

What the marker really is

In a reasoning model the think marker is a boundary in the token stream. Everything between the opening and closing marker is reasoning; everything after it is the answer. The model is trained to respect that boundary, and the serving stack uses it to split a single generation into two channels: a reasoning channel and a content channel.

There is no single implementation. Some model families use literal text tokens — the characters for an opening angle bracket, the word think, a closing bracket — which the tokenizer treats like any other text. Others use dedicated special tokens with their own vocabulary ids, which cannot be produced by ordinary text and cannot be typed by a user. Others never expose the boundary to the model at all: the API returns a separate reasoning field and the raw tokens stay hidden.

This matters because the three are not interchangeable. A prompt that writes the literal characters is a no-op on a model whose reasoning channel is opened by a special token. A parser that looks for the literal string finds nothing in an API response that already separated the channels. Before writing code, work out which of the three you are dealing with.

Who writes the opening tag

In most chat templates the opening marker is not generated by the model. The template appends it after the user turn and marks that as the start of the assistant reply, so the model begins generating already inside the reasoning channel. Its first job is to reason; its first structural job is to emit the closing marker and then the answer.

This design is deliberate. A model that has to decide whether to open a reasoning block spends probability mass on a decision the application already made. Injecting the opener removes that choice, makes the format more reliable, and gives the serving stack a clean place to switch channels. It also means you cannot detect reasoning by looking for an opening tag in the output, because it was never generated. Look for the closing tag, or for the channel field.

Some templates support a soft switch instead. A token in the system or user message, or a template flag, decides whether the opener is injected at all. That gives you a per-request thinking toggle without changing models. The catch is that the switch only works if the template rendering your prompt is the one the model was trained with; pass a flag to a server that ignores it and you get a thinking response when you asked for a direct one.

Chat templates and the exact format

A chat template is a small program, usually Jinja, stored with the tokenizer. It turns a list of role-tagged messages into the exact token sequence the model expects: role headers, separators and any reasoning markers. Serving frameworks render it for you, but they render whatever copy they have, which is not always the copy the model shipped with.

The failure mode is quiet. If the template is wrong the model still produces fluent text, so nothing looks broken; accuracy just drops, instruction following weakens, and the reasoning channel may never open. When a self-hosted reasoning model underperforms its published numbers, a mismatched template is one of the first things to check. Compare the rendered prompt against the model card character by character, including whitespace and newlines.

The practical rule: pin the tokenizer and template with the weights, render one sample prompt at startup, and log it once. If the model card shows the expected rendering, diff against it. Do this before tuning anything else, because every later measurement is contaminated if the format is off.

A rendered conversation typically looks like a role header, the user text, an end-of-turn marker, an assistant header, and then the injected reasoning opener. Every one of those pieces is a place where a template can differ: an extra newline before the opener, a different end-of-turn token, a missing space. None of them raise an error, and all of them shift the distribution the model was trained on.

Parsing it in production

The naive parser is a regular expression that captures everything between the markers. It works in a notebook and fails in production for predictable reasons.

  • Split the stream with a state machine, not a regex. Track whether you are inside or outside the reasoning block and emit deltas per channel; a regex applied to each chunk cannot match a marker that arrives in two pieces.
  • Handle a missing closing tag. Truncated generations, token limits and model errors all produce traces that end mid-thought, and the parser should fall back to treating the remainder as reasoning rather than dropping it.
  • Handle text before the opening marker. Some models emit a stray newline or a short preamble first, so strip leading whitespace instead of assuming the response starts with the tag.
  • Handle more than one block. Agentic turns can contain several reasoning segments interleaved with tool calls, so loop rather than splitting once.
  • Never let the marker reach the user. Strip the delimiters from both channels and normalise the whitespace where the boundary was.
  • Keep the raw response. Store it next to the parsed channels so a parser bug can be diagnosed without re-running the request.

Streaming two channels

Users judge latency by the first useful token, and a reasoning model may spend a long time before it produces one. The usual fix is to stream the reasoning channel into a collapsed panel or a status line while the answer streams into the main surface. That turns a dead wait into visible progress, and it costs nothing in tokens.

Implementation details matter more than they look. Send distinct event types for reasoning and content so the client does not have to parse text to decide where to put it. Emit a boundary event when the channel switches rather than relying on the absence of a field. Keep the connection alive during long tool calls with heartbeat events, because proxies and load balancers close idle streams. And buffer the first few characters of the answer until you know they are not a stray marker.

If you do not want to show reasoning, do not stream it, but do not wait silently either. A spinner with an elapsed timer and a cancel button is honest. The cancel path has to actually stop generation server-side; closing the client connection is not always enough, and a runaway trace keeps costing money after the tab is gone.

What to log, and what to hide

Reasoning text is model output conditioned on everything in the context. That means it can echo a customer's email address, repeat a fragment of the system prompt, quote an API key that appeared in a tool result, or speculate about a person in terms you would not want in a support ticket. Treat it as sensitive by default.

Decide retention before launch, not after. The common pattern is to keep the final answer indefinitely and the trace for a short window — long enough to debug a complaint, short enough to limit exposure. If you need traces for evaluation, store them separately with a different retention period and access rule, and redact obvious identifiers on write.

There is a compliance angle too. A trace can contain the reasoning behind a refusal or an approval, which is exactly what an auditor wants and exactly what an attacker wants. Log access to traces, and never include them in a public error message or a client-side bundle.

Sampling beats storing everything. Keep a small random share of traces for quality review, hash the rest for counts, and give engineers a time-boxed path to retrieve one specific trace when a user reports a problem. That preserves the debugging ability without turning the trace store into a liability.

Why separate channels are worth the trouble

Separation makes evaluation tractable. You can score the answer with an exact match or a unit test, and score the trace with a rubric, without one contaminating the other. You can compare accuracy with thinking on and off on the same harness, which is the only honest way to decide whether the feature earns its cost.

It also makes distillation possible. A trace is a training target: capture successful reasoning from a large model, filter it by whether the final answer was correct, and fine-tune a smaller model on the pairs. The channel boundary is what lets a pipeline treat the two halves differently — keep the answer as supervision, keep the trace as the thing being imitated.

And it makes product decisions possible. Some surfaces should show reasoning, such as a debugging assistant or a maths tutor; some should show a summary; some should show nothing. A single undifferentiated string forces the same choice everywhere.

Visibility also affects trust. A short summary of what the model considered reads as competence; a raw three-thousand-token trace reads as malfunction to most users, even when the answer is right. The channel boundary lets you choose the level of detail per audience instead of shipping whatever the model happened to emit.

Reasoning across tool calls

In an agent loop, reasoning does not stop at the first tool call. The model thinks, calls a function, reads the result, thinks again, and eventually answers. Each of those segments may be a separate block, and the conversation history grows with both the reasoning and the observations.

Providers differ on what to do with old reasoning. Some require the blocks from the current assistant turn to be passed back verbatim, signatures intact, or they reject the request. Others ignore reasoning in history and in some cases error if you send it. Some bill for it again on every turn. Read the provider's rules before building a loop, and keep the raw assistant message so you can replay it in the shape the API expects.

There is a cost decision hiding here. Carrying every trace forward can double or triple the prompt on a long session. Dropping it loses continuity and can make the agent repeat work. A workable middle ground is to keep the last turn's reasoning plus a short summary of earlier decisions, treating the summary as part of the task state rather than as model output.

Common mistakes

  • Assuming the tag is universal. Model families use different markers, token ids and template flags; copy the format from the model card, not from a post about a different model.
  • Splitting on the first closing tag and stopping there, which breaks on multiple blocks and on traces that mention the marker in their own text.
  • Losing the answer when the closing tag never appears, because the parser only reads what follows the tag.
  • Prompting a non-reasoning model with think tags and expecting reasoning-model behaviour. You get the costume, not the capability.
  • Concluding that the model is broken because the output has no opening tag, when the template was supposed to inject it.
  • Counting reasoning tokens as free. They are billed, they occupy the context, and they dominate latency on long traces.
  • Leaving thinking enabled for structured output jobs, where the trace competes with the schema and the parser sees prose before the JSON.
  • Showing raw traces to end users without a warning that they are unverified drafts, sometimes containing the system prompt.
  • Upgrading the weights without upgrading the template, which is the most common cause of a sudden quality regression in a self-hosted deployment.

Checking a model's format in five minutes

Before integrating anything, spend one request on discovery. Most format bugs are obvious in the raw response and invisible through a client library that has already merged or renamed the channels.

  • Send a trivial prompt with a small token limit and print the raw text, not the parsed object.
  • Note whether the opening marker appears. If it does not, the template injected it, so look for the closing marker instead.
  • Check the finish reason. A length cutoff inside the reasoning block is the case that breaks most parsers.
  • Repeat the same request three times and compare where the boundary falls; a format that moves between runs will break any fixed-offset logic.

A checklist before you ship

  • The rendered prompt matches the model card, including the injected opener and the exact whitespace.
  • The parser is a state machine, tolerates a missing closer, and has a test for a marker split across chunks.
  • The response schema keeps reasoning and content in separate fields with separate token counts.
  • Client events distinguish the two channels, and the boundary is explicit.
  • Retention, redaction and access rules for traces are written down and implemented.
  • Thinking is configurable per route, with a default that matches the task.
  • An evaluation exists that compares thinking on and off on your own data.
  • The tool-call loop replays reasoning in whatever shape the provider requires.
Page feedback

Was this helpful?

A quick signal helps improve these notes.

Report a mistake Straight to the lab inbox

Put it to work

See the models, datasets and gateway this lab runs.