Tidqom — Source-linked AI and developer tools
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.

Diana Park profile photo
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: Midjourney vs DALL-E vs Flux: A Practical Image-Tool Comparison Framework →

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

Advertisement — In Article

Related: 9 Free AI Coding Tools Every Developer Should Try in 2026 →

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: Sora 2 Review: OpenAI's Video Model Is Finally Useful for Real Work →

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: How to Clone Your Voice with AI in 2026 (Free and Paid Options) →

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: 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

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.

Advertisement

Related Articles

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

View all in AI

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

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

The Daily Pulse

Newsletter delivery is not connected yet. This form only saves your address in this browser; no email is sent.

Get concise, source-linked technology notes without the hype.

Advertisement