Back to guide/General Productivity

Debug Code Step by Step

DeepSeek-R1's reasoning training makes it excellent at step-by-step code tracing. Constraining to a 'minimal fix' prevents the model from rewriting your entire function when only one line needs to change. The execution trace reveals the model's reasoning so you can verify it.

deepseek-promptslanguagebugDescriptioncode
Edit View
Prompt
Debug the following {{language}} code. There is a bug causing {{bugDescription}}.

**Code:**
\`\`\`{{language}}
{{code}}
\`\`\`

**Expected behavior:** {{expectedBehavior}}
**Actual behavior:** {{actualBehavior}}
**Error message (if any):** {{errorMessage}}

Debug this step by step:
1. Read the code and trace the execution flow
2. Identify where the actual behavior diverges from expected
3. Explain the root cause clearly
4. Provide the corrected code with a comment marking what changed and why

Do not rewrite the entire function — show only the minimal fix needed.

Variables to customize

{{language}}{{bugDescription}}{{code}}{{expectedBehavior}}{{actualBehavior}}{{errorMessage}}

Why this prompt works

DeepSeek-R1's reasoning training makes it excellent at step-by-step code tracing. Constraining to a 'minimal fix' prevents the model from rewriting your entire function when only one line needs to change. The execution trace reveals the model's reasoning so you can verify it.

Save this prompt to your library

Organize, version, and access your best prompts across ChatGPT, Claude, and Cursor.