Module 03 · Lesson 3.1
Reproducing a Failure
On this page
- What you will learn
- What reproducing a bug means
- Worked scenario: the TC7-0042 napkin invoice
- Step-by-step workflow for a minimal reproduction
- When you cannot reproduce the failure
- Using an AI assistant to help you reproduce a bug
- Conclusion and your next step
- Reusable prompt
- Expected output
- Common errors and fixes
- Validation checklist
- Hands-on exercise
- Knowledge check
- Frequently asked questions
- References
Imagine taking your car to a garage and saying, 'It makes a funny noise sometimes.' The mechanic cannot fix a noise they cannot hear. They will ask when it happens, how fast you were driving and whether it is cold. Then they will go for a drive and listen.
Software bugs are the same. A report such as 'the invoice looks wrong' is a clue, not yet a bug you can work on. In this lesson you learn to turn a report into a reproduction: a short, repeatable way to make the failure happen on your own machine. You will also learn to shrink it until nothing unnecessary is left.
The examples follow Tidewell Wholesale, a made-up supplier of catering goods, and its order service tidewell-orders. The company, the account codes and the people are invented. The code is a simplified version of the service's code, so you can run it without Django.
What you will learn
- Turn a vague report into steps, an expected result and an actual result.
- Shrink a failing case to the smallest input that still fails.
- Record the environment and commit so that anyone can repeat the failure.
- Decide what to collect when a failure cannot be reproduced yet.
Before you start
- Finish Recording Decisions in Short Form, or be comfortable reading a codebase you did not write.
- You can run the application, or a part of it, and its tests on your own machine.
- A defect report for a repository you are allowed to work on. If you plan to paste code into an AI assistant, read Sharing Code with an AI Assistant Safely first.
What reproducing a bug means
To reproduce a bug is to make it happen again, on purpose, in a place where you can watch it. Until you can do that, you are guessing. After you can do that, you can test every idea quickly.
There is a second reason to start here. A fix is only proven when the failure that happened before stops happening. If you never saw the failure, you cannot show that your change removed it.
- Reproduction
- A set of steps or a small script that makes the failure happen every time. Think of a recipe that always burns the cake.
- Minimal reproduction
- The shortest reproduction that still fails. It is like taking everything out of your bag until only the one thing that sets off the alarm is left.
- Expected result
- What should happen, and who says so. 'Expected' needs a source, such as a policy, a document or a person.
- Actual result
- What really happens, copied exactly. Write the numbers, not 'it looks wrong'.
- Environment
- Everything around the code that can change the result: the version of the code, the language version, the settings and the data.
Worked scenario: the TC7-0042 napkin invoice
On Monday the finance systems contact at Tidewell sends this message. It is the only report you have.
A good first move is to list what the report says and what it leaves out.
| What we know | What is missing |
|---|---|
| Account TC7-0042 is a contract account. | Is it only this account, or all contract accounts? |
| Order 58213: 40 packs of NAP-100 gave £44.80. | Does the same order give the same result today? |
| The accounts system says £45.20. | How does the accounts system get £45.20, and is it right? |
| The gap is £0.40, which is 1p per pack. | Is the gap always 1p per pack? |
You ask the finance systems contact two questions. First, what is the rule for the price? Second, what is the list price and discount for this account? The answers come back the same day.
- NAP-100 has a list price of £1.25 a pack.
- TC7-0042 has a 10% contract discount.
- Finance policy: round each contract unit price half up to the penny.
- So the correct unit price is £1.25 less 10%, which is £1.125. Rounded half up, that is £1.13. And 40 × £1.13 = £45.20.
Now the report has an expected result with a source: the finance policy. The invoice shows £44.80, which is 40 × £1.12. So the service seems to use £1.12 as the unit price. That is a first clue, but it is not yet proven.
Step-by-step workflow for a minimal reproduction
Step 1: Write the report in your own words
Write one sentence: 'For account X and product Y, the service gives A but B is expected.' If you cannot fill in every part, those gaps are your questions for the reporter.
What you should see: One sentence plus a short list of questions.
Step 2: Collect the exact input
Gather the values that went in: the lines of order 58213, the account's band and discount, and the list price. Use copies of data. Do not edit real records.
What you should see: A small table of inputs: NAP-100, quantity 40, band Contract, discount 10%, list price 1.25.
Step 3: Reproduce the original case
Run the code with those inputs. The script below does it. It is a simplified version of the service's pricing code, so you can run it without Django. Run it from the top folder of the repository.
Pythonrepro_nap100.py """Minimal reproduction: contract account TC7-0042 buying NAP-100.""" from decimal import Decimal from invoicing.totals import price_order PRICES = {"NAP-100": Decimal("1.25")} DISCOUNT = 10 # TC7-0042 has a 10% contract discount for qty, expected in [(1, "1.13"), (40, "45.20")]: got = price_order([("NAP-100", qty)], "Contract", PRICES, DISCOUNT) verdict = "OK" if str(got) == expected else "WRONG" print(f"qty {qty:>2}: expected {expected}, got {got} {verdict}")What you should see: You see the same wrong total as the report. If not, see the section on failures you cannot reproduce.
Step 4: Run it and read the result
Run the script. The output shows the original 40-pack order and the smallest order, one pack.
Bash python repro_nap100.pyWhat you should see: The output below. Run it twice and check that it never changes.
Step 5: Shrink the case
Change one thing at a time and run again. Can you use 1 pack instead of 40? Can you drop the other lines of the order? Keep every change that still fails, and undo every change that makes it pass.
What you should see: A smallest case: one line, quantity 1, NAP-100, account TC7-0042, unit price £1.12 instead of £1.13.
Step 6: Write the reproduction card
Record steps, expected, actual, environment and the commit you ran. Save it with the ticket so the next person starts from facts.
What you should see: A card like the one in the next section.
qty 1: expected 1.13, got 1.12 WRONG
qty 40: expected 45.20, got 44.80 WRONGWhat each part of the script does
PRICESholds the list price as aDecimal. ADecimalis Python's type for exact decimal numbers, such as money.DISCOUNT = 10is the contract discount of account TC7-0042, as a percentage.- The loop tries two cases: one pack (the minimal case) and 40 packs (the original order).
price_order(...)is the service's pricing function. In this simplified copy it returns the goods total, before VAT and delivery.- The last line prints expected and actual side by side and marks each as OK or WRONG.
- Report
'Invoice looks low'
- Questions
Account, order, rule
- Exact input
Lines, band, discount
- Reproduce
Same wrong total
- Shrink
One pack still fails
- Card
Steps, expected, actual
Each stage produces something you can write down.
The reproduction tells you something already. The gap for one pack is 1p, and for 40 packs it is 40p. So the problem seems to sit in the price of one pack, not in the order total. That is a clue for the next lesson. Do not treat it as a conclusion yet.
A reproduction card
Title: TC7-0042 contract price is 1p too low on NAP-100
Steps:
1. Check out commit 01d9417 (practice repository, branch main).
2. Run: python repro_nap100.py
Input: band Contract, discount 10%, NAP-100 list price 1.25.
Expected: unit price 1.13 (1.125 rounded half up, finance policy).
Actual: unit price 1.12. For 40 packs: 44.80, expected 45.20.
Environment: Python 3.12, no database, no Django (simplified copy).
Frequency: every run (3 of 3).
Not yet known: whether other prices or accounts are affected.Short enough to paste into a ticket.
Notice the last line. A good card says what is not known. That keeps the next person from assuming more than you proved.
The code in this module comes from a small practice repository built for these lessons. Its commit ids are therefore not the same as the commit 4f9c2e1 you met in Module 1.
When you cannot reproduce the failure
Sometimes you run the steps and everything works. That does not mean the report is wrong. It usually means your setup differs from the reporter's. Look for the difference before you do anything else.
| Possible difference | How to check | What to ask for |
|---|---|---|
| Different code version | Compare the commit you run with the one in production. | The version or release the reporter used. |
| Different data | Compare the account, discount and prices. | The exact order number and account. |
| Different settings | Compare the settings files and environment variables. | Which environment: live, test or local. |
| Time or date | Does the result depend on the day, the month end or a time zone? | The date and time of the failure. |
| Only sometimes | Run it many times. Look for what differs between runs. | A log line or request id from a failing run. |
Python's built-in logging module is the usual tool for leaving evidence. Its documentation is in the references at the end of this lesson. Log the inputs and the result at the point where the failure shows, and never log secrets or personal data.
Using an AI assistant to help you reproduce a bug
An assistant is good at turning a messy message into clear questions, and at drafting a first script from your description. It is poor at knowing what really happened in your system. It has never run your code.
- Good use: turn the report into a list of questions for the reporter.
- Good use: draft a small script from the inputs you collected. You run it and check the output.
- Good use: suggest ways to shrink the case. You try each one.
- Poor use: 'Does this bug exist?' The assistant cannot see your data or run your service.
- Poor use: pasting real customer records. Use invented or masked values.
The prompt below keeps the assistant to what you know. It asks for questions and a script, not for a cause.
Conclusion and your next step
You now have a failure you can repeat on demand: a one-pack case that gives £1.12 instead of £1.13, and a card that records the steps, the expected result, the actual result and the commit. That card is what makes the rest of the module possible.
Your next step: list the possible causes and test each one cheaply in Hypotheses and Experiments. Then try the exercise on a defect in your own repository, so that you finish with a real reproduction card.
For more on prompting during debugging, read AI-Assisted Debugging: A Scientific-Method Prompt Framework. The module overview, Debugging and Root-Cause Analysis, shows how the five lessons fit together.
Reusable prompt
Reproduction builder
Turns a vague bug report into questions for the reporter and a first reproduction script, without asking the assistant to guess the cause.
Help me reproduce a bug. Do not suggest a cause yet.
Report (fictional): "Invoices for contract account TC7-0042 are lower than our accounts system. Order 58213 shows £44.80 for 40 packs of NAP-100 napkins. We expected £45.20."
What I already know:
- NAP-100 list price is 1.25. Account TC7-0042 has a 10% contract discount.
- Finance policy: round each contract unit price half up to the penny.
- The service is Python. The pricing function is price_order(lines, band, prices, contract_discount). It returns the goods total as a Decimal. I will run everything myself.
Please give me:
1. Up to five questions to ask the reporter. Mark which ones I cannot answer from the code.
2. A reproduction card with Steps, Expected, Actual, Environment and Not yet known.
3. A short Python script that runs the original order and a one-pack order and prints expected and actual.
4. Two ways to shrink the case further.
Use only the facts above. If something is missing, say so instead of inventing it.Show the reusable template
Replace each {{placeholder}} with your own details.
Help me reproduce a bug. Do not suggest a cause yet.
Report: "{{report_text}}"
What I already know:
{{known_facts}}
Language and entry point: {{language_and_function}}. I will run everything myself.
Please give me:
1. Up to five questions to ask the reporter. Mark which ones I cannot answer from the code.
2. A reproduction card with Steps, Expected, Actual, Environment and Not yet known.
3. A short script that runs the original case and a smaller case and prints expected and actual.
4. Two ways to shrink the case further.
Use only the facts above. If something is missing, say so instead of inventing it.Expected output and limitations
A short list of questions, a card with every field filled from your facts, and a small script that prints expected and actual. The assistant should say 'not known' where your facts run out. It should not name a cause.
Questions for the reporter
1. Which accounts besides TC7-0042 show lower invoices?
2. Is the gap always 1p per pack, or does it vary?
3. Was the order priced when it was placed, or re-priced later?
Reproduction card
Steps: call price_order([("NAP-100", 1)], "Contract", prices, 10).
Expected: 1.13. Actual: to be filled in after you run it.
Not yet known: whether other products are affected.
Ways to shrink: use one pack instead of 40; remove other lines.Limitations to keep in mind
- The sample is illustrative. The assistant has not run your code, so 'Actual' is something you fill in.
- It may add questions that do not matter. Keep the ones that change what you do next.
- A script it writes may use a different function name or import path. Check it against your repository.
- If it names a cause, treat that as an idea to test later, not as a result.
Common errors and how to fix them
Reproducing with different data from the reporter's
Why it happens: You used a convenient test account instead of the real one's band, discount and prices.
Fix: Copy the exact inputs from the report. Change them only when you are shrinking the case, one change at a time.
Changing several things at once while shrinking
Why it happens: You removed lines, changed quantities and edited the settings in one go, so you cannot tell which change mattered.
Fix: Make one change, run, record the result, and then decide. Keep changes that still fail.
Reproducing it on a different version of the code
Why it happens: Your branch is older or newer than the version that produced the report.
Fix: Write the commit id on the card. Check that the version you run matches the version that failed.
Validation checklist
Tick each item once you have confirmed it.
Hands-on exercise
Write a reproduction card for a real defect
Pick one defect, real or seeded, in a repository you are allowed to work on. Reproduce it, shrink it to a minimal case and write a reproduction card.
You will need
- A defect report or ticket, or a bug you can seed yourself, for example by changing a rounding rule in a copy of the code.
- A checkout you can run locally, with its test command.
- The card format from this lesson.
Acceptance criteria
Your work is done when every one of these is true.
Hints (3)
- If the report is thin, write the questions you would ask before you write any code.
- If you cannot reproduce the failure, record what differs between your setup and the reporter's.
- Start with the largest case from the report and shrink from there.
Show a model answer
A strong answer opens with the report in one sentence, then lists inputs copied from the source. It shows the original case failing and a smaller case that also fails, with the steps used to shrink it. The expected result names its source. The card ends with what is not known. A weak answer says 'invoice looks wrong', skips the version and describes the result instead of copying it.
Knowledge check
Choose an answer, then check it. Nothing is recorded — this is for you.
Show the answer and explanation
Answer: B. An exact example lets you see the failure and test ideas against it. Searching and fixing first is tempting but changes code without evidence. An assistant that has not run your code can only guess.
Show the answer and explanation
Answer: B. A smaller case that still fails removes things that are not needed. It points towards the part that is. It is a clue, not a proof. The failure is not fixed, and the report was right.
Show the answer and explanation
Answer: B. Most 'cannot reproduce' cases come from a difference between setups. Closing the ticket drops a real problem. Changing code without seeing the failure leaves you unable to tell whether you fixed it.
Frequently asked questions
What is a minimal reproduction?
It is the smallest set of steps or the shortest script that still makes the bug happen. It has nothing extra in it. This makes the bug easier to understand and easier to test.
Why not just fix the bug if I can guess the cause?
A guess can be wrong, and without a reproduction you cannot check it. You may also hide the symptom while the cause stays. Reproduce first, then test the guess.
How many times should I run a reproduction?
Run it at least three times. If the result changes between runs, you have found something important: the failure depends on something that varies, such as time or order of events. Record that in the card.
Can I use real customer data in my reproduction?
Prefer invented or masked data. Copy only the values that matter, such as the price and the discount. Check your organisation's rules before sharing anything with an AI service.
- 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.
- pytest documentation(opens in a new tab)
pytest · Official documentation · For turning a reproduction script into a test.
- logging — Logging facility for Python(opens in a new tab)
Python Software Foundation · Official documentation · For leaving evidence when a failure cannot yet be reproduced.
- git-log Documentation(opens in a new tab)
Git project · Official documentation · For finding the commit you are running.
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.