Debug from an error and stack trace
Ranked hypotheses with a test for each, instead of one confident guess. Written for Claude, free to copy, with every placeholder explained below.
The prompt
<role>
You are debugging alongside me. You generate hypotheses; I run the tests.
</role>
<context>
Language and version: {{language}}
What I expected: {{expected}}
What actually happened: {{actual}}
Already ruled out: {{ruled_out}}
</context>
<error>
{{error_and_stack_trace}}
</error>
<code>
{{relevant_code}}
</code>
<task>
Give me the most likely causes, ranked.
</task>
<constraints>
- For each cause: what would confirm it, in one concrete step I can run.
- Rank by likelihood given the evidence, and say what makes each likely.
- Do not suggest a fix until a cause is confirmed.
- If the stack trace is insufficient to narrow it down, say what additional
output would help most.
- Do not repeat anything in "already ruled out".
</constraints>
Now give me the ranked causes.Open this in the prompt builder to adapt it, score it, and re-render it for a different model.
What to replace
| Placeholder | What to put there |
|---|---|
| {{language}} | Language, version and framework. |
| {{expected}} | What should have happened. |
| {{actual}} | What happened instead, precisely. |
| {{ruled_out}} | What you have already checked, and how. |
| {{error_and_stack_trace}} | The full trace, not a paraphrase. |
| {{relevant_code}} | The code path involved. |
Why this prompt works
- Hypotheses, not answers
- Debugging is a search. A model is good at generating candidate causes and bad at knowing which is true, so the prompt asks for what it is good at.
- A test per hypothesis
- Converts a list of guesses into a plan you can execute in order.
- No fix before confirmation
- Stops the model jumping to a plausible patch for a cause nobody verified — the main way debugging sessions go sideways.
- "Already ruled out" supplied
- Prevents the model re-suggesting what you have tested, which is what makes iterative debugging feel useless.
More prompts
- Code review for correctness only — Findings with a triggering input, ranked by severity — and permission to find nothing.
- Unit tests written from the spec — Tests derived from requirements rather than from the implementation, so they can fail.
- Explain unfamiliar code — A walkthrough pitched at your actual level, with the non-obvious decisions called out.
- SQL query from a plain-English question — A query with its assumptions stated, so you can check them before running it.
- Blog post from an outline — Turn a rough outline into a full draft that keeps your structure and does not pad.
- Rewrite for clarity without changing meaning — Tighten prose while keeping the author's voice and every factual claim intact.
Browse the full prompt library, all coding & development prompts, or read the guides.