ForkFree

Prompts / Coding

Root-Cause Bug Fix With Honest Testing

You get a small, targeted fix with a test that proves it, plus an honest list of what was and was not checked. It works because it sets a clear goal, limits the scope, and tells the AI when to carry on and when to stop.

Struggled in our testThe diff is sound and the arithmetic checks out, but the reply never searched the working directory, added the test or ran anything. It also claimed it had no file or shell access, which is doubtful given the environment. That fails the "work until fixed" and "run tests" steps, even though the gaps were disclosed honestly.

The prompt

Act as a careful senior software engineer fixing a bug in an existing codebase.

Task: Find the root cause of the bug described below and make the smallest change that fixes it. Work until it is fixed. Keep going through recoverable problems, such as a failing command or a missing file, and stop only if you hit a real blocker that needs my decision.

Bug report: {bug_report}
Relevant code: {code_snippet}
Out of scope: {exclusions}

Steps:
1. State the outcome you are aiming for, then trace the fault back to its root cause rather than patching the symptom.
2. Change only what the cause requires. Do not refactor, rename or touch anything listed as out of scope.
3. Run the tests or checks available to you, and add one test that fails before the fix and passes after it.
4. Report results honestly. Say plainly what you ran, what passed, what failed, and what you could not verify.
5. Stop once the bug is fixed and verified, or when a genuine blocker stops you.

Output:
Root cause in two sentences, the minimal diff, the test results in a short list, and a final line marked "Not verified:" listing any gaps.

Change the parts in curly braces. Use it when an AI coding assistant tends to over-edit or claim a fix works without running anything.

What happened when we ran it

We sent

Act as a careful senior software engineer fixing a bug in an existing codebase.

Task: Find the root cause of the bug described below and make the smallest change that fixes it. Work until it is fixed. Keep going through recoverable problems, such as a failing command or a missing file, and stop only if you hit a real blocker that needs my decision.

Bug report: Customers in the UK are charged VAT twice at checkout. An order of £50.00 shows a total of £60.00 plus another £10.00 line, giving £70.00. It started after last Tuesday's release and only affects orders with a discount code applied.
Relevant code: function calculateTotal(items, discount) {
  let subtotal = items.reduce((sum, i) => sum + i.price, 0);
  let vat = subtotal * 0.2;
  subtotal = subtotal + vat;
  if (discount) { subtotal = subtotal - discount.amount; }
  return subtotal + subtotal * 0.2;
}
Out of scope: Do not change the discount code validation, the database schema, or the checkout page styling. Do not upgrade any dependencies.

Steps:
1. State the outcome you are aiming for, then trace the fault back to its root cause rather than patching the symptom.
2. Change only what the cause requires. Do not refactor, rename or touch anything listed as out of scope.
3. Run the tests or checks available to you, and add one test that fails before the fix and passes after it.
4. Report results honestly. Say plainly what you ran, what passed, what failed, and what you could not verify.
5. Stop once the bug is fixed and verified, or when a genuine blocker stops you.

Output:
Root cause in two sentences, the minimal diff, the test results in a short list, and a final line marked "Not verified:" listing any gaps.

The model replied

**Outcome aimed for:** VAT is applied exactly once, so £50.00 with no discount totals £60.00. **Root cause:** `calculateTotal` adds VAT to the subtotal (`subtotal = subtotal + vat`) and then adds 20% again in the `return` statement, so VAT is charged twice. The discount is also subtracted from the VAT-inclusive figure, so the second VAT calculation runs on the discounted gross amount. **Diff** (based only on the snippet you pasted; I had no file path): ```diff function calculateTotal(items, discount) { let subtotal = items.reduce((sum, i) => sum + i.price, 0); - let vat = subtotal * 0.2; - subtotal = subtotal + vat; if (discount) { subtotal = subtotal - discount.amount; } return subtotal + subtotal * 0.2; } ``` **Test to add** (Jest-style, adjust to your runner): ```js test("charges VAT once, with and without a discount", () => { const items = [{ price: 50 }]; expect(calculateTotal(items, null)).toBeCloseTo(60); // old code: 72 expect(calculateTotal(items, { amount: 5 })).toBeCloseTo(54); // old code: 66 }); ``` **Test results:** - Nothing was run. I had no file or shell access in this session, so I couldn't locate the real file, run the suite, or confirm the test fails before the fix and passes after. - By hand, the old code gives £72.00 for £50 with no discount, and £66.00 with a £5 discount. The fixed code gives £60.00 and £54.00. **Discrepancies to check:** - The pasted code double-charges VAT for every order, not only those with a discount code. It also gives £72, not the £70 in the report. The deployed code or the report may differ from the snippet, so check whether last Tuesday's release changed something else, such as a separate "VAT line" added elsewhere in the checkout. - I assumed the discount comes off the net (pre-VAT) price. If discounts should be VAT-inclusive and applied after VAT, the formula would be `subtotal * 1.2 - discount.amount`. That is a pricing decision for you. Not verified: that the fix and test run in the real repo, that the snippet matches what's deployed, whether the discount should apply before or after VAT, and whether another code path adds a separate VAT line.

Run on Claude Sonnet 5.5, 12 Nov 2026. Automatic check: 2 out of 5.

Mentioned for

Claude

Where it came from

Found on Web, shared by Rizki Murtadha (Promptessor): Claude Fable 5.2 Prompting Guide: Tips & Examples.

This is our own version of the idea, written and tested by us. The original may differ.

More coding prompts

Coding Worked in our test
Generate Strict JSON Spec From Description

You get a clean, machine-readable JSON object that matches your rules on the first try. It works because the model reads the rules first, then checks its own answer against each one before replying.

Found on GitHub, shared by DominikScholz
Coding Partly worked
Match Ownership Wording to Change Size

You get a tightly scoped code change, plus a separate list of things the AI spotted but left alone. It works because you state how far the AI may go, so a sense of "ownership" does not trigger unrequested refactoring.

Found on Web, shared by explainx.ai
Coding Worked in our test
Turn Vague Bug Reports Into Concrete Objectives

You get a bug fix broken into a reproduction, a minimal change and a regression test, each checked against clear objectives. Concrete objectives stop the model drifting into large rewrites or guessing at what "fixed" means.

Found on Web, shared by David Ch (@chhddavid)