AI

Debugging with AI: what works and what doesn’t

Avi, the Avenux Techspire mascot, illustrating: Debugging with AI: what works and what doesn't

Debugging is where most of a developer’s time goes, so it is natural to hope AI can take it off our hands. Sometimes it really does help. Other times you end up in a loop: paste error, get fix, new error, paste again, and an hour later the code is worse than when you started. Knowing which situation you are in makes a big difference.

Where AI is genuinely useful

Explaining error messages

Error messages are often written for people who already know the answer. Something like Cannot read properties of undefined (reading 'map') or a long Java stack trace can confuse a beginner. Asking an assistant “what does this error mean and what usually causes it?” is one of its best uses. You get a plain-language explanation and a list of likely causes to check.

Spotting common mistakes in small code

Paste a short function and the assistant can often spot an off-by-one error, a missing await, a wrong comparison operator or a variable used before it is assigned. These are patterns it has seen many times.

Suggesting where to look

“My form submits but the data never reaches the database. What should I check?” A good assistant will give you a checklist: is the request reaching the server, is the body parsed, is the query running, is there an error being swallowed. That checklist is valuable even if it cannot see your code.

Writing debug code for you

Ask it to add logging around a suspicious function, or to write a small test that reproduces the bug. This saves typing and gets you evidence faster.

Where AI struggles

Bugs that depend on your environment

Wrong file permissions on the server, a misconfigured web server, an environment variable missing in production, a database with different data than your laptop. The assistant cannot see any of that. It will guess, and the guesses can sound very convincing.

Bugs spread across many files

If the cause is in one file and the symptom shows up in another, and you only paste the second one, the assistant will try to fix the symptom. You get a patch that hides the problem instead of solving it.

Timing and state bugs

Race conditions, caching issues, things that fail “sometimes”. These need observation and evidence, not pattern matching.

Library version problems

Assistants may suggest code for an older or newer version of a library than the one you are using. If a suggested method “does not exist”, check your installed version against the docs.

The loop to avoid

The worst pattern looks like this:

  1. Paste error.
  2. Apply suggested fix without understanding it.
  3. New error appears.
  4. Repeat.

Each “fix” changes something, and soon you have several layers of changes, none of which addressed the real cause. If you have gone around twice without progress, stop. Undo the changes (this is why you commit working code often) and switch to a proper process.

A process that works, with or without AI

  1. Reproduce it. Find the exact steps that trigger the bug every time. If you cannot reproduce it, you cannot confirm a fix.
  2. Read the full error. The first line and the line in your code in the stack trace usually matter most.
  3. Form a guess. “I think user is undefined because the API returns nothing for new accounts.”
  4. Test the guess. Add a log, use a breakpoint, check the network tab. Get evidence.
  5. Narrow it down. Comment out half, check which half has the problem, repeat.
  6. Fix the cause, not the symptom. Then check the original steps again.

AI fits nicely into steps 2, 3 and 4. Use it to understand the error, to suggest guesses and to write the logging. Steps 1, 5 and 6 are mostly yours.

How to ask an assistant for debugging help

Give it what a senior colleague would need:

Environment: Node 20, Express, MySQL, running locally
What I'm doing: submitting the signup form
Expected: user row created, redirect to /dashboard
Actual: 500 error
Error from server log:
  Error: ER_DUP_ENTRY: Duplicate entry '' for key 'email'
Relevant code: [paste the route handler]
What I've checked: the form sends email correctly in the network tab

With this, the assistant can point out that the server is probably not reading the email from the request body, maybe because the body parser is missing. Without it, you get generic suggestions.

Also, ask it to explain its reasoning: “why do you think that is the cause?” If the reasoning does not match what you have observed, the suggestion is probably wrong.

Learn the tools AI cannot replace

Whatever you use AI for, get comfortable with these:

  • The browser developer tools, especially Console and Network tabs
  • Your editor’s debugger and breakpoints
  • Server logs and how to read them
  • git diff and git stash to see and undo changes

These give you facts. AI gives you suggestions. Good debugging needs both, but facts come first.

Debugging is one of the skills we spend a lot of time on with students, because it is what makes someone useful on a real project. If that interests you, see our training page.