大模型网摘deepseek.wang

AI Usage Guides · 2026-11-05

DeepSeek Coding Workflow: A Prompt Sequence from Error Debugging to Refactoring

When code throws an error, many people dump the whole file and the traceback into the model at once, then get advice that looks right but doesn't work. The problem isn't the model—it's how you feed it. DeepSeek's V series is great for quickly interpreting errors and fixing small code snippets; the R series with deep thinking mode handles problems that need step-by-step reasoning, like multi-file coupling, async race conditions, or tricky math. Note that thinking mode can be toggled in both the chat interface and the API—no need to enable it for simple tasks, since it's slower and uses more tokens. Below is the "interpret → diagnose → refactor" prompt sequence I use repeatedly in real projects. Copy, tweak the placeholders, and run.

Step 1: Interpret the Error—Don't Make the Model Guess

Error interpretation is a simple task: use the V series, thinking mode off. The key is providing enough context while constraining the output format, so the model doesn't launch into a long lecture.

I hit the following error. Please interpret it:

【Error message】
(paste the full traceback—never truncate the last line)

【Relevant code】
(paste the function or snippet the error points to, ideally 10–50 lines)

【Environment】
Language/version: Python 3.11
Key dependencies: FastAPI 0.115, SQLAlchemy 2.0 (fill in actuals)

Output in this format only, no unrelated background:
1. Direct cause of the error (one sentence)
2. Exact code location that failed
3. 2–3 possible trigger scenarios, ranked by likelihood

The line "no unrelated background" matters. DeepSeek understands Chinese context well—if you don't set limits, it defaults to writing an essay. Always paste the complete traceback, especially the final line and the middle stack frames; truncation is the most common failure mode.

Step 2: Root-Cause Analysis—This Is When to Enable Deep Thinking

If Step 1 yields multiple candidate causes and you can't tell which one is real, switch to the R series with thinking mode. Don't open with role-play like "you are a senior architect"—reasoning models respond to clear constraints, not theatrics. Lay out the known facts and verification conditions directly.

This error has three candidate causes. Please reason through each and determine which holds:

【Candidate 1】DB connection pool exhaustion: evidence is that it only occurs at peak hours
【Candidate 2】Synchronous ORM calls inside async tasks: evidence is session.query() inside an async def
【Candidate 3】Timeout set too short: evidence is intermittent occurrence with timeout in the stack

【Constraints】
- Production is read-only; no ad-hoc logging restarts for verification
- For each candidate, propose the minimal-change method to verify it in production
- If the information is insufficient to decide, explicitly state what's missing—do not guess

"Do not guess" and "state what's missing" are worth their weight in gold. In thinking mode the model will genuinely eliminate options step by step instead of picking whatever sounds plausible.

Step 3: Refactoring Prompts—Plan First, Code Second

Once the root cause is confirmed, don't ask for code right away. Have DeepSeek propose a refactoring plan first; confirm the direction, then have it write the code. Far less rework.

For the confirmed root cause (DB connection pool exhaustion), refactor this code:

【Existing code】
(paste in full)

【Refactoring requirements】
1. Reuse the existing connection pool; no new dependencies
2. Keep function signatures unchanged so callers need no edits
3. Annotate the reason for each change
4. Afterward, list: test cases to add, and possible regression risks

First output a change plan for my confirmation, then the full code.

"Plan first, then code" is how you put deep thinking to work where it counts—the model reasons through the trade-offs during planning, and error rates in the coding phase drop noticeably.

Two Common Pitfalls

First, dumping an entire repo in and asking "what's wrong with this code." The longer the context, the more scattered the attention—long context capability (and its cost advantage) isn't meant to be used this way. Slice by function or module and solve one problem at a time. Second, enabling deep thinking for trivial errors. A misspelled variable name triggering minutes of reasoning is pure waste; if the error message is obvious at a glance, just ask the V series directly.

The core idea of this sequence fits in one sentence: split "interpret, diagnose, refactor" into three separate prompts, each giving the model only the minimal context it needs, using the V series for simple questions and reserving thinking mode for problems that truly require reasoning. Copy the templates above, tweak the placeholders, and try it on your next error.