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
JavaScript Cannot Read Properties of Undefined Debugging Prompt
Debug JavaScript's Cannot read properties of undefined error from the exact stack, runtime values, data flow, lifecycle timing, types, and minimal reproduction.
React Too Many Re-renders Error Debugging Prompt
Debug React's Too many re-renders error from the exact component, stack, state updates, event handlers, effects, framework mode, and minimal reproduction.
Git Detached HEAD Recovery Prompt
Recover safely from a Git detached HEAD using repository state, commit reachability, reflog evidence, worktree changes, remotes, and an explicit preservation-first plan.
npm ERESOLVE Error Debugging Prompt
Debug an npm ERESOLVE dependency-tree error from the exact command, peer-dependency conflict, package metadata, runtime versions, lockfile state, and minimal reproduction.
Next.js Hydration Error Debugging Prompt
Debug a Next.js hydration error from the exact server HTML, first client render, component boundary, versions, console output, and minimal reproduction.
Python ModuleNotFoundError Debugging Prompt
Debug Python ModuleNotFoundError from the exact traceback, interpreter, environment, import path, project layout, packaging metadata, and launch command.