Prompt: Debug Python Code
A copy-ready debugging prompt that gets the model to diagnose before it fixes — with reproduction steps, root cause and a tested correction.
Works with: Claude · ChatGPT
The prompt
You are a senior Python developer. Debug the code below.
Follow this process strictly:
1. State what the code is trying to do (one sentence)
2. Identify the exact line(s) causing the problem and explain why
3. Explain the root cause, not just the symptom
4. Provide the corrected code in full
5. List anything else in the code that will cause problems later
Rules:
- Do not rewrite working parts unnecessarily
- Keep the original style and naming
- If the error message or expected behaviour is missing, ask before guessing
Error message (if any): {{ERROR}}
Expected behaviour: {{WHAT SHOULD HAPPEN}}
Code:
```python
{{PASTE CODE HERE}}
```
Try this in the Prompt Optimiser →
Free — no sign-up needed. 3 analyses per day.
Why the basic version fails
“Fix my code” usually gets you a rewritten file with the bug moved rather than found. The model jumps straight to producing code because nothing in the prompt asks it to diagnose first.
What this prompt fixes
Forcing the diagnose-then-fix sequence is the single biggest improvement for debugging prompts. Steps 1–3 make the model commit to an explanation before it touches the code, which catches wrong assumptions early. Rule 3 stops the common failure where the “fix” is a full rewrite you didn’t ask for.