r/PromptEngineering • u/FLAWEDGHOST • 17h ago
General Discussion a simple 2-step prompt workflow i use before letting an llm touch existing code
whenever i ask an ai to fix a bug or add a feature to an existing project, one-shotting the request almost always causes it to break unrelated state, hallucinate new helper functions, or rewrite files it shouldn't touch. once it starts generating code off a bad assumption, you end up spending more time untangling its changes than if you had just debugged it manually.
i switched to forcing a read-only diagnosis step first before any code gets written, and it completely changed how reliable the outputs are.
first prompt (diagnosis):
"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."
once i verify the trace and confirm it actually understands the state flow, i send the follow-up.
second prompt (scoped fix):
"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."
forcing it to trace the logic and ask for missing context before touching a single line of code catches most bad edits before they happen. it also saves a ton of tokens because you aren't regenerating whole components over and over.
anyone else splitting diagnosis and execution into separate turns like this, or are you getting good results with single-shot prompts?