When AI Gets It Wrong: Debugging With an Assistant
Your AI assistant will write bugs, and sometimes get stuck fixing them. Practical patterns for debugging with an AI assistant: errors, causes and resets.
7 min read

Here's something the demos don't show: AI coding assistants write bugs. Not constantly, but regularly. And sometimes, when you ask them to fix one, they confidently make it worse, then fix that, then break the first thing again.
That's not a sign you're doing it wrong. It's just part of building software, with or without AI. The good news is that debugging with an AI assistant is a skill, and a few simple habits make a huge difference.
The debugging loop
Whatever the bug, the process is basically the same:
Let's go through each step, plus what to do when you're stuck going round and round.
1. Reproduce it on purpose
Before you can fix a bug, you need to be able to make it happen again. Write down the exact steps: "I log in, go to the settings page, change my name and click save. The page goes blank."
If you can't make it happen reliably, note when it does happen: only on your phone? Only after you've been logged in for a while? Only on the live site, not on your computer? Those details are often the biggest clue.
2. Find and read the full error
"It's broken" gives the AI nothing to work with. The actual error message usually tells it exactly where to look. Errors show up in a few places:
- The terminal where your app is running (for example, where you ran
npm run dev) - The browser console: open your browser's developer tools (F12 in most browsers, or Cmd+Option+I on a Mac) and look at the Console tab for red messages
- The Network tab in those same developer tools, for requests that failed
- Your host's logs, for problems that only happen on the live site (Vercel shows logs for each deployment)
Copy the whole error, including the lines underneath it (the "stack trace"). Those lines show which files and lines of code were involved.
3. Give the AI the full picture
Here's a bug report format that works far better than "fix it":
What I did: <the exact steps>
What I expected: <what should have happened>
What happened instead: <what actually happened>
The full error: <paste it, untouched>
What changed recently: <the last thing we worked on>
That last line matters more than you'd think. Most bugs appear right after a change, and the AI may not connect the two unless you tell it.
4. Ask for causes before any code
This is the habit that changes everything. Instead of letting the AI jump straight to a fix, ask it to think first:
Don't change any code yet. Based on this error, list the most likely
causes, ranked, and tell me how we could check which one it is.
When an AI rushes to fix something, it often guesses, and a wrong guess adds a second problem on top of the first. Asking for causes makes it reason about what's actually happening. Often the answer is "let's add some logging to see what value this has", and that's exactly the right move.
5. Fix one thing, then verify it yourself
Ask for one small, targeted fix. Then check it yourself, following the same steps you used to reproduce it. Don't take "this should fix it" as proof.
While you're reviewing the fix, watch for "fixes" that hide the problem instead of solving it: deleted tests, switched-off error checks, or an empty catch that swallows the error. I covered those red flags in reading AI-generated code when you're not a developer.
When you're stuck in a loop
Sometimes the AI tries a fix, it doesn't work, it tries another, that breaks something else, and twenty minutes later you're further back than when you started. Here's how to break out:
- Stop after two or three failed attempts. More attempts in the same conversation usually means more of the same guessing.
- Go back to the last working version. If you've been committing with Git, you can see recent checkpoints and set the messy changes aside:
git log --oneline # list recent commits
git stash # set aside uncommitted changes (bring them back with git stash pop)
- Start a fresh conversation. Long conversations fill up with failed ideas, and the AI can keep circling back to them. Write a short summary (the bug report above, plus "we already tried X and Y, which didn't work") and start over.
- Get a second opinion. A different AI assistant can approach the problem from another angle. I often use one assistant to build and another to challenge an idea when I'm stuck.
- Make the problem smaller. Ask the AI to help you build the tiniest version that still shows the bug. Removing everything else often makes the cause obvious.
Prevent the next one
The best debugging habit is making bugs easier to find in the first place:
- Work in small steps. If one small change breaks something, you know exactly where to look.
- Commit after everything that works. Every commit is a safe point you can go back to.
- Test after every change, not at the end of the day.
Bugs are part of the deal when you build things. With AI, you'll fix them faster than ever. You just have to be the calm one in the conversation. (For more on that mindset, see I'm not a developer — here's how I build apps with AI anyway.)
— Spencer
Share this post
Found this useful?
Get the next one in your inbox. No spam, unsubscribe anytime.
