DeepSeek Prompt EngineeringComplete Guide
Prompt Engineering is the core skill for using DeepSeek. Master prompt techniques to elevate your DeepSeek response quality by an order of magnitude. From principles to practice, from beginner to expert, this guide covers everything.
Start LearningPrompt Fundamentals
Understanding the core principles of prompt engineering is the first step to writing high-quality prompts. This section is suitable for all DeepSeek users, whether you are a complete beginner or an experienced developer.
What is Prompt Engineering?
Prompt engineering is the practice of carefully designing input text (prompts) to guide large language models (LLMs) to generate more accurate, relevant, and higher-quality outputs. Simply put, a good prompt equals a good response.
DeepSeek, as one of the most advanced large language models, is highly sensitive to prompts. The same question asked in different ways can yield vastly different response quality. Prompt engineering helps you find the most effective way to ask.
For example:
Poor Prompt
"Write an article"
Better Prompt
"Write an 800-word WeChat article on 'How AI is Changing Remote Work', aimed at workplace managers, with a professional but not dry tone, including 3 specific examples, and ending with 3 practical suggestions."
How do LLMs understand prompts?
Large language models like DeepSeek are essentially "next-token predictors." When you input text, the model predicts the most likely next word (token) based on patterns learned from training data, then generates the full response word by word.
This means:
- Context is everything: The quality of the prompt directly influences the direction of the model's "guessing." The clearer the prompt, the easier it is for the model to give the correct answer.
- The model does not "understand" intent: The model does not infer your true thoughts; it strictly predicts the next word based on the literal meaning of the prompt. So don't assume the model "should know."
- Attention mechanism: DeepSeek uses the Transformer architecture, where each word in the prompt affects the model's attention allocation to the context. The position and emphasis of keywords affect output quality.
Four Principles of High-Quality Prompts
Clarity
Clearly state what you want and what you don't want. Avoid vague expressions. Use specific verbs and quantifiers, e.g., "list 5 points" is better than "talk about it."
Provide Context
Tell the model background information, target audience, and usage scenario. The richer the context, the more accurate the response. For example, tell the model "You are a senior Python engineer" instead of "You are an assistant."
Specify Format
Clearly specify the output format: JSON, table, Markdown, list, code block, etc. Format constraints greatly reduce the model's "free play" space, making output more controllable.
Iterate and Optimize
Not satisfied with the first prompt? Don't give up. Adjust wording, add details, try a different angle. Prompt engineering is essentially an iterative process; each adjustment brings the response closer to your expectation.
Role Prompting
Role playing is one of the most effective prompting techniques. By setting a clear persona, you can let DeepSeek answer questions as an expert in a specific field, significantly improving the quality and professionalism of responses.
Why is role playing effective?
DeepSeek has learned a large amount of text from various fields during training. When you set a role in the prompt (e.g., "senior Python engineer"), the model activates knowledge patterns and language styles associated with that role, making responses closer to professional standards in that field.
System Prompt
The System Prompt is the core tool for role playing. In API calls, the System Prompt is the first element of the messages array, setting the tone for the entire conversation. DeepSeek's official App and web version also use System Prompts in the background.
Role Playing Prompt Template
Below is a general role playing prompt template. You can replace the content in brackets according to your needs:
Practical Examples
Chain-of-Thought Prompting
Chain-of-Thought (CoT) is a prompting technique that makes the model show its step-by-step reasoning process. For complex tasks requiring multi-step reasoning such as math, logic, and programming, CoT significantly improves answer accuracy.
Why is Chain-of-Thought effective?
Large language models generate answers in a single forward pass. For complex reasoning tasks, jumping directly to the final answer can easily lead to errors. CoT guides the model to "think step by step," breaking down complex problems into multiple simpler sub-problems, each easier for the model to answer correctly. Research shows that CoT can improve math reasoning accuracy by 20%-40%.
Comparison:
Without CoT
"What is 24 * 37 + 15 * 8 - 126 / 3?"
May directly give a wrong answer without reasoning process
With CoT
"Calculate 24 * 37 + 15 * 8 - 126 / 3. Please show your calculation process step by step, first multiplication, then division, and finally addition and subtraction."
Shows step-by-step reasoning, significantly improves accuracy
CoT Prompt Template
Practical Examples
CoT Variant: Zero-shot CoT
Zero-shot CoT is the simplest chain-of-thought technique. Simply add "Let's think step by step" or "Please reason step by step" at the end of the prompt to trigger the model's reasoning mode. No examples needed, zero cost to activate chain-of-thought.
Few-shot Prompting
Few-shot Learning is providing 1-5 examples in the prompt to let the model learn your format, style, and expectations. This is one of the most effective ways to get the model to output in a specific format.
Why is Few-shot effective?
Large language models have learned the ability of "In-Context Learning" during training. When you provide a few examples, the model extracts patterns (format, style, logic) from the examples and applies these patterns to new tasks. The advantage of Few-shot is: No need to fine-tune the model, just modify the prompt to change output behavior.
Few-shot Prompt Template
Practical Examples
Few-shot Best Practices
- Number of examples: 1-3 examples are usually enough; too many may dilute attention to the real task and consume more tokens.
- Quality of examples: Examples should be accurate, standardized, and representative. Wrong examples will "teach" the model incorrectly.
- Diversity of examples: If the task has multiple cases, try to provide an example for each case. For example, sentiment analysis covers positive, negative, and neutral.
- Format consistency: The format of all examples must be exactly the same, otherwise the model will be confused.
- Clear labels: Use labels like "Example 1", "Example 2" or "Input", "Output" to separate examples and tasks.
Structured Output
When you need DeepSeek to output data in a specific format, structured output prompts are the best choice. Whether it's JSON, tables, CSV, or custom formats, clearly specifying the format makes the output immediately usable.
JSON Output
JSON is the most commonly used output format for API calls and programmatic processing. DeepSeek supports JSON format very well; just clearly request it in the prompt.
Table Output
DeepSeek can generate Markdown tables, which are great for comparative analysis, data organization, specifications, etc.
Custom Format Output
Besides JSON and tables, you can specify any custom format. The key is to provide a clear format template.
Step-by-Step Instructions
For complex tasks, a single prompt often fails to produce perfect results. Step-by-step instructions break down complex tasks into multiple steps, each confirmed independently before proceeding to the next, like peeling an onion layer by layer.
Why do step-by-step instructions work?
Complex tasks usually involve multiple dimensions (content, structure, style, format, etc.). Asking the model to meet all requirements at once can lead to trade-offs. Step-by-step instructions decompose the task into independent subtasks, each focusing on one goal, and finally assemble the complete output.
Step-by-step vs. one-shot instructions:
- One-shot instruction: "Write a 3000-word AI industry analysis report" -- the model may produce a chaotic structure and empty content
- Step-by-step instruction: First outline -> confirm, then write introduction -> expand section by section -> finally summarize -- each step's quality is controllable
Step-by-step instruction prompt template
Practical examples
Best practices for step-by-step instructions
- One goal per step: Each step should have the model complete one clear task, not multiple goals.
- Explicitly wait for confirmation: Clearly write "wait for my confirmation before continuing" in the step description to ensure the model doesn't output everything at once.
- Outline first, details later: For writing tasks, have the model produce an outline first, confirm direction and structure, then write the body to avoid going off track.
- Correct promptly: If a step's output is unsatisfactory, directly tell the model "This step isn't quite right; what I actually want is..." and redo that step.
DeepSeek R1 Special Prompting Tips
DeepSeek R1 is a reasoning-enhanced model with built-in chain-of-thought (CoT) capability. Unlike V3, R1 automatically displays its thinking process before answering. Prompting strategies need to be adjusted for R1's characteristics.
Core differences between R1 and V3
General conversational model
Suitable for daily conversation, writing, translation, and knowledge Q&A. Answers directly without showing thinking process. Prompting tips: role-playing, structured output, and step-by-step instructions work best.
Reasoning-enhanced model
Performs better in mathematics, programming, and logical reasoning. Shows thinking process (think tags) before answering. Prompting tips: be concise and direct; no need to overuse CoT.
R1 prompting core principle: simplicity is king
R1 has built-in powerful reasoning capabilities, so you don't need to manually write CoT prompts. Too many prompts may actually interfere with R1's reasoning process. The prompting principles for R1 are:
- Ask directly: No need for CoT prefixes like "think step by step"; R1 will reason automatically.
- Be clear about requirements: Clearly state what you want, but don't teach R1 how to reason.
- Avoid System Prompt: R1 is less sensitive to System Prompt than V3; it's recommended to put role information in the User Prompt.
- Temperature parameter: Use a lower temperature (0.1-0.3) for R1 reasoning to get more stable and accurate results.
R1 practical prompt examples
R1's think tags
R1's responses include a thinking process wrapped in <think> and </think> tags. In API calls, you can parse these tags to separate the "thinking process" from the "final answer".
R1 vs V3: When to use which?
| Task type | Recommended model | Reason |
|---|---|---|
| Mathematical computation, proofs | R1 | R1's mathematical reasoning far exceeds V3, AIME score 79.8 vs 39.2 |
| Complex programming, algorithms | R1 | For algorithmic reasoning and code debugging, R1 is more accurate |
| Logical reasoning, puzzles | R1 | For multi-step reasoning tasks, R1's CoT capability is naturally suited |
| Everyday conversation, writing | V3 | V3 responds more directly and fluently, no need to show thinking process |
| Translation, polishing | V3 | V3 processes language faster, output is more concise |
| Creative writing | V3 | V3 has better creativity and literary flair, R1 is more rational |
| Structured output, JSON | V3 | V3 better complies with format constraints |
Scenario-based Prompt Template Library
20+ ready-to-use prompt templates covering high-frequency scenarios such as writing, programming, translation, analysis, summarization, brainstorming, code review, debugging, documentation, email, reports, etc. Copy and use directly, modify as needed.
Writing
Programming
Translation
Analysis
Summarization
Brainstorming
Email and Reports
Learning and Education
Documentation and Instructions
Common Mistakes and Optimization
Even if you master all the techniques, you can still make mistakes when writing prompts. Below are the most common prompt errors and their optimization methods to help you quickly troubleshoot and fix issues.
Mistake 1: Prompt is too vague
| Bad example | "Write an article about AI" |
| Problem | No specific topic angle, word count, style, or audience specified; the model can only generate randomly |
| Optimized | "Write an 800-word popular science article on 'How AI is changing medical diagnosis', aimed at the general public, with a relaxed and easy-to-understand tone, including 2 real cases, and ending with future prospects." |
Mistake 2: Information overload
| Bad example | In one prompt, asking the model to complete 5 different tasks simultaneously (write an article, translate, analyze data, generate code, summarize a document) |
| Problem | Attention is divided, and each task is done poorly. The model switches between tasks, leading to degraded output quality |
| Optimized | Split into multiple independent conversations or use step-by-step instructions, focusing on one core task at a time |
Mistake 3: Ignoring context window limits
| Mistake | In long conversations, early context is gradually "forgotten". The DeepSeek local deployment version has a default context of 128K tokens, but the longer the conversation, the less attention the model pays to early information |
| Optimization | For long conversations, periodically "summarize and review" key information from earlier. Before critical instructions, use "Let's review the previous discussion..." to reactivate context. Start a new conversation when necessary |
Mistake 4: Over-reliance on the model's "common sense"
| Mistake | Assuming the model knows your specific project background, internal company terminology, or the latest event information (training data has a cutoff date) |
| Optimization | Provide necessary background information in the prompt. For questions requiring the latest information, use DeepSeek's web search feature. For project-specific content, clearly state it in the prompt |
Error 5: Ignoring R1's think output
| Error | When calling R1 via the API, directly using the full output (including think tags) without separating the thinking process and the final answer |
| Optimization | Parse R1's output, extract the content between <think> and </think> as the thinking process, and the content after the tags as the final answer. In user-facing scenarios, usually only the final answer is displayed. |
Prompt Debugging Methodology
When DeepSeek's output does not meet expectations, systematically troubleshoot and optimize according to the following steps:
- Check if the prompt is clear: Are there vague words? Are there implicit assumptions? Add specific details.
- Check if context is missing: Does the model know the background information you need? Add role settings or background explanations.
- Check if the format is explicit: Have you specified the output format? If not, add format requirements.
- Try a different angle: For the same task, rephrase the question with different wording and structure.
- Use few-shot: Provide 1-2 examples of desired output for the model to imitate.
- Break it down into multiple steps: If one-shot output is not ideal, break it into step-by-step instructions and confirm gradually.
- Switch models: V3 and R1 each have advantages; if the current model performs poorly, try the other.
- Start a new conversation: Accumulated context in long conversations may interfere with the model; start a new conversation to begin fresh.
Iterative Optimization Example
The following is an iterative optimization process of a prompt from "bad" to "excellent":
DeepSeek Prompt Engineering FAQ
More DeepSeek Learning Resources
How to Use DeepSeek Models
Start from zero, four ways to use DeepSeek with hands-on guidance.
DeepSeek Model Complete Guide
Technical architecture, Benchmark performance comparison, model selection guide.
DeepSeek Open Source Models
Complete catalog of 6 series, 20+ models, quickly find the right one.
DeepSeek Model Download
Detailed guide for three download methods: Ollama, Hugging Face, GitHub.
DeepSeek Local Deployment
Deployment solutions with Ollama, Docker, vLLM, from single machine to cluster.
DeepSeek Ecosystem Tools
30+ peripheral tools, full coverage of WebUI, IDE plugins, Agent frameworks.