Module 03 · Lesson 3.4
Debugging with an AI Assistant
On this page
- What you will learn
- What an AI assistant can and cannot do when debugging
- Build an evidence pack: what to give the assistant
- Worked scenario: the assistant blames VAT
- Step-by-step workflow for assistant-aided debugging
- How to judge an assistant's claims
- Conclusion and your next step
- Reusable prompt
- Expected output
- Common errors and fixes
- Validation checklist
- Hands-on exercise
- Knowledge check
- Frequently asked questions
- References
Think of an AI assistant as a very well-read colleague who has never seen your system. Ask a good question with good evidence, and the answer can save you an hour. Ask a vague question, and you get a confident answer that may be about someone else's bug.
This lesson shows how to give an assistant the right evidence, how to ask for ranked hypotheses rather than a fix, and how to test what it says. The example continues the napkin invoice bug from the fictional Tidewell Wholesale. In it, the assistant confidently blames VAT. You will see how cheap experiments show what is true.
What you will learn
- Build an evidence pack that gives an assistant what it needs and nothing it should not have.
- Ask for ranked hypotheses with experiments, not for a patch.
- Sort each claim into verified, plausible or unsupported, and test it.
- Record the assistant's role honestly in your hypothesis log and write-up.
Before you start
- Finish Using History and Bisection, or have a reproduced defect with some evidence about it.
- Your reproduction card and hypothesis log from the earlier lessons.
- An AI assistant approved for the code you will share. Read Sharing Code with an AI Assistant Safely if you are unsure what you may paste.
What an AI assistant can and cannot do when debugging
An assistant is a language model. It predicts useful text from patterns it has seen. That makes it good at some debugging jobs and poor at others. The difference is simple: it can reason about what you show it, but it cannot see or run anything else.
| Job | How well it works | Your check |
|---|---|---|
| Explain what a function does | Often well, if you paste the function. | Read the code yourself and run it. |
| Suggest possible causes | Often well, as a source of ideas. | Each idea goes into the log as a hypothesis. |
| Propose cheap experiments | Well, if it knows your evidence. | You run each one and record the real result. |
| Say which function is broken | Poorly, if you did not paste it. | Treat it as a guess about code it has not seen. |
| Write a fix | Fine as a draft. | It needs a failing test first. See the next lesson. |
- Evidence pack
- The set of facts you give the assistant: the reproduction, the expected result and its source, the code involved, and what you have already ruled out. It is like handing a doctor your test results, not just saying 'I feel ill'.
- Confident wrong answer
- A fluent, certain-sounding answer that is false. An assistant does not feel unsure. A tone of certainty tells you nothing about accuracy.
- Anchoring
- Getting stuck on the first idea you hear. If the assistant names a cause early, you may stop looking for others. Counter it with a ranked list of rivals.
Build an evidence pack: what to give the assistant
A good pack is small and exact. It contains these parts.
- The symptom, with numbers. Expected and actual, copied exactly, and the source of 'expected'.
- The minimal reproduction. The one-pack case, not the whole story of the ticket.
- The code that runs. Paste the function you suspect and the ones it calls. Do not ask about code you have not pasted.
- What you ruled out. Your hypothesis log. This stops the assistant repeating ideas you have already killed.
- The rules of the answer. Ask for hypotheses, predictions and cheap experiments. Say 'do not write a fix yet'. Ask it to say what it cannot know.
Here is the function you would paste for the napkin bug. It is a simplified version of legacy/pricing_v1.py, so you can run it without Django.
"""Contract pricing, kept from the original pricing service."""
def contract_unit_price(list_price, discount_percent):
"""Unit price for a contract customer, rounded to the penny."""
price = float(list_price)
unit = price * (1 - discount_percent / 100)
return round(unit, 2)The function in its current, faulty form.
What each part does
float(list_price)turns the price into a float, which is Python's ordinary decimal-point number type.1 - discount_percent / 100is the share the customer pays. For a 10% discount, it is 0.9.price * ...multiplies the list price by that share to get the unit price.round(unit, 2)is the built-in rounding to two decimal places, which gives the penny.
What to leave out
- Secrets: passwords, API keys, the hard-coded EDI token.
- Real customer names, emails and invoice data. Use the invented account code and the product code instead.
- Large unrelated files. More text means more noise and a bigger risk of leaking something.
Worked scenario: the assistant blames VAT
You send the pack with the prompt at the end of this lesson. The reply is below. It is an illustrative reply, written to show a typical pattern: fluent, confident, partly useful and partly wrong.
The most likely cause is rounding in the VAT calculation. In invoicing/totals.py the vat() helper probably rounds each line before adding 20%, which could lose a penny per pack.
Second most likely: floating-point error. Floats cannot store 1.125 exactly, so the product is slightly off and rounds the wrong way.
Suggested fix: wrap the result in Decimal, for example Decimal(round(unit, 2)), and round VAT once at the end.
Less likely: a wrong discount stored for the account.Read it as a list of claims. Each claim needs a check before it goes anywhere near the code. Start by sorting them.
| Claim | Is it about code you pasted? | How to test it | Cost |
|---|---|---|---|
A vat() helper in invoicing/totals.py rounds each line. | No. You never pasted it, and the assistant invented the name. | Compare the size of the gap with the largest possible VAT rounding error. | One minute |
| Floats cannot store 1.125 exactly. | Yes, but it is a fact about floats. | Print the exact stored value. | One minute |
Decimal(round(unit, 2)) fixes it. | Yes, it is a proposed fix. | Run it on the failing case. | One minute |
| A wrong discount is stored. | No. The stored value was not pasted. | Already checked in the hypothesis log: the discount is 10%. | Done |
Test 1: is it VAT?
A VAT amount is rounded once to the penny, so the rounding can be wrong by half a penny at most. The invoice is 40p short. The script compares the two.
"""Test the claim 'the gap is VAT rounding'."""
from decimal import Decimal
invoice = Decimal("44.80")
expected = Decimal("45.20")
gap = expected - invoice
# Rounding a VAT amount once to the penny can be wrong by half a penny at most.
largest_vat_rounding_error = Decimal("0.005")
print("gap on the invoice :", gap)
print("largest VAT rounding error:", largest_vat_rounding_error)
print("VAT rounding can explain it:", gap <= largest_vat_rounding_error)gap on the invoice : 0.40
largest VAT rounding error: 0.005
VAT rounding can explain it: Falsegapis the missing amount: expected minus invoiced.largest_vat_rounding_erroris the biggest mistake that rounding one VAT amount to the penny can make.- The last line asks whether the rounding error could be as big as the gap. It could not.
The VAT claim is refuted. It also pointed at a helper that your code does not have. The assistant filled a gap with an invention. This is a classic warning sign: names and file paths that you did not give it.
Test 2: does it say the right thing about floats?
The second claim is partly right. Float arithmetic is involved. But the detail is wrong. You already printed the exact stored value in the experiments, and it is easy to run again.
factor : 0.9
product : 1.125
stored exactly : 1.125
round(product, 2): 1.12The float stores 1.125 exactly. The product is not 'slightly off'. The real story has two effects, found in the earlier lessons. An exact half is sent to the even digit by round(). And some other prices are stored just below a half. So the assistant had the right family of cause with a wrong detail. If you had repeated its story in your write-up, a reader who knows floats would have doubted the rest.
Test 3: does the suggested patch work?
"""Test the assistant's first fix: wrap the float result in Decimal."""
from decimal import Decimal
unit = Decimal(round(1.25 * (1 - 10 / 100), 2))
print("Decimal(round(...)) gives:", unit)
print("quantized to the penny :", unit.quantize(Decimal("0.01")))Decimal(round(...)) gives: 1.12000000000000010658141036401502788066864013671875
quantized to the penny : 1.12round(1.25 * (1 - 10 / 100), 2)is the float calculation that the service does today. It gives 1.12.Decimal(...)of that float only copies the number. The rounding has already happened, and wrongly.quantize(...)then rounds to the penny, which changes nothing, because 1.12 is already at the penny.
The patch still gives 1.12. It changes the type of the number but not the answer. Applying it would have looked like a fix and fixed nothing. A test that fails first, which you meet in the next lesson, would have caught it at once.
Step-by-step workflow for assistant-aided debugging
Step 1: Reproduce first, without the assistant
You need a failing case before you ask anything. Without one, you cannot test what it says.
What you should see: A reproduction card.
Step 2: Build the evidence pack
Put in the symptom, the minimal reproduction, the code you paste, and the hypothesis log so far. Remove secrets and real customer data.
What you should see: One block of text that a stranger could follow.
Step 3: Ask for ranked hypotheses, not a fix
Ask for hypotheses with predictions and cheap experiments. Say 'do not write a fix yet' and 'say what you cannot know from this'.
What you should see: A list you can add to your log.
Step 4: Sort every claim
For each claim, ask: is it about code I pasted? Is it a fact I can check in a minute? Mark it verified, plausible or unsupported.
What you should see: A table like the one above.
Step 5: Test the cheapest claims first
Run a small script for each. Record the real output, not the assistant's prediction.
What you should see: Results in the hypothesis log.
Step 6: Go back with the results
Tell the assistant what you found, and ask for the next experiment. Only when a cause is confirmed do you ask for a draft fix, as a diff with a test.
What you should see: A narrower list, and a cause you have proved.
- Reproduce
You run it
- Evidence pack
Facts, code, ruled out
- Ask
Ranked hypotheses
- Sort claims
Pasted or invented?
- Test
Small scripts
- Report back
Real results
You hold the evidence. The assistant supplies ideas.
How to judge an assistant's claims
| Warning sign | Why it matters | What to do |
|---|---|---|
| Names a file, function or line you never pasted | It is guessing from habit. The thing may not exist. | Search your repository for it with git grep. If it is absent, discard the claim. |
| Says 'definitely' or 'the cause is' | Certainty is a tone, not evidence. | Ask: 'What result would prove you wrong?' |
| Gives a precise but unchecked fact | Details sound true even when they are false, like the claim about 1.125. | Check the exact detail with a one-line script. |
| Proposes a fix before any cause is confirmed | A patch can hide the symptom. | Ask for experiments first. Require a failing test. |
| Changes its answer when you push back | It follows you, not the facts. | Go back to the evidence, not the argument. |
Do not ask the assistant which of its ideas is more likely and then trust the answer. That only repeats the guess in a more ordered form. Ask it for a test that would tell two ideas apart. Then run the test.
A second assistant agreeing with the first is not evidence either. Two models can make the same mistake. Only your own run counts.
Conclusion and your next step
An assistant speeds up debugging when you hand it a good evidence pack and treat its answers as hypotheses. In the napkin case it blamed VAT (refuted in a minute), told a partly wrong story about floats (corrected by one printed value) and offered a patch that changed nothing (shown by one more run). Evidence won every time.
Your next step: now that the cause is confirmed, fix it and prove the fix. Continue with Fixing and Proving the Fix. Try the exercise first, so you have a real log to fix from.
For more prompts, read 10 ChatGPT & Claude Prompts for Debugging Code Faster and How to Prevent AI Hallucinations in Code Generation. The prompt library has Intermittent Failure Investigation Plan for bugs that only happen sometimes.
Reusable prompt
Evidence-pack debugging prompt
Asks for ranked hypotheses with predictions and cheap experiments, from evidence you supply, with no fix yet and an honest list of unknowns.
I am debugging a defect and I will run every experiment myself. Do not write a fix yet.
Symptom: contract account TC7-0042 buys 40 packs of NAP-100 and is charged 44.80. The accounts system expects 45.20. One pack gives 1.12 where finance policy (round each contract unit price half up to the penny) gives 1.13. List price 1.25, contract discount 10%.
Minimal reproduction: price_order([("NAP-100", 1)], "Contract", prices, contract_discount=10) returns 1.12.
Code (the only code you may reason about):
def contract_unit_price(list_price, discount_percent):
price = float(list_price)
unit = price * (1 - discount_percent / 100)
return round(unit, 2)
Already ruled out: VAT and whole-order rounding (the gap grows 1p per pack); a wrong stored discount (it is 10%).
Please give me:
1. Up to four ranked hypotheses. For each: what I would see if it were true, and one cheap experiment.
2. For each hypothesis, say whether it is about code I pasted or about code you have not seen.
3. A list of what you cannot know from this evidence.
Do not name files, functions or settings that I did not mention.Show the reusable template
Replace each {{placeholder}} with your own details.
I am debugging a defect and I will run every experiment myself. Do not write a fix yet.
Symptom: {{symptom_with_numbers_and_source_of_expected}}
Minimal reproduction: {{minimal_reproduction}}
Code (the only code you may reason about):
{{pasted_code}}
Already ruled out: {{hypothesis_log_summary}}
Please give me:
1. Up to {{number_of_hypotheses}} ranked hypotheses. For each: what I would see if it were true, and one cheap experiment.
2. For each hypothesis, say whether it is about code I pasted or about code you have not seen.
3. A list of what you cannot know from this evidence.
Do not name files, functions or settings that I did not mention.Expected output and limitations
A short ranked list in which each hypothesis has a prediction and an experiment, a note on whether it concerns pasted code, and a closing list of unknowns. It should name nothing that you did not paste, and it should not contain a fix.
1. Built-in round() sends an exact half to the even digit (about the pasted code).
If true: 1.125 rounds to 1.12 but 1.135 rounds to 1.14.
Experiment: compare round() with Decimal ROUND_HALF_UP on a few prices.
2. Float products stored slightly below a half (about the pasted code).
If true: some prices round down even though the true value is a half.
Experiment: print Decimal(product) for several prices.
3. A different price is used for this account (about code not seen).
If true: other products on the account are wrong too.
Experiment: price one other product for the same account.
Cannot know from this evidence: how the discount is stored, which other callers use this function, and whether past invoices were affected.Limitations to keep in mind
- The sample is illustrative. The assistant has not run any of the code.
- Even a good answer can contain a wrong detail. Check each claim with a script.
- It may still mention files or helpers you did not give it. Search your repository before believing it.
- Its ranking reflects patterns it has seen, not your system. Rank by your own evidence.
Common errors and how to fix them
Asking 'why is my code wrong?' with no evidence
Why it happens: You paste a whole file and a one-line complaint, so the assistant has to guess the symptom.
Fix: Send an evidence pack: numbers, a minimal reproduction, the code that runs and what you ruled out.
Applying a suggested fix before any test
Why it happens: The answer sounded sure, and the patch was only one line.
Fix: Ask for experiments first. Write a failing test, then apply the patch and see the test pass.
Pasting secrets or real customer data
Why it happens: You copied a file or log as it was.
Fix: Remove tokens, keys and personal data before pasting. Use invented account codes. Follow your organisation's rules.
Validation checklist
Tick each item once you have confirmed it.
Hands-on exercise
Run an assistant-aided investigation
Take your reproduced defect and its hypothesis log. Build an evidence pack, ask an assistant for ranked hypotheses, and test at least three of its claims yourself.
You will need
- Your reproduction card and hypothesis log.
- The function or function pair you suspect, with secrets and personal data removed.
- An assistant that your organisation allows you to use with this code.
Acceptance criteria
Your work is done when every one of these is true.
Hints (3)
- If the assistant names a function you did not paste, search for it with
git grepfirst. - If you have no sensitive-data approval for an assistant, practise with a small invented example.
- If every claim seems right, ask what result would prove it wrong and run that.
Show a model answer
A strong answer includes the exact prompt, the assistant's reply, and a claims table with a test and a result for each. At least one claim was refuted by a real run, and one detail was corrected. The log credits the assistant for ideas and shows that you produced the facts. A weak answer pastes the reply, applies the first patch and reports that 'the assistant fixed it'.
Knowledge check
Choose an answer, then check it. Nothing is recorded — this is for you.
Show the answer and explanation
Answer: B. Without the code, the claim is a guess, so test it. Editing the helper on that guess may hide the symptom rather than diagnose it. Asking the assistant to choose repeats the guess.
Show the answer and explanation
Answer: B. A passing case without a test that failed first does not show that the patch fixes the cause. It may pass by luck. Another assistant's approval is another opinion, not a test.
Show the answer and explanation
Answer: B. Evidence and a clear task produce checkable answers. A vague request leaves the assistant to guess. Telling it to act as an expert changes its tone, not its access to your system.
Frequently asked questions
Can an AI assistant find the bug for me?
It can suggest causes and explain code, which often saves time. But it cannot run your system, so it cannot prove anything. Treat its answer as an idea to test, and keep the proof for yourself.
What should I never paste into an assistant?
Passwords, keys, tokens, real customer data and anything your organisation forbids. Use invented values instead. If you are not sure what is allowed, ask before you paste.
Why does the assistant sound so sure when it is wrong?
It writes fluent text whether or not it is right. Confidence in its tone does not measure accuracy. This is why you check every claim with a small test.
Is it a problem if the assistant's idea turns out to be right?
No, but test it anyway, because a right idea can still contain wrong details. Record in your log that it came from the assistant and what you did to confirm it.
- Written by
- PromptFable Editorial
- Last updated 19 Nov 2026
- Review
- Reviewed by Waseem Nadir, Technical Reviewer
- Last reviewed 27 Nov 2026
References
Primary sources for the technical details in this lesson. Vendor platforms change — check the official page if anything here looks different from what you see.
- pdb — The Python Debugger(opens in a new tab)
Python Software Foundation · Official documentation · For looking inside a program yourself, whatever the assistant says.
- 15. Floating-Point Arithmetic: Issues and Limitations(opens in a new tab)
Python Software Foundation · Official documentation
- git-grep Documentation(opens in a new tab)
Git project · Official documentation · For checking whether a name the assistant used exists in your repository.
PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.