Community post
Debugging With AI: Reproduce the Bug Before Requesting a Fix
By Liam · Published · 2 min read
Editorial standards and correctionsLearn a safer debugging prompt: provide expected and actual behavior, isolate the smallest reproduction, and verify the proposed fix.
If I ask “fix this bug” without a reproduction, the model may change code that was not broken. First I make the failure observable.
After reproducing the bug, Use AI to Draft Tests, Then Challenge the Tests shows how to draft tests that would fail on the broken implementation.
Build the bug packet
For a small scoring error, I collect four items:
Expected: a 50-second finish gives 0 bonus points.
Actual: the UI shows -5 points.
Reproduction: enter
50 in the supplied test page and click Calculate.
Relevant code: the score function and the display line, not the whole project.
Now my prompt can ask for diagnosis:
From the supplied code and reproduction, identify the expression that permits a negative score. Propose the smallest fix. Add a test for 0, 50, and 80 seconds. State what you cannot verify from this snippet.
I run the reproduction before and after the change. If the negative score persists, the diagnosis was incomplete.Separate diagnosis from implementation
Sometimes I ask for likely causes first, but I do not accept a cause without evidence. The model should point to the code path or suggest a test that distinguishes causes. “It is probably a race condition” is not useful if no timing evidence exists.
Protect the surrounding behavior
A fix that passes the failing case may break the normal case. Keep a tiny regression set: one failing input, one typical input, and one boundary input. Ask the model to change only the relevant code slice and explain why it should leave other behavior unchanged.
Try it: Before prompting for a fix, write expected/actual/reproduction/relevant code. If you cannot reproduce the bug, ask AI to help design a reproduction step—not to rewrite the feature.
Keep learning: Use AI to Draft Tests, Then Challenge the Tests, A Better Code Review Prompt Uses a Diff and a Risk Checklist, and A Tiny Evaluation Set for Your Favorite Coding Prompt.
About the author
Liam
Coder and gamer. I test prompts, share what works, and show how to improve AI results for code and creative projects.
View Liam's public profileComments (0)
Loading comments…
Keep exploring
Related from Prompt Engineering Lab
Use AI to Draft Tests, Then Challenge the Tests
Prompt AI for boundary and invalid-input tests, then check whether the tests would catch a real defect.
Privacy Checks Before You Paste Anything Into AI
Remove credentials, private identifiers, and unnecessary personal data before using AI tools; preserve the task without exposing the source.
How to Prompt Across Models Without Pretending They Work the Same
Keep the task and success criteria stable while checking each AI provider’s current model-specific guidance.