20 tested prompts across 4 stages. Works with ChatGPT, Claude, and Gemini.

Most people try to use AI for ChatGPT for Debugging with a single vague prompt and get generic results. This guide takes a different approach: 4 targeted stages, from Describe the bug through Prevent future bugs, each with a prompt that gives the AI exactly the context it needs. Diagnose and fix bugs faster by using ChatGPT as a debugging partner across any programming language. Works with ChatGPT, Claude, and Gemini.
Stage 1
Start here to articulate the problem precisely so you can diagnose it effectively.
Report the bug clearly
I have a bug in my [LANGUAGE] code. What is happening: [ACTUAL BEHAVIOR]. What should happen: [EXPECTED BEHAVIOR]. Here is the relevant code: [PASTE CODE]. Help me find the root cause.
Explain an error message
Explain this error in plain language: [PASTE ERROR MESSAGE AND STACK TRACE]. What caused it, where did it originate in the code, and what does it mean?
Debug wrong output
My function returns [WRONG OUTPUT] when it should return [CORRECT OUTPUT] for input [INPUT]. Here is the code: [PASTE CODE]. Walk me through the logic to find where it goes wrong.
Debug intermittent failure
I have a bug that only appears sometimes. Here is what I know: [DESCRIBE CONDITIONS WHEN IT APPEARS]. Here is the code: [PASTE CODE]. What are the most likely causes of intermittent failures?
Debug after a change
Something broke after I made this change: [DESCRIBE WHAT YOU CHANGED]. The error is: [DESCRIBE ERROR]. Here is the relevant code before and after: [PASTE BOTH]. What did I break?
Stage 2
These prompts help you implement the right fix and verify it solves the root cause.
Get a fix
Here is the buggy code: [PASTE CODE]. The bug is: [DESCRIBE BUG]. Write the fix, explain why it works, and tell me what edge cases to watch out for.
Fix a null/undefined error
I'm getting a null or undefined error on this line: [PASTE CODE AND LINE]. What is null/undefined here, why, and how do I fix it safely?
Fix an async bug
I have an async timing problem or race condition: [PASTE CODE]. Explain what is happening and fix it using proper async patterns.
Fix a logic error
The logic in this function is wrong: [PASTE CODE]. Expected behavior: [DESCRIBE]. Walk through the logic step by step and identify exactly where it diverges from what I intended.
Fix without side effects
I need to fix [DESCRIBE BUG] in this code: [PASTE CODE]. What other parts of the codebase might be affected? Help me fix it without introducing new bugs elsewhere.
Stage 3
Use these prompts to add observability and tooling that makes future bugs easier to catch.
Add logging
Add logging to help diagnose [DESCRIBE ISSUE] in this code: [PASTE CODE]. Log the values that matter most and label each log statement clearly.
Write a reproducing test
Write a minimal test case that reproduces this bug: [DESCRIBE BUG, PASTE CODE]. The test should fail now and pass after I apply the fix.
Debug API calls
My API call is failing: [PASTE CODE WITH THE API CALL]. How do I debug this? What should I log and what are common causes of this type of failure?
Debug a performance issue
This code is running slower than expected: [PASTE CODE]. How do I measure exactly where the time is going and identify the bottleneck?
Explain the call stack
Help me read this call stack to understand what happened before the error: [PASTE CALL STACK]. What was the execution flow and where did it go wrong?
Stage 4
Use these prompts to identify patterns and add safeguards that prevent the same issue recurring.
Add regression tests
Write regression tests for this bug so it can never come back: [DESCRIBE BUG, PASTE FIXED CODE]. Cover the exact scenario and adjacent edge cases.
Improve error handling
Improve the error handling in this code to make future bugs easier to diagnose: [PASTE CODE]. Add meaningful error messages and proper context.
Add input validation
Add input validation to prevent this class of bug in the future: [DESCRIBE BUG, PASTE CODE]. What inputs should I validate and how?
Code review for bugs
Review this code for potential bugs before I ship it: [PASTE CODE]. Look for: null access, off-by-one errors, async issues, and unhandled edge cases.
Document the fix
Write a brief comment explaining why this fix was needed: [PASTE FIXED CODE]. The comment should explain the bug that existed, not just what the code does now.
Share the actual error message and stack trace, the relevant code, what you expected to happen, and what actually happened. The more specific you are, the more accurate the diagnosis. Vague bug descriptions produce vague answers.
Yes. ChatGPT understands code logic regardless of whether it has seen your specific codebase. Paste the relevant code and describe the bug, and it will reason through what is happening.
Logic errors, async timing bugs, null/undefined access, incorrect API usage, type mismatches, and common algorithmic mistakes. It is less reliable for bugs caused by environment-specific issues, race conditions in distributed systems, or hardware-level problems.
No. Always review AI-suggested fixes before applying them. ChatGPT can misunderstand context or suggest a fix that addresses the symptom rather than the root cause. Understand the fix before you ship it.
Yes, across mainstream languages: JavaScript, TypeScript, Python, Java, C#, Go, Rust, Ruby, PHP, and more. It also handles SQL, shell scripts, and configuration files.
AI Prompts for Cursor for Debugging
Debugging code can be time-consuming and frustrating for developers.
See promptsAI Prompts for ChatGPT for Code Review
Use ChatGPT to catch bugs, improve code quality, and prepare better code before human reviewers see it..
See promptsAI Prompts for ChatGPT for Unit Tests
Write comprehensive unit tests faster using ChatGPT to improve coverage and catch bugs before they reach production..
See prompts