DeepSeekDSH
Independent community guideNot affiliated with DeepSeek.Download versions and guide references

DeepSeek-R1 Reasoning Best Practices and Prompt Guide

DeepSeek-R1 generates autonomous chain-of-thought exploration before producing final outputs. Follow official prompting guidelines, hyperparameter boundaries, and streaming code examples.

On this page

1. Core reasoning mechanism

DeepSeek-R1 generates an internal chain of thought before providing answers. In API responses, the reasoning trajectory is returned in the dedicated reasoning_content field, while final conclusions are delivered in standard content.

2. Official prompting principles

Zero-shot prompt preference

Directly describe the target question. Avoid rigid few-shot examples or strict formatting templates that hinder autonomous problem exploration.

Avoid step-by-step instructions

Do not append "think step by step." DeepSeek-R1 is reinforcement-learning trained to self-verify and refine steps autonomously.

3. Recommended hyperparameters

  • Temperature range: Keep temperature at 0.5 ~ 0.7 (default 0.6). Setting temperature to 0 degrades exploratory diversity, while excessive values cause looping.
  • Allocate sufficient max_tokens: The max_tokens limit caps the sum of reasoning tokens and final answer tokens. Set this to 4096 ~ 8192 to avoid cutoffs.

4. Streaming reasoning_content (Python example)

Stream both reasoning steps and final conclusions separately:

from openai import OpenAI client = OpenAI( api_key="sk-your_deepseek_api_key", base_url="https://api.deepseek.com" ) response = client.chat.completions.create( model="deepseek-reasoner", messages=[{"role": "user", "content": "Which number is larger: 9.11 or 9.8? Provide a proof."}], stream=True ) reasoning_content = "" answer_content = "" for chunk in response: delta = chunk.choices[0].delta # Print reasoning steps if hasattr(delta, "reasoning_content") and delta.reasoning_content: reasoning_chunk = delta.reasoning_content reasoning_content += reasoning_chunk print(reasoning_chunk, end="", flush=True) # Print final answer elif delta.content: if not answer_content: print("\n\n=== Final Answer ===\n") answer_chunk = delta.content answer_content += answer_chunk print(answer_chunk, end="", flush=True)

5. Common pitfalls to avoid

Overcomplicating the System Prompt

Overly detailed persona rules restrict the model's exploratory reasoning. Keep system prompts short or omit them.

Truncated outputs with incomplete answers

The reasoning phase consumed the entire max_tokens budget. Increase max_tokens to allow space for the final answer.

References