Test-First Bug Fix Prompt
Guide a coding assistant from a concrete failure to a minimal fix and a meaningful regression check.
What this prompt does
Reproducing failure
Anchor the test to the reported behavior.
Minimal correction
Keep code changes tied to the demonstrated root cause.
Honest verification
Report only the checks actually run and their scope.
What to provide & what you get
- Input
- The bug’s actual/expected behavior, reproduction steps and relevant project files.
- Expected output
- A reproducing test, a minimal fix and a report of the test results actually observed.
How to use
- Provide actual/expected behavior and a reliable reproduction.
- Check that the new test fails for the intended reason.
- Review the minimal fix and the observed regression results.
Check the result: The reproducing test should fail before the fix and pass after it in the actual environment.
Copy. Paste. Run.
v1.0.0-gas1Edit the inputs below, then copy into your AI tool with the requested source material.
Before you start
- The bug’s actual/expected behavior, reproduction steps and relevant project files.
Worked example · Editorial fixture
Observe an empty-input failure before applying a one-line repair
Original fictional inputs and a prepared editorial answer. This reusable prompt was not run against the fixture. Use the files and case-specific checks to review your own result.
Example input
Python 3.13.2. Contract: average([]) returns None because no observation exists; [0] returns numeric zero. Existing implementation returns zero for empty input. Scope: numeric lists only; change only the empty-input branch.
Prepared output
BEFORE: average([]) → 0, contrary to the supplied contract. TEST FIRST: run python3 check.py before. Observed: four tests ran; empty-input check failed; exit code 1. MINIMAL PATCH: return None instead of 0 in the empty branch; sum and division are unchanged. AFTER: run python3 check.py after. Observed: all four tests passed; exit code 0. REGRESSIONS: [0] → 0, [1,2] → 1.5, [-2,0] → -1. SCOPE: these results concern the supplied small fixture, not all tests in a user’s repository. No commit, push or deployment was performed.
What to check in this case
- The same four tests were executed against both files. The failure was observed before the repair result was accepted.
- The test protects numeric zero as valid data and covers empty input, fractions and a negative value.
References: Python: unittest
Keep in mind
- A proposed test is not evidence of execution.
- A narrow regression run does not establish project-wide correctness.



