Debugging Detective
Systematically debug errors and unexpected behavior with root cause analysis and fix suggestions.
Prompt Template
You are a senior debugging specialist. Help me find and fix this bug systematically. **What should happen:** [expected behavior] **What actually happens:** [actual behavior] **Error message (if any):** ``` [paste error/stack trace] ``` **Environment:** [OS, language version, framework version, relevant packages] **When it started:** [always / after a specific change / intermittent] **What I've already tried:** [list attempts] **Relevant code:** ``` [paste code] ``` **Relevant config/dependencies:** ``` [paste if relevant] ``` Please: 1. **Parse the error** — explain what the error message actually means in plain English 2. **Identify likely root causes** — rank from most to least probable 3. **Diagnostic steps** — what I should check/log to confirm the root cause 4. **Fix** — provide the specific code change for the most likely cause 5. **Prevention** — how to prevent this class of bug in the future (linting rules, types, tests) 6. **If my code isn't the issue** — check for known framework bugs, dependency conflicts, or environment issues
Example Output
Error Analysis
What the error means:
`TypeError: Cannot read properties of undefined (reading 'map')` on line 42 means `data.items` is `undefined` when your component tries to render. The API response doesn't have the shape your code expects.
Most Likely Causes (ranked)
1. **Race condition** (90% likely) — Component renders before the API call completes. `data` is `undefined` during the initial render.
2. **API response shape changed** (5%) — The API might return `{results: [...]}` instead of `{items: [...]}`
3. **Error response not handled** (5%) — API returns an error object that doesn't have `.items`
Fix
// Add optional chaining and a loading state
const items = data?.items ?? [];
if (isLoading) return <Skeleton />;
return items.map(item => <Card key={item.id} {...item} />);
Prevention
- Add TypeScript types for your API responses
- Use Zod to validate API responses at runtime
- Add a `<Suspense>` boundary or loading state for async data
Tips for Best Results
- 💡Include the FULL stack trace — the root cause is often several frames deep
- 💡Mention what changed recently — new packages, version upgrades, config changes
- 💡For intermittent bugs, describe the frequency and any patterns you've noticed
- 💡Include browser console output for frontend bugs
Frequently Asked Questions
What is the Debugging Detective prompt?
Systematically debug errors and unexpected behavior with root cause analysis and fix suggestions. It's a free ChatGPT prompt template from our Coding collection — copy it, fill in the bracketed variables, and paste it into your AI tool.
Which AI tools work with this prompt?
It's written and tested for ChatGPT, Claude and Gemini. Any AI assistant that accepts free-form text prompts will handle it well.
How do I customize this ChatGPT prompt?
Replace the bracketed variables — such as [expected behavior], [actual behavior], [paste error/stack trace] — with your own details before running it. Include the FULL stack trace — the root cause is often several frames deep
Is this prompt free to use?
Yes. Every prompt on PromptAtlas is free to copy, customize, and use — no signup required.
Related Prompts
Python FileNotFoundError Debugging Prompt
Debug Python FileNotFoundError from the exact traceback, resolved path, working directory, filesystem context, deployment environment, and failing operation.
Python ZeroDivisionError Debugging Prompt
Debug Python ZeroDivisionError from the exact traceback, operand values and types, data path, numeric semantics, runtime context, and failing input.
Python IndentationError Debugging Prompt
Debug Python IndentationError from the exact parser message, whitespace, block structure, source bytes, formatter settings, and runtime version.
Python SyntaxError: Invalid Syntax Debugging Prompt
Debug Python SyntaxError invalid syntax from the exact parser location, surrounding tokens, Python version, generated code, execution context, and minimal reproduction.
Python AttributeError: Object Has No Attribute Debugging Prompt
Debug Python AttributeError from the exact traceback, runtime object type, attribute contract, construction path, version, imports, and minimal reproduction.
Python UnboundLocalError Debugging Prompt
Debug Python UnboundLocalError from the exact traceback, binding scope, assignments, branches, closures, imports, runtime path, and minimal reproduction.