The default way most people debug with AI is to paste a stack trace and type "fix this." Sometimes it works. More often the model invents a plausible-sounding cause, "fixes" it, and the bug is still there — now hidden under a layer of confident wrong code.
The problem is the same one that ruins human debugging: jumping to a fix before understanding the cause. A good debugging prompt forces the model to do what a senior engineer does — reproduce, isolate, form a hypothesis, then test it — instead of pattern-matching the error string to the nearest Stack Overflow answer.
Here are the prompts I actually use, organized by the kind of bug. They work in Cursor, Claude, ChatGPT, or any assistant. Copy them, paste your context, and notice how the output stops being a guess.
Why "fix this" fails
"Fix this" gives the model no role, no method, and no constraint against guessing. So it does the easy thing: it finds the most common cause of that error message and assumes that's yours. For generic errors (undefined is not a function, connection refused) the most common cause is rarely your cause.
The fix is to make the model show its reasoning before it writes a single line of code — and to forbid it from changing anything until you've agreed on the cause.
Prompt 1: Root-cause analysis (no fix yet)
This is my default. The key constraint is the last line — it stops the model from skipping to a patch.
You are a senior engineer debugging a problem. Do NOT write a fix yet.
Here is the symptom: <what you observe>
Here is the error / log: <paste>
Here is the relevant code: <paste>
What I've already ruled out: <list, or "nothing yet">
Work through this in order:
1. State exactly what the symptom tells us — and what it does NOT tell us.
2. List the 3-4 most likely causes, ranked by probability for THIS code (not in general).
3. For each cause, give the single cheapest check that would confirm or eliminate it.
4. Tell me which check to run first and what result would point where.
Do not propose a code change until I report back what the checks showed.
You run the checks, paste the results, and then it fixes — now with evidence instead of a guess. This one prompt has saved me from more wrong "fixes" than anything else.
Prompt 2: Regression hunt ("it worked yesterday")
When something broke and you have version control, the bug is almost always in the diff. Point the model at the change, not the whole file.
This worked before and now it doesn't. The behavior change is: <before vs after>.
Here is the diff of recent changes: <paste git diff, or the commit range>
Here is the failing case: <input → expected → actual>
Analyze the diff specifically:
1. Which changed lines could plausibly cause this exact symptom? Quote them.
2. For the top suspect, trace how the new code produces the wrong result, step by step with the failing input.
3. Confirm it's the cause before fixing: what value would I see at <line> if you're right?
Ignore unchanged code unless the diff broke an assumption it relied on.
The last line matters. Without it, the model wanders off into unrelated parts of the file. A regression lives in what changed — anchor it there.
Prompt 3: Race conditions and intermittent failures
Intermittent bugs are where AI guessing is most dangerous, because the "fix" appears to work (the bug just didn't happen to fire). Force the model to reason about interleaving and ordering, not just the code path.
This bug is intermittent — it fails maybe 1 in 20 runs. Assume it's a timing/ordering issue.
Here is the code: <paste async/concurrent code>
Here is what's shared between the concurrent paths: <state, files, DB rows, caches>
Reason about it as a concurrency problem:
1. Identify every piece of shared mutable state and who reads/writes it.
2. Find an interleaving of operations that produces the bad result. Write it as a numbered timeline (Thread A line X, then Thread B line Y...).
3. Name the category: race, deadlock, lost update, stale read, missing await, or unhandled rejection.
4. Propose a fix that removes the race (lock, atomic op, await, idempotency key) — not one that just makes it rarer.
If you can't construct a failing timeline, say so — don't invent one.
The "write it as a numbered timeline" instruction is what turns hand-waving into something you can verify. If the timeline is real, the bug is real. If the model can't build one, it admits it instead of fabricating a fix.
Prompt 4: The "explain it back to me" sanity check
Before you accept any AI fix, run this. It catches the cases where the model fixed the symptom but misunderstood the cause.
Before I apply your fix, explain it back to me:
1. In one sentence, what was the actual root cause?
2. Why did the bug appear only under <the conditions I described> and not always?
3. What does your fix change, and why does that address the cause (not just the symptom)?
4. What input would still break this code after your fix? Is there an edge case left?
If any answer is "I'm not sure," tell me what to check instead of guessing.
If the model can't cleanly answer #2 — why these conditions and not others — it didn't understand the bug, and its fix is a coincidence. That single question has caught more bad patches for me than any test.
The pattern behind all of these
Every prompt here does the same four things: assigns a role, demands a method (reproduce → hypothesize → verify), forbids guessing, and delays the fix until there's evidence. That's not an AI trick — it's just disciplined debugging, written down so the model can't skip steps.
You can build these yourself from the templates above. The only real work is keeping a tuned library so you grab the right one instantly instead of rewriting it at 2 a.m. during an incident.
If you want the full library ready to go
I keep a much larger set than fits in one post — prompts for root-cause, performance profiling, flaky tests, memory leaks, log analysis, and writing the minimal repro. I cleaned them up and packaged them as the Developer's AI Prompt Arsenal: 140 copy-paste prompts across debugging, code review, refactoring, testing, and architecture, organized so you find the right one in seconds, with a START HERE guide on how to fill in the variables.
That said, the four prompts above cost nothing and will change your very next debugging session. Start with Prompt 1 — paste your current bug into it before you let any AI touch the code.
What's the most stubborn bug an AI prompt ever helped you crack — or the one it kept getting wrong? Tell me in the comments; I'm collecting the patterns.
Top comments (0)