# Debug an error and find the root cause

Reproduces, isolates, and fixes a bug — with a test to prevent it coming back.

- Topic: Software Development
- Framework: RCTFVV
- Level: Advanced
- Tags: Coding, Code, Fill-in Template
- Source: https://www.thinkwithprompt.com/prompts/debug-an-error-and-find-the-root-cause

## Prompt

```text
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.
```

## What to fill in

- BUG_REPORT
- ENV_VERSION
- EVIDENCE
- TRIED
- CONSTRAINTS
- function
- log field

Free to copy and use. From ThinkWithPrompt (https://www.thinkwithprompt.com/), a library of 2,663 curated AI prompts.
