Tidqom — AI, Gadgets and Tech News
AITid
AI

DeepSeek-R1 Shows Its <think> Tags in the Output — Here Is How I Strip Them

DeepSeek-R1 prints its whole reasoning chain before the answer. Three ways I remove it: prompt-level, API-level parsing, and a small wrapper I use in every script.

D
August 1, 2026 · 5 min read
DeepSeek-R1 Shows Its <think> Tags in the Output — Here Is How I Strip Them — AI

DeepSeek-R1 Shows Its <think> Tags in the Output — Here Is How I Strip Them

DeepSeek-R1 is a reasoning model, so every response starts with a long block wrapped in think tags before the real answer. In a chat window it is interesting. In an automation that writes to a database, it is garbage in your column.

Tested on: deepseek-r1:8b and deepseek-r1:14b (q4_K_M) via Ollama 0.6.x, Mac mini M4 16 GB and an RTX 3060 box.

Why prompting alone does not work

Related: GPT-5 Is Here: Everything You Need to Know About OpenAI's Most Powerful Model Yet →

Related: DeepSeek-R1 Repeats Itself or Outputs Gibberish: The 4 Settings That Fixed It →

I tried "do not show your reasoning" in the system prompt on both sizes. R1 ignores it — the reasoning block is part of how the model was trained, not an instruction it can opt out of. Suppress it in code, not in the prompt.

Fix 1 — Read the dedicated reasoning field

Related: Will AI Coding Agents Replace Developers? We Asked 100 Engineers →

Advertisement — In Article

Related: Ollama Filled My Disk: How I Moved the Models Directory Safely →

Modern Ollama separates it for you, which is the cleanest path:

python
import ollama
r = ollama.chat(model="deepseek-r1:8b",
                messages=[{"role": "user", "content": "Summarise this changelog"}])
print(r["message"]["content"])          # answer only
# r["message"].get("thinking")          # reasoning, if you want to log it

If your client library is older, upgrade first — that alone removed the problem in two of my scripts.

Fix 2 — Strip it with a regex

Related: The 27 Best AI Tools in 2026 (Tested for 90 Days) →

Related: Ollama Answers Get Cut Off Mid-Sentence: num_ctx vs num_predict Explained →

The one-liner I keep in my utils file:

python
import re
def strip_reasoning(text: str) -> str:
    return re.sub(r"<think>.*?</think>", "", text, flags=re.DOTALL).strip()
Advertisement — In Article

Guard against a truncated block — if generation hits the token limit mid-reasoning, the closing tag never arrives:

python
if "<think>" in out and "</think>" not in out:
    out = ""   # incomplete; retry rather than store noise

Fix 3 — Turn thinking off where the runner supports it

Related: ChatGPT vs Claude 4: Which AI Should You Actually Pay For in 2026? →

Related: Ollama "connection refused on 127.0.0.1:11434": The 5 Causes I Have Actually Hit →

bash
ollama run deepseek-r1:8b --think=false

Quality on multi-step tasks drops noticeably when I do this, so I only use it for classification and short extraction jobs where R1 was overkill anyway.

My exact settings

Related: Google Gemini 3 Ultra Review: Has Google Finally Caught Up? →

Related: Ollama Error "model requires more system memory": How I Fixed It in 10 Minutes →

Use caseModelthinknum_ctx
Long-form draftingdeepseek-r1:14bon, stripped in code8192
Tag/classifyqwen2.5:7bn/a4096
Offline researchdeepseek-r1:8bon, logged8192

Note the middle row: for pure classification I switched off R1 entirely. It was 3× slower for no measurable gain.

FAQ

Related: Midjourney vs DALL-E 4 vs Flux 1.1: The Definitive AI Image Generator Comparison →

Does the reasoning block count against my context? Yes. It is generated tokens, so it eats both time and num_ctx. That is why my R1 sessions use a bigger context than my Qwen ones.

Can I show the reasoning in a UI? That is exactly what I do — render thinking inside a collapsed "show reasoning" toggle, and keep the answer clean.

Where do I set R1 up from scratch? My full walkthrough is running DeepSeek-R1 offline on a Mac mini M4, with the general path in the local LLM guide and tooling context in the ultimate AI tools guide.

Hands-on

Experience Log

This is not theory. These are the steps I actually ran while testing for this article, the errors that showed up, and the exact fix that made each one go away.

  1. 1Step I tried

    DeepSeek-R1 is a reasoning model, so every response starts with a long block wrapped in think tags before the real answer. In a chat window it is interesting. In an automation that writes…

    Error I hit

    Tested on: deepseek-r1:8b and deepseek-r1:14b (q4KM) via [Ollama](/article/ollama-common-errors-solutions-ar) 0.6.x, Mac mini M4 16 GB and an RTX 3060 box.

    Exactly how I fixed it

    Related: [DeepSeek-R1 Repeats Itself or Outputs Gibberish: The 4 Settings That Fixed It →](/article/fix-deepseek-r1-repeating-loops-gibberish)

  2. 2Step I tried

    python import ollama r = ollama.chat(model="deepseek-r1:8b", messages=[{"role": "user", "content": "Summarise this changelog"}]) print(r["message"]["content"]) # answer only #…

    Error I hit

    If your client library is older, upgrade first — that alone removed the problem in two of my scripts.

    Exactly how I fixed it

    Related: [Ollama Answers Get Cut Off Mid-Sentence: numctx vs numpredict Explained →](/article/fix-ollama-answers-cut-off-num-ctx-num-predict)

  3. 3Step I tried

    Quality on multi-step tasks drops noticeably when I do this, so I only use it for classification and short extraction jobs where R1 was overkill anyway.

    Error I hit

    Related: [Ollama Error "model requires more system memory": How I Fixed It in 10 Minutes →](/article/fix-ollama-model-requires-more-system-memory)

    Exactly how I fixed it

    Related: [Ollama Error "model requires more system memory": How I Fixed It in 10 Minutes →](/article/fix-ollama-model-requires-more-system-memory)

  4. 4Step I tried

    | Use case | Model | think | numctx | |---|---|---|---| | Long-form drafting | deepseek-r1:14b | on, stripped in code | 8192 | | Tag/classify | qwen2.5:7b | n/a | 4096 | | Offline research…

    Error I hit

    Note the middle row: for pure classification I switched off R1 entirely. It was 3× slower for no measurable gain.

    Exactly how I fixed it

    Note the middle row: for pure classification I switched off R1 entirely. It was 3× slower for no measurable gain.

What the run ended with

After all of the above, the setup that actually held up is the one described in this guide to “DeepSeek-R1 Shows Its &lt;think&gt; Tags in the Output — Here Is How I Strip Them”. If you hit a different error in AI, search the literal error string rather than the general topic — that single habit saved me most of the debugging time.

Advertisement

Related Articles

مقالات ذات صلة — تابع القراءة داخل الموقع

View all in AI

مواضيع مقترحة · Suggested Topics

استكشف مواضيع ومحاور ذات صلة بهذا المقال — روابط داخلية لتعميق قراءتك.

The Daily Pulse

Get the 5 biggest tech stories in your inbox every morning. Free, no spam, unsubscribe anytime.

Join 50,000+ tech professionals reading every day.

Advertisement