AI Agents and Coding Assistants

How to Describe a Bug So an AI Assistant Can Help Fix It

What to include in a bug report for an AI assistant: expected and actual behavior, exact errors, steps, context and limits.

Key takeaways

  • State expected behavior and actual behavior as two separate sentences.
  • Copy error messages in full instead of paraphrasing them.
  • Give steps that reproduce the problem, with a small sample input.
  • Remove passwords, keys and personal data before sharing anything.
  • Treat the suggested cause as a hypothesis and confirm it with a test.

A useful bug description tells the assistant five things: what you expected, what happened instead, the exact steps that trigger it, the relevant code and error text, and what you have already tried. With those, an AI assistant can reason about your actual problem. Without them, it tends to offer a list of common causes and hope one fits.

A bug is any behavior of a program that differs from what was intended. The assistant cannot see your screen, remember how the program behaved last week or know what you meant it to do unless that information is in front of it. Some tools can read your files and run commands, which helps a great deal, but even they need to be told what "wrong" looks like.

Start with expected and actual

"The total is broken" could mean the program crashes, shows nothing, shows a wrong number or shows a right number in the wrong place. Write two sentences instead.

"I expected the cart total to include the 10 percent member discount. Instead, the total shows the full price, with no error."

The first sentence defines correct behavior, which the assistant cannot infer reliably. The second narrows the search. "No error" is itself information: the program is running to completion but following the wrong logic.

Add how often it happens. Every time, only for some users, only after midnight and only on one machine are very different problems. If it used to work, say so and mention what changed since, such as an update, a new setting or a recent edit.

Copy the evidence exactly

Error messages often contain the file name, line number and type of failure. Paste the whole message, including the stack trace, which is the list of function calls that led to the failure. The line people leave out is frequently the useful one.

Keep the text as text when you can. A screenshot may be cropped or hard to read. Include relevant log lines from just before the failure.

Share the code involved, and state the language, the main libraries and their versions if you know them. Behavior differs between versions, and an assistant may otherwise assume one you do not use.

Be careful about what travels with the evidence. Logs and configuration files can contain passwords, access keys, email addresses and customer details. Replace them with obvious placeholders. Check your employer's rules before sending any company code to an outside service, and see what not to type into a public chatbot.

Make it reproducible

Reproducing a bug means making it happen on demand. List the steps in order, starting from a known point.

  1. Open the order page with an empty cart.
  2. Add one item priced at 20.00.
  3. Sign in with a test member account.
  4. Look at the total. It shows 20.00 and should show 18.00.

Then shrink the problem. A minimal reproducible example is the smallest piece of code and data that still shows the failure. Remove parts one at a time. If the bug disappears when you remove something, you have learned something important. People often find the cause themselves during this step.

If you cannot reproduce it, say that plainly. Describe when it has occurred and ask what logging would help catch it next time. An assistant that is told a bug is intermittent is more likely to consider timing, shared data or outside services.

A before and after

A vague report and a useful one (hypothetical)
Vague Discount does not work Please fix my code Whole project pasted No steps or error details Useful Expected 18.00, got 20.00, no error Four steps from an empty cart The total function and a test account Already confirmed the member flag is true Do not change the database layout VS Vague Discount does not work Please fix my code Whole project pasted No steps or error details Useful Expected 18.00, got 20.00, no error Four steps from an empty cart The total function and a test account Already confirmed the member flag is true Do not change the database layout

The useful version is not much longer. It is more selective. It spends words on facts that rule possibilities in or out, and none on frustration or guesswork presented as fact.

Here is a compact template you can reuse.

What I expected:
What happened instead:
Steps to reproduce:
Exact error or log text:
Relevant code and versions:
What I already tried and the result:
Limits (what must not change):

Say what you tried and what you suspect

Listing failed attempts saves the assistant from suggesting them again. Give the result too: "I restarted the server; same total" is more informative than "restarting did not help."

You may include a guess, but label it. "I suspect the discount runs before sign-in finishes" is helpful. "The sign-in library is broken" stated as fact can send the assistant down a wrong path, and many assistants are inclined to agree with the user. To counter that, ask for alternatives: "Give three possible causes and a quick check that would separate them." The habit of telling you what you want to hear is worth keeping in mind here.

Ask for diagnosis before repair

If you ask only for a fix, you may get a change that hides the symptom. Ask first for an explanation of the likely cause and how to confirm it.

Good follow-up requests include these:

  • "Which line do you think produces the wrong value, and why?"
  • "What should I print or log to confirm that?"
  • "Write a test that fails now and should pass once fixed."
  • "Make the smallest change that fixes it, and list anything else it affects."

Run the suggested check and report the real result, even if it contradicts the theory. That new fact is more useful than rephrasing your original complaint. For a stubborn problem, one test at a time beats applying several suggested changes together, because you will not know which mattered or what the others broke.

A short worked exchange

Here is a hypothetical case. Someone writes, "My script that adds up expenses gives the wrong total." The assistant can only guess: rounding, a skipped row, text stored where a number should be.

The revised message says: "I expected 60.00 from three rows with amounts 10.00, 20.00 and 30.00. I get 50.00. No error. If I move the 10.00 row to the bottom, I get 30.00. Here is the loop."

Those results are revealing. With the rows in the order 10, 20, 30, the total of 50 equals 20 plus 30, so the first row seems to be missing. With the order 20, 30, 10, the same fault would give 30 plus 10, which is 40, yet the reported figure is 30. Either something else is going on or one of the observations is mistaken.

A good assistant, or a good colleague, would ask the person to check. Say the rerun shows a total of 40 for the second order. Now both results fit one explanation: the first row is never added, perhaps because the header line is removed early on and the loop then skips one more line, assuming the header is still there. Printing the first value the loop reads would confirm it.

The lesson is that precise numbers let anyone test a theory with arithmetic, and that an inconsistent report is worth rechecking before changing code.

Describe the surroundings

Many bugs live outside the code you pasted. Mention where the program runs: your laptop, a shared server, a phone, a spreadsheet service. Say whether it works anywhere else. "Fine on my computer, fails on the server" points toward differences in settings, versions, file paths, permissions or data.

Note anything about the input that is unusual, such as accented characters, very large files, empty fields or dates written in another country's style. If the failing data is private, create made-up data with the same shape and confirm that it still triggers the problem.

State your constraints too. Perhaps you cannot upgrade a library, cannot restart the service during the day or must keep an old file format. Without that, you may get a correct answer you are unable to use.

Verify the fix

A fix is confirmed when the original steps now give the expected result and nothing else has stopped working. Rerun your reproduction, then the existing tests, then a few neighboring cases: a non-member, an empty cart, two items, a very large quantity.

Watch for fixes that cheat. Examples include catching an error and ignoring it, adding a special case for your sample value or loosening a test until it passes. Reviewing AI-written code gives a broader checklist, and testing without fooling yourself explains how to keep the new test meaningful.

Add that test to your project if you have a test suite. It guards against the bug returning.

When the conversation goes in circles

After several failed attempts, a chat fills with outdated code and rejected ideas, and the replies can degrade. Start a new conversation with a fresh summary: the original report, what has been ruled out and the current code.

Consider other sources too. Official documentation and the issue tracker of the library involved may describe your exact problem. A colleague may know the history in a minute. Stepping through the program with a debugger, a tool that pauses execution so you can inspect values, often settles a question that discussion cannot.

For bugs involving security, money, health or safety, do not rely on an assistant's reassurance. Bring in someone qualified, and follow your organization's process for reporting the problem.

Common questions

Can non-programmers use this approach?

Yes. Expected behavior, actual behavior, steps and exact messages apply to a spreadsheet formula, an automation or an app you cannot read. Say what your skill level is so the explanation fits.

Should I paste my entire project?

Usually not. Large dumps bury the relevant part and may expose private material. Give the smallest set that shows the problem, and describe how the other parts connect. Tools that can search a project themselves still benefit from a pointer to where you think the trouble starts.

Written for 4ArtificialIntelligence with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 46 articles in AI Agents and Coding Assistants →

Latest news on this topic