Blog / Build with AI /
Debugging with AI: give it the error, not the frustration
“It doesn’t work. Please fix.”
Every one of us has typed some version of that to an AI assistant at eleven at night. It almost never helps. The AI has no idea what “it” is, what “work” meant, or what you tried. So it guesses. Then you paste the guess, the guess fails, and you type a more irritated version of the same sentence.
The fix is not a cleverer prompt. It’s handing over the facts. An error message is a gift: it tells you, in the computer’s own words, what went wrong and often where. Give the AI that, and the conversation changes.
Why the error message matters so much
Think of calling a mechanic. “My car’s being weird” gets you a shrug. “There’s a grinding noise from the front left when I brake at low speed, started after I hit that pothole” gets you a diagnosis.
Error messages are the grinding noise. They usually contain:
- What kind of problem it is: a syntax error, a missing file, a permission problem, a null value.
- Where it happened: a file name and a line number.
- The chain of events: a stack trace showing which function called which.
AI can read all of that in a second. It cannot read your mood.
What to give it: the debugging bundle
When something breaks, collect five things before you ask.
- The exact error message, copied, not retyped and not paraphrased. Include the whole thing, including the stack trace.
- The code involved. The function that failed, and a little around it. Not your entire project, and not one line with no context.
- What you expected to happen.
- What happened instead.
- What changed since it last worked. New plugin, new version, an edit you made ten minutes ago.
Then the environment: what language or platform, which version, where it runs. “WordPress 6.4 on PHP 8.2” or “a Google Apps Script bound to a Sheet” changes the answer.
A good message looks like this:
I’m editing a WordPress plugin (PHP 8.2, WordPress 6.4). After I added the function below, the site shows a white screen. Here is the line from
debug.log:
PHP Fatal error: Uncaught Error: Call to undefined function lus_get_date() in /wp-content/plugins/last-updated/last-updated.php:18Here is the code around line 18: (code)
Expected: the shortcode prints the modified date. Actual: white screen on any page with the shortcode. What changed: I renamed a function from
get_datetolus_get_datean hour ago.What is the likely cause? Explain it before suggesting a fix.
The error says a function is undefined. The “what changed” line says a function was renamed. A human or an AI can connect those in seconds: somewhere the old name is still being called, or the new function isn’t defined where it’s called.
Say what you want back
Debugging prompts work best when you control the shape of the answer.
- “Explain the cause first, then the fix.” Understanding the cause is how you learn, and how you spot a wrong diagnosis.
- “Give me the smallest change that fixes it.” Otherwise the AI may rewrite the whole function and introduce new bugs.
- “Show only the changed lines.” Easier to review.
- “List two or three possible causes, most likely first, and how to test each.” This one is gold when the error is vague.
Where to find the error in the first place
Often the hard part is finding an error at all, because a site or a script simply fails quietly. A few places to look:
- Browser console: open developer tools and check the Console tab for JavaScript errors. Red text is your friend.
- Network tab: shows failed requests and their status codes (404, 500, 403).
- WordPress
debug.log: withWP_DEBUG_LOGturned on in a test site, PHP errors are written towp-content/debug.log. - Server error logs: your host’s control panel usually has them.
- Apps Script Executions: shows each run and its error.
- The terminal: where a build or install command printed its failure. Copy the first error, not only the last line. The first error often causes the rest.
If you’re debugging a WordPress problem that isn’t your own code, the method is similar. I use the same approach in fixing WordPress errors with AI help.
Reproduce it, then shrink it
Before you ask for help, try to make the problem happen reliably. “Sometimes the form fails” is hard. “The form fails when the name contains an apostrophe” is nearly solved.
Then shrink it. Remove everything that is not needed to see the bug. A ten-line example that fails beats a thousand-line project that fails, for you and for the AI. Often, by the time you have shrunk it, you’ve found the bug yourself. Programmers call that rubber-duck debugging: explaining the problem out loud is half the fix.
Don’t let it loop
The classic trap: the AI suggests fix A, it fails, you say “still broken”, it suggests fix B, which is fix A with a different variable name, and so on. After three rounds you’ve changed six things and no longer know what the original code looked like.
Rules to break the loop:
- Change one thing at a time, and test after each.
- Report the new result precisely. “Now I get a different error: (paste)”. That is information. “Still broken” is not.
- Keep a copy of the working version before experimenting, so you can go back. A version-control habit pays off hugely here.
- If two fixes fail, step back. Ask, “What assumptions are we making that might be wrong?” The mistake is often in the setup (wrong file, wrong environment, a cache) rather than in the code.
- Start a fresh chat with a clean summary if the conversation has grown long and tangled. The AI may be working from earlier wrong assumptions.
Check the fix before you accept it
AI explanations are persuasive even when wrong. Before you apply a fix:
- Does the explanation match the error? If the error says “undefined variable” and the answer talks about caching, be suspicious.
- Does the suggested function or setting exist? Look it up in the official documentation. See AI hallucinations in code: spotting invented functions.
- Is it a patch over the symptom? Wrapping everything in
try/catchor silencing a warning hides the problem and doesn’t solve it. - Does it add something risky, such as disabling security checks “to make it work”? Say no.
Then test the fix for the original problem and for a couple of neighbours, to see if you’ve broken something next door.
What not to paste
An error log can contain things you shouldn’t share: API keys, database passwords, file paths revealing a client’s name, customer details. Scan what you paste and replace sensitive values with placeholders such as YOUR_API_KEY. The reasons are covered in what an API key is and why you should never share it. If a key did end up in a chat, treat it as exposed and replace it.
When the AI genuinely can’t help
Some problems are beyond what a chat can solve, and it’s better to know it:
- A bug that depends on something the AI can’t see, like your hosting configuration, a conflict with another plugin, or what’s cached on a CDN.
- A problem in a closed system where the vendor needs to look at your account.
- An issue caused by a recent update that the AI hasn’t heard about.
In those cases the AI is still useful for drafting a clear report: what you did, what you expected, what happened, error text, steps to reproduce. That same note works as a support ticket to a host or plugin author, and getting good answers from support is a skill of its own.
Key takeaways
- Paste the exact error, the code around it, what you expected, what happened and what changed.
- Ask for the cause before the fix, and for the smallest change.
- Reproduce and shrink the problem before you ask.
- Change one thing at a time and report new results precisely.
- Check the fix against official documentation, and keep a working copy.
- Strip secrets out of anything you paste.
Related reading
- AI hallucinations in code: spotting invented functions
- How to describe a tool to AI so it builds the right thing
- Building a Shopify app idea with AI: where it gets hard
Next time something breaks, spend two minutes collecting the five items before you open the chat. Then notice how much shorter the conversation is. What’s the error you’ve been avoiding looking at this week?