Debug an error and find the root cause
Reproduces, isolates, and fixes a bug — with a test to prevent it coming back.
The prompt
Role: Act as a senior engineer methodically debugging a reported defect.
Context: Bug report (symptom, when it started, frequency): [BUG_REPORT]. Environment and version: [ENV_VERSION]. Relevant code paths, logs, stack traces, recent changes: [EVIDENCE]. What has been tried: [TRIED]. Constraints on the fix (compatibility, risk window): [CONSTRAINTS].
Goal: Get from symptom to a confirmed root cause and the smallest safe fix, with a test that would have caught it.
Task: Produce: (1) a hypothesis list ranked by likelihood, each with how to confirm or eliminate it from the evidence; (2) a reliable reproduction (steps or a failing test); (3) the root cause with the specific evidence that proves it (not just a plausible story); (4) the minimal fix and why it is minimal, plus any follow-up cleanup noted separately; (5) a regression test that fails before and passes after.
Constraints: Do not propose a fix before the root cause is evidenced. Prefer the smallest change that addresses the cause over a broad refactor. State clearly if the evidence provided is insufficient to confirm the cause and what to collect next.
Examples: Hypothesis row: 'H2: timezone handling in [function]. Confirm by: reproduce with a UTC-negative offset input; check [log field]. Eliminate if: the failure also occurs at UTC.'
Format: Sections: Hypotheses & how to test | Reproduction | Root cause + evidence | Minimal fix (+ deferred cleanup) | Regression test. Code in fenced blocks.
Verification: Explicitly separate what the evidence proves from what is inference; if the cause is not actually confirmable from the given evidence, say so and stop short of a fix.
Validation: Pressure-test the fix: does it address the cause rather than the symptom, and could it break an existing caller? Name the caller most at risk.
Highlighted [brackets] are blanks to replace with your own details.
Fill in the blanks and use this promptMore Software Development prompts
What to fill in
- BUG_REPORT
- ENV_VERSION
- EVIDENCE
- TRIED
- CONSTRAINTS
- function
- log field
How this prompt is built
This prompt follows the RCTFVV structure (Role, Context, Task, Format, Verification, Validation). RCTFVV extends RCTF with two checking steps. Verification asks the model to review its own draft against your requirements; Validation asks it to flag assumptions and gaps you should confirm.
Related prompts
- Implement a feature from a spec, with testsPlans and writes production-quality code for a feature, including tests and edge cases.
- Set up CI/CD and infrastructure as codeCI/CD pipelines and IaC templates with environments, checks, and rollback.
- Explain what a piece of code doesPlain-language walkthrough of unfamiliar code: purpose, flow, key parts, and gotchas.
- Write documentation, a README, or API docsGenerates clear technical documentation from your code or notes.