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.

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
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:
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 itIf 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:
import re
def strip_reasoning(text: str) -> str:
return re.sub(r"<think>.*?</think>", "", text, flags=re.DOTALL).strip()Guard against a truncated block — if generation hits the token limit mid-reasoning, the closing tag never arrives:
if "<think>" in out and "</think>" not in out:
out = "" # incomplete; retry rather than store noiseFix 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 →
ollama run deepseek-r1:8b --think=falseQuality 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 case | Model | think | num_ctx |
|---|---|---|---|
| Long-form drafting | deepseek-r1:14b | on, stripped in code | 8192 |
| Tag/classify | qwen2.5:7b | n/a | 4096 |
| Offline research | deepseek-r1:8b | on, logged | 8192 |
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.
Related Articles
مقالات ذات صلة — تابع القراءة داخل الموقع
مواضيع مقترحة · 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.




