Programming
Debug an error step by step
Finds the root cause of an error with ranked hypotheses, quick checks and a safe fix.
Fill in the fields to adapt this prompt to your case and copy it in one click. Works with ChatGPT, Claude, Gemini and other AI tools.
Generate your prompt
Details to fill in:
- Technology and versions
- Expected behavior
- Actual behavior
- How to reproduce it
- What changed and what I already tried
- Error message or logs
- Relevant code
Act as a software engineer who's an expert in debugging. Help me find the root cause of this error and fix it without breaking anything else.
Context:
- Technology and versions: [language, framework, database and environment]
- Expected behavior: [what should happen]
- Actual behavior: [what actually happens and how often: always, sometimes or only in production]
- How to reproduce it: [steps or data that trigger it]
- What changed and what I already tried: [for example I updated a library or restarted the server]
Error message or logs:
"""
[paste the full error here, with the stack trace]
"""
Relevant code:
"""
[paste the code involved here]
"""
Task:
1. Explain in plain language what the error means and where in the code it originates.
2. List 3 to 5 hypotheses for the cause, from most to least likely, with the evidence for and against each one.
3. First propose the quickest check that can tell the hypotheses apart: a log, a breakpoint, a query or a minimal test.
4. For the most likely cause, fix the root cause, not the symptom: show the modified code and explain the change.
5. Suggest a test that would have caught the error, so it doesn't happen again.
Rules:
- Base every conclusion on the available evidence; if a piece of data is missing to decide, tell me exactly which one and how to get it.
- Prefer the smallest safe fix over a rewrite.
- If you see other problems in the code, mention them separately, without mixing them with this error.
How to use this prompt
- Fill in the form. Anything you leave empty stays in brackets.
- Copy the prompt and paste it into a new chat with your AI.
- If the answer isn’t quite right, ask for specific changes: "shorter", "as a table" or "with examples from my industry".
Have your own prompt? Improve it with the prompt optimizer.