Skip to main content
Coding Prompts

Debug This Code

Diagnose bugs in any code snippet with clear explanations of the root cause and a corrected version.

beginnerWorks with any modelCoding
Prompt
I have a bug in my [LANGUAGE] code. Please help me debug it.

**Code:**
```[LANGUAGE]
[CODE]
```

**Error or unexpected behavior:**
[ERROR_OR_BEHAVIOR]

Please provide:
1. **Root cause** — explain exactly why this bug occurs
2. **Corrected code** — the fixed version with changes highlighted in comments
3. **Explanation of the fix** — what you changed and why it works
4. **Prevention tip** — how to avoid this class of bug in the future

How to Use

Paste your broken code along with the error message or a description of the unexpected behavior. The more detail you give about what you expected vs. what actually happened, the more precise the diagnosis will be. Works for runtime errors, logic bugs, off-by-one errors, type mismatches, and silent failures.

Variables

VariableDescription
[LANGUAGE]Programming language (e.g., Python, JavaScript, Go, Rust)
[CODE]The full code snippet containing the bug — include enough context so the bug is reproducible
[ERROR_OR_BEHAVIOR]Paste the exact error message, stack trace, or describe what the code does vs. what you expect it to do

Tips

  • Include the full stack trace if you have one — line numbers and error types dramatically speed up diagnosis.
  • If the bug is intermittent, mention that and describe the conditions under which it appears (e.g., "only with empty arrays" or "only in production").