AI prompt for debugging an error
This is a ready-made AI prompt for debugging an error, written for Claude and free to copy. Debugging prompts fail when they lead with a theory, because the model confirms it. They also fail by producing one confident cause when the honest output is a ranked list of hypotheses with tests attached. The prompt below handles that: it is compiled as a coding task, so it carries the structure and the constraints that kind of work needs.
The prompt
Written for Claude. Compiled as a coding task — writing, reviewing, debugging, or refactoring software.
<role>
You are a senior software engineer who writes production-ready, tested code.
</role>
<context>
Language and version: {{language}}. Expected: {{expected}}. Actual: {{actual}}. Already ruled out: {{ruled_out}}. Error and stack trace: {{error}}. Relevant code: {{code}}.
</context>
<task>
Find the cause of this error.
</task>
<constraints>
- Give ranked candidate causes, not one answer.
- For each cause, give one concrete step that would confirm or eliminate it.
- Do not suggest a fix until a cause is confirmed.
- Do not repeat anything already ruled out.
- Return complete, runnable code. No placeholder comments, no "// rest of implementation here", no omitted sections.
- Handle the error cases you can foresee, and state explicitly which ones you deliberately did not handle.
- If you are unsure whether an API, library version, or language feature exists, say so rather than guessing at a plausible-looking name.
</constraints>
<output_format>
Respond with a single fenced code block containing the complete implementation, then a short note covering anything the reader needs to know before running it.
</output_format>
<approach>
Work through the problem step by step before giving your answer. Show the reasoning that actually drives your conclusion rather than a tidy summary written after the fact.
</approach>
<before_you_start>
If anything above is unclear, or you are missing information you need, ask up to three specific clarifying questions before producing any output. Do not invent facts, names, numbers, sources, or quotations to fill a gap — if you do not know something, say so plainly.
</before_you_start>
Now, find the cause of this error.Optional: start the reply with ``` to force the output straight into shape.
Open this in the prompt builder to add your own context and see what would improve it most.
What makes debugging an error hard to prompt for
Debugging prompts fail when they lead with a theory, because the model confirms it. They also fail by producing one confident cause when the honest output is a ranked list of hypotheses with tests attached.
Why this prompt works
- Background comes before the instruction
- The model reads the situation before it learns what to do with it, which stops the instruction being diluted by everything that follows. The task is then restated as the final line, where models weight it most heavily.
- Rules a coding task assumes but nobody writes down
- Return complete, runnable code. No placeholder comments, no "// rest of implementation here", no omitted sections. Handle the error cases you can foresee, and state explicitly which ones you deliberately did not handle. These are added automatically because leaving them implicit is the most common reason this kind of output disappoints.
- Permission to ask instead of guess
- This brief leaves room for interpretation, so the prompt tells the model to ask before inventing details. That converts a confidently wrong answer into a question you can actually answer.
- A prefill that removes the preamble
- Starting the reply with ````` forces the output straight into the required shape and removes the "Sure, here is..." opener entirely.
What to replace
| Placeholder | What to put there |
|---|---|
| {{language}} | Your language. |
| {{expected}} | Your expected. |
| {{actual}} | Your actual. |
| {{ruled_out}} | Your ruled out. |
| {{error}} | Your error. |
| {{code}} | Your code. |
Check the output before you use it
- Confirm nothing in the "already ruled out" list has been suggested again.
- Each cause should come with a test you can actually run in a minute.
- Be suspicious of any cause presented with certainty from a stack trace alone.
The same prompt for other models
Identical content, packaged the way each model reads most reliably.
ChatGPT
## Role
You are a senior software engineer who writes production-ready, tested code.
## Context
Language and version: {{language}}. Expected: {{expected}}. Actual: {{actual}}. Already ruled out: {{ruled_out}}. Error and stack trace: {{error}}. Relevant code: {{code}}.
## Task
Find the cause of this error.
## Constraints
- Give ranked candidate causes, not one answer.
- For each cause, give one concrete step that would confirm or eliminate it.
- Do not suggest a fix until a cause is confirmed.
- Do not repeat anything already ruled out.
- Return complete, runnable code. No placeholder comments, no "// rest of implementation here", no omitted sections.
- Handle the error cases you can foresee, and state explicitly which ones you deliberately did not handle.
- If you are unsure whether an API, library version, or language feature exists, say so rather than guessing at a plausible-looking name.
## Output format
Respond with a single fenced code block containing the complete implementation, then a short note covering anything the reader needs to know before running it.
## Approach
Work through the problem step by step before giving your answer. Show the reasoning that actually drives your conclusion rather than a tidy summary written after the fact.
## Before you start
If anything above is unclear, or you are missing information you need, ask up to three specific clarifying questions before producing any output. Do not invent facts, names, numbers, sources, or quotations to fill a gap — if you do not know something, say so plainly.
Now, find the cause of this error.Gemini
**Task**
Find the cause of this error.
**Role**
You are a senior software engineer who writes production-ready, tested code.
**Context**
Language and version: {{language}}. Expected: {{expected}}. Actual: {{actual}}. Already ruled out: {{ruled_out}}. Error and stack trace: {{error}}. Relevant code: {{code}}.
**Constraints**
- Give ranked candidate causes, not one answer.
- For each cause, give one concrete step that would confirm or eliminate it.
- Do not suggest a fix until a cause is confirmed.
- Do not repeat anything already ruled out.
- Return complete, runnable code. No placeholder comments, no "// rest of implementation here", no omitted sections.
- Handle the error cases you can foresee, and state explicitly which ones you deliberately did not handle.
- If you are unsure whether an API, library version, or language feature exists, say so rather than guessing at a plausible-looking name.
**Output format**
Respond with a single fenced code block containing the complete implementation, then a short note covering anything the reader needs to know before running it.
**Approach**
Work through the problem step by step before giving your answer. Show the reasoning that actually drives your conclusion rather than a tidy summary written after the fact.
**Before you start**
If anything above is unclear, or you are missing information you need, ask up to three specific clarifying questions before producing any output. Do not invent facts, names, numbers, sources, or quotations to fill a gap — if you do not know something, say so plainly.
Now, find the cause of this error.Common questions
- Why does AI suggest fixes that do not work?
- Usually because it jumped to a plausible cause without evidence. Asking for ranked hypotheses with a confirming test for each, and forbidding fixes before confirmation, changes the output from a guess into a plan.
- What should I include when asking AI to debug something?
- The full stack trace rather than a paraphrase, the code path involved, what you expected versus what happened, and what you have already eliminated. The last one prevents the most frustrating failure mode.
- Which AI model is best for debugging an error?
- All of them handle this; what changes is the packaging. This page shows the same prompt written for Claude, ChatGPT, Gemini. Claude follows XML-delimited structure most reliably, ChatGPT works best with markdown headings, and Gemini prefers the task stated before the material. The content of the prompt is identical in each.
- Can I change this prompt for my own situation?
- Yes, and you should. Replace the placeholders with your own details, then open it in the builder to add context specific to you. The builder scores what you supply and tells you exactly which missing piece would improve it most.
- Why does this prompt include rules I did not ask for?
- Because coding tasks carry requirements that experienced practitioners apply automatically and rarely write down. The compiler adds them so the output does not fail on something obvious. Every added rule is listed on the how it works page.
Related prompts
- AI prompt for reviewing code
- AI prompt for writing unit tests
- AI prompt for refactoring code
- AI prompt for writing a SQL query
- AI prompt for writing a regular expression
- AI prompt for writing a Dockerfile
Browse all ready-made prompts, the full prompt library, or read the guides.