Describe the expected vs actual output and paste your code. Get a root cause analysis with a fix you can apply immediately.
By Arshad Hossain
How to Use
Copy the prompt, fill in what the code should do, what it actually does, and paste your code snippet.
The Prompt
I need help debugging this code. It is supposed to do [EXPECTED OUTPUT], but instead it produces [ACTUAL OUTPUT].
Please:
1. Identify the root cause of the bug
2. Explain step-by-step why the current code produces the wrong output
3. Provide the corrected code with comments explaining each change
4. List any other potential issues you notice
5. Suggest a test case that would have caught this bug
Here is the code:
[paste your code here]
Why "Bug Debugger" Works
"Bug Debugger" eliminates the most common reason AI output disappoints - vague instructions. This prompt uses reasoning elicitation and sequential task breakdown to define both what the output should include and how it should be structured. The end result is production-quality code that handles edge cases and follows your stack conventions, delivered on the first try rather than after multiple failed attempts.
Pro Tips for Using "Bug Debugger"
These coding tips will help you get stronger results when using "Bug Debugger" and similar prompts in this category.
Ask the AI to include error handling and edge cases in generated code. Production code needs to handle failures gracefully.
Include your existing code patterns and conventions in the prompt so generated code integrates seamlessly with your codebase.
Always specify the programming language, framework version, and runtime environment - "write a function" without context produces unusable code.
When to Use "Bug Debugger"
"Bug Debugger" is particularly useful in these situations. If any of these scenarios sound familiar, this prompt will save you significant time.
Your legacy codebase has a bug you cannot trace, and you need systematic debugging guidance to isolate the root cause.
Your pull request needs comprehensive unit tests and you want to generate test cases that cover edge conditions.
You want to optimize a slow database query and need to understand the execution plan and indexing strategy.
What You Will Get from "Bug Debugger"
When you use "Bug Debugger" with ChatGPT, Claude, or Gemini, here is what to expect in the AI output.
Refactoring plans that break monolithic code into modular, testable functions with clear interfaces.
API integration boilerplate with authentication, retry logic, rate limiting, and error response handling.
Unit test suites with coverage for happy paths, edge cases, boundary conditions, and failure modes.
How to Customize "Bug Debugger"
Adapt "Bug Debugger" to your specific situation by modifying these key areas. The more context you add, the better the results.
Add your existing code conventions (naming patterns, file structure, style guide) for consistent output.
Include your database type and ORM so generated data layer code integrates with your existing persistence layer.
Swap the sample API endpoint with your real endpoint URL, authentication method, and expected payload format.