Most People One-Shot AI Bug Fixes. This 2-Step Prompt Split Works Better

Most people paste a bug into an AI and say “fix it.” One redditor, u/FLAWEDGHOST on r/PromptEngineering, does it differently, and the results are more reliable.

The Key Idea

Split the job into two turns. In the first turn, the AI only diagnoses. In the second, it only fixes. No code gets written until you’ve checked that the AI understands what’s going on. Think of it as a checkpoint between “here’s the problem” and “here’s the change.” That checkpoint is where most of the value lives, because it’s the only moment when a wrong idea is still cheap to fix.

The Old Way vs. The New Way

The old way: You paste the code and the error, then ask for a fix. The AI picks the first explanation that sounds plausible and starts writing. If that guess is wrong, everything built on it is wrong too. You get broken unrelated state, helper functions that don’t exist, and rewritten files you never asked it to touch. Then you spend more time untangling its changes than you would have spent debugging by hand. A classic example: a form that submits twice. The AI blames the button handler, adds a debounce, and rewrites the component. The real cause was a duplicate event listener attached in a useEffect. Now you have a debounce you didn’t need and the original bug is still there.

The new way: You make the AI show its reasoning first. Wrong assumptions get caught while they’re still just words on a screen, before they turn into a diff. Their claim is that this catches most bad edits before they happen. It also saves tokens, because you stop regenerating whole components over and over. Reading a short trace takes a minute. Reviewing a 200-line rewrite you didn’t ask for takes much longer, and it’s easy to miss what changed.

How To Do It

Step 1: The diagnosis prompt

Paste the relevant file and the error behavior, then send something like this:

“Here is the relevant file and the error behavior: [paste code/error]. Do not write any code yet. Trace the data flow step by step, list the top 3 likely root causes ranked by probability, and tell me which exact lines are responsible. If you need to see another file or schema to be sure, ask before guessing.”

Three parts of that prompt matter:

  • 🔍 “Do not write any code yet” keeps the AI in read-only mode.
  • 📊 Ranked root causes force it to commit to a theory and show its confidence.
  • 🙋 “Ask before guessing” gives it permission to say what it’s missing instead of making things up.

A practical tip: include the exact error message and what you expected to happen, not just what went wrong. “The total shows 0 after adding an item, expected 25” gives the AI far more to trace than “the cart is broken.” If the bug only happens in certain conditions, say so, like “only after refreshing” or “only for logged-in users.”

Step 2: Check the trace yourself

Don’t skip this. Read the data flow it described. Does it match how your code really works? If the AI misunderstood the state flow, correct it now, while it costs you one message. Pay special attention to any place where it says “probably” or “assuming.” Those words mark the spots where it’s guessing. If the top-ranked cause doesn’t fit what you’ve seen, try asking about cause #2 or push back with what you know, such as “that function only runs on mount, so it can’t be that.”

Step 3: The scoped fix prompt

Once the trace looks right, send this:

“Confirming root cause #1. Propose the smallest possible diff to fix this without changing existing function signatures, UI layout, or external dependencies. Show only the modified block and explain any edge cases this might affect.”

This boxes the AI in. It can’t redesign your app, it can’t swap your dependencies, and it only shows the changed block, so you can review it quickly. If the fix looks bigger than the bug, that’s a signal to go back to the trace and see what the AI got wrong.

A Useful Add-On From the Comments

One commenter, u/Spare_Interview5263, runs a three-step version: analyze, confirm, fix. Their “confirm” step asks the AI to list what it’s assuming about the code’s structure before it suggests any change. That’s a smart extra check. Hidden assumptions cause a lot of bad edits, and this makes them visible. For example, the AI might assume a function returns an array when it can also return null, or that a config value is always set. You can spot those in seconds, and a single correction can change the whole diagnosis.

Why It Works

AI models are eager to help. Ask for a fix and you get a fix, even if the model doesn’t fully understand the problem yet. Separating diagnosis from execution takes away that rush. It’s the same reason a good mechanic tells you what’s wrong before starting to swap parts. You wouldn’t want a new alternator installed because the car “sounded off.” You’d want to hear the reasoning first, and the same standard applies here.

Try It On Your Next Bug

Next time something breaks, don’t ask for the fix. Send the diagnosis prompt first and read the trace. Save both prompts somewhere handy, like a notes file or a text snippet, so you can paste them in seconds. If you’ve been splitting your prompts into separate turns like this, or you still get good results from single-shot prompts, I’d like to hear which one works for you!

Frequently Asked Questions

Q: Why split diagnosis and fixing into two turns instead of using one prompt?

One-shot requests often push the model to guess at state it has not seen, and that’s how you end up with unrelated breakage, invented helpers, and rewritten files. A read-only diagnosis step makes it trace the data flow and name exact lines first, so you can catch a bad assumption before any code exists. Once the trace checks out, the scoped fix is usually a much smaller diff that’s easier to review.

Q: What should I do if the model’s trace looks wrong or it asks for more files?

Give it the files or schema it asks for instead of letting it guess. If the trace is off, correct the wrong assumption in your next message and ask for the trace again before requesting a fix. Hold off on the diff until you actually agree with the root cause.

Q: Is an extra confirmation step worth it before the fix?

One commenter runs a three-step version: analyze, confirm, then fix. In the confirm step, they ask the model to list what it’s assuming about the code’s structure before it suggests any changes. That makes hidden assumptions visible, so you can correct them before they turn into a bad diff. For a quick one-line bug, the two-step flow from the post is likely plenty.

a simple 2-step prompt workflow i use before letting an llm touch existing code
by u/FLAWEDGHOST in PromptEngineering

Scroll to Top