Debugging Prompts

8 Prompts · Copy-Paste Ready

Home › Vibe Coding Prompts › Debugging

Category · Debugging

Debugging Prompts

8 prompts that make AI do the detective work — trace errors, isolate root causes, and fix them properly. Not just patch the symptom.

How to use: Replace [bracketed placeholders] with your actual code, error, and context. Paste into Claude Code, Cursor, Copilot Chat, ChatGPT, or Claude.ai. Read every line of output before merging.

1

Root cause finder

Use this when you have an error but no idea where it's coming from. Forcing AI to explain before fixing prevents hallucinated fixes.

I have a bug. Here's the error: [paste the full error message and stack trace] Here's the file that's failing: [paste the file] Here's what calls it: [paste the caller function or code path] Before proposing a fix, explain: 1. What line the error is actually on 2. What value is causing the failure 3. Why that value is wrong (trace it back to where it came from) 4. What the correct behavior should be Do NOT propose a fix yet. Just explain what's happening.
What you should expect

A step-by-step trace of where the value became wrong. If AI jumps straight to a fix, reply: "You skipped the explanation. Go back to step 1."

2

Reproduce the bug

Use this when the bug is intermittent or you can't trigger it reliably. AI is good at finding the specific sequence of events that causes a failure.

I have an intermittent bug in this function: [paste the function] The bug: [describe what goes wrong, in what situation] Write a minimal reproduction — a script or test that reliably triggers this bug. Include: 1. The exact setup (data, state, environment) 2. The shortest code path that fails 3. Comments on each line explaining what triggers the failure The goal is a repro I can run in under 30 seconds.
What you should expect

A small, runnable script. If AI gives you a code snippet instead of a runnable file, ask: "Wrap this in a complete script with a main() function."

3

Compare two hypotheses

Use this when you have two theories about what's wrong and can't tell which is correct. Forces AI to reason through both — and often reveals a third cause you missed.

Bug in [file/function]. Hypothesis A: [first theory] Hypothesis B: [second theory] For each hypothesis: 1. What would the error output look like if this were correct? 2. What would the error output look like if this were wrong? 3. What test would distinguish between the two? Then tell me which one is actually more likely — and whether there's a third hypothesis I missed. Be direct. Don't hedge.
What you should expect

A clear comparison with a recommendation. If AI says "both are possible," push back with: "Pick one. Which is more likely based on the evidence?"

4

Explain an unfamiliar stack trace

Use this when the error comes from inside a library or framework you don't know. AI parses stack traces better than humans — let it translate.

I don't understand this stack trace: [paste the entire stack trace] The code I actually wrote is in [file:line]. Translate the stack trace for me: 1. What does each frame do? (Just the ones in my code and the library boundary.) 2. Which frame is where things went wrong? 3. What is the library expecting that I'm not providing? 4. What's the minimum code change to fix it? Skip the frames from the runtime or engine — I only care about my code and the immediate library layer.
What you should expect

A frame-by-frame translation with the actual problem at the library boundary. Most stack trace bugs come from mismatched types or missing properties at that line.

5

Add defensive checks without hiding the bug

Use this when you need a temporary guard but don't want to hide the actual problem. Critical for production code — silent failures are worse than crashes.

I need to add defensive checks to this function without hiding the bug: [paste the function] The undefined value I'm guarding against is: [variable/expression] Add checks that: 1. Fail loudly in development (throw with a useful message) 2. Fail safely in production (return a sensible default or skip gracefully) 3. Log the incident once (not on every call) so I can track frequency Do NOT silently swallow the error. Do NOT just add `if (!x) return;` — I need to know when this happens.
What you should expect

A guard that fails safely in production but throws in dev. If AI adds a silent return, push back: "This hides the bug. Make it throw in dev mode."

6

Find the bug you wrote yesterday

Use this after a bug appears in code that worked last week. AI can diff two versions of a file better than you can scan.

This code worked last week and is broken now. Current version: [paste the current file] The only changes I made were: [list what you changed] The bug: [describe the new behavior] Find the specific change that broke it. 1. What did I change that caused this? 2. Why did it break when it used to work? 3. What's the smallest fix? Don't suggest rewrites. Just identify the broken change and fix it.
What you should expect

A specific line and the reason it broke. If AI suggests a full rewrite, push back: "Just find the broken change. Don't rewrite the file."

7

Debug performance, not just correctness

Use this when the code works but is slow. Performance debugging is different from bug debugging — it's about identifying the expensive operation, not the wrong one.

This function is too slow. It works correctly, but it's taking [actual time] on data of size [N]. [paste the function] 1. What's the algorithmic complexity? 2. Which line is the actual bottleneck? 3. What's the theoretical best complexity for this problem? 4. Give me the optimized version — same output, better complexity. Don't micro-optimize. I want the algorithmic fix, not 10% improvements from loop unrolling.
What you should expect

A complexity analysis and a rewrite that changes the algorithm. If AI says "it's already optimal," ask: "What's the constraint that makes it optimal? Can I change the data structure?"

8

The "what did I miss" prompt

Use this before marking a bug as fixed. AI is good at spotting cases you didn't think of — but only if you ask.

I think I fixed this bug: Original problem: [describe the bug] My fix: [paste the fix] Before I commit, tell me: 1. Does this fix the actual root cause, or just the symptom I observed? 2. What edge cases does this fix NOT cover? 3. What could this fix break in other code paths? 4. Are there related bugs with the same root cause that I should check? Be skeptical. Assume I'm wrong and look for what I missed.
What you should expect

At least one edge case or related bug. If AI says "looks good," push back: "What input would still trigger the original bug?" It'll find one.

🎯 Why these prompts work

❓ Frequently asked questions

What makes a good debugging prompt?

A good debugging prompt includes the error text, the relevant code, the context (what you expected vs what happened), and a request to explain root cause before proposing fixes. The last part is critical — it prevents AI from guessing.

Why do I need to include the full error message?

Error messages often contain the exact line number, the type of failure, and the property path. AI uses all three to locate the actual bug. Pasting just 'it's broken' forces guessing.

Should I include my whole file or just the relevant part?

Just the relevant function plus its callers. Full files add noise and waste context. If the bug involves cross-file behavior, include the boundary — the function that calls this one, or the object this one receives.

What if AI proposes a fix that doesn't work?

Reply with the new error and ask it to explain what its previous fix was based on. This usually reveals whether it understood the problem or guessed. If it guessed, start a fresh session with a clearer prompt.

Can I use these prompts for non-JavaScript languages?

Yes. The prompts are language-agnostic. Replace the language-specific examples with your own stack — the structure (context, task, constraints, verification) works everywhere.

🔗 Related

← All Prompts