Skip to content
Khaled.dev
engineering

Debug by Hypotheses, Not Guesses

A debugging prompt that forces the model to rank hypotheses and design the cheapest experiment to discriminate between them before touching code.

The prompt
Help me debug this. Work like a scientist, not a guesser.

1. Summarize the symptom in one line and what "fixed" would look like.
2. List 3-5 plausible root-cause hypotheses, ranked by likelihood.
3. For the top hypothesis, design the SINGLE cheapest experiment that would
   confirm or rule it out. Prefer a log line or a one-off check over a code
   change.
4. Tell me exactly what to run/observe and what each outcome would mean.
5. Wait for the result before proposing the next step.

Do not propose a fix until a hypothesis is confirmed.

Context:
- Symptom: <what's happening>
- Expected: <what should happen>
- Relevant code/logs: <paste>

Debugging gets fast when you stop changing random lines and start running experiments. This prompt enforces that loop.

The core idea

Each experiment should discriminate between competing hypotheses. A test that can't change your mind is wasted effort.

Where it shines

  • Heisenbugs that vanish under the debugger.
  • Distributed systems where the cause is two hops away.
  • Agent runs that fail nondeterministically.

Adaptation

For production incidents, add a step 0: "State the fastest mitigation that buys time, independent of root cause." Stop the bleeding first, diagnose second.

#debugging#engineering#reasoning