Debug by Giving the AI the Error and the Context
What it is
The reliable way to get an AI to fix a bug: instead of saying 'it's broken' or 'that didn't work', you give it the exact error message, what you did to trigger it, what you expected, and the relevant code or files. Precise input turns a guessing game into a targeted fix.
Why it works
AI can only fix what it can see. A vague complaint forces it to guess at the problem and often 'fixes' the wrong thing or rewrites working code. The actual error text usually names the file, line, and cause; the reproduction steps tell it when it happens; the surrounding code shows the real state. With those, the model reasons about the specific failure instead of inventing a plausible one.
When to use it
Every time something breaks. Make it a reflex: copy the real error, note how you triggered it, and hand both to the AI along with the code involved.
When not to use it
If there's no concrete failure yet — you just want a design or approach — this isn't the move; describe the goal instead. This technique is specifically for fixing observed breakage.
Prompt
Something's broken. Here's the exact error message: <paste it>. Here's what I did to trigger it: <steps>. Here's what I expected instead: <expected>. The relevant code is in <files>. Diagnose the actual cause before changing anything, tell me what it is, then make the smallest fix — don't rewrite working code.Example
Instead of 'the login is broken, fix it', a maker pastes the console error, says 'happens when I submit the form with a valid email', and points at the auth file. The AI immediately identifies a missing await, fixes that one line, and leaves the rest untouched — instead of regenerating the whole login flow.
Advanced version
Give the AI access to the running app's logs or error output so it can see failures directly, and after a fix, add a small test that reproduces the original bug so it can't silently return. For stubborn bugs, ask the AI to first explain what it believes is happening and how to confirm it, so you catch a wrong theory before it edits code.
Common mistakes
- Saying 'it doesn't work' with no error text, forcing the AI to guess and often break something else.
- Letting the AI rewrite large sections to fix a small bug, discarding working code and adding new risk.
- Not capturing how to reproduce the bug, so neither you nor the AI can confirm it's actually fixed.