Why this prompt works
This debug code prompt asks for the root cause before the fix, which stops the AI from guessing and wrapping your code in try-except blocks that hide the real problem. Giving the expected and actual behaviour, the full stack trace and what you already tried narrows the search a lot.
"The smallest change" keeps the fix easy to review, and the test case makes sure the same bug cannot quietly return. The last line, asking for two likely causes when unsure, gives you a way forward instead of a confident wrong answer.
How to use this prompt
- Tap "Copy prompt".
- Replace every part in [square brackets] with your own details.
- Paste it into ChatGPT or Claude and send.
- Ask a follow-up like "make it shorter" or "give me 3 more options" to fine-tune it.
Variations to try
Debug a failing test
- Type
- Text
- Fill in
- 4 blanks
- Copies
- Be the first
Debug a slow or hanging program
- Type
- Text
- Fill in
- 4 blanks
- Copies
- Be the first
Explain a confusing error message
- Type
- Text
- Fill in
- 2 blanks
- Copies
- Be the first
Make it your own
- Replace "senior [language] developer" with your stack, for example "senior Django developer".
- Add "Explain like I am new to programming" if you are learning.
- Paste related files (models, config) when the error points outside the code you shared.
Common problems and fixes
- The AI rewrites the whole file. Keep "smallest change" and "do not rewrite unrelated code" in the prompt.
- The fix works on your machine but not in production. Add the production environment details, versions and any config differences.
- You paste secrets with the code. Replace API keys, passwords and tokens with placeholders before pasting.
FAQ
Should I paste my whole project?
No. Paste the smallest piece of code that shows the bug, plus the error. Large pastes make answers less focused.
What if the AI's fix does not work?
Paste the new error and say "this did not work, here is what happened". Ask it to list other possible causes.