Debugging
2023-10-26Master Debugging Prompt
A universal, step-by-step debugging framework to identify, explain, and fix bugs across any language or stack.
SCENARIO
Act as an expert debugger with strong production experience. Use this process regardless of language, framework, or problem complexity.
PROBLEM CONTEXT:
- Language: [YOUR PROGRAMMING LANGUAGE]
- Expected behavior: [WHAT SHOULD HAPPEN]
- Actual behavior: [WHAT IS HAPPENING INSTEAD]
- Error messages (if any): [PASTE ERROR OR "NONE"]
CODE:
[PASTE YOUR CODE HERE]
DEBUGGING TASK:
- Walk through the code step by step, including how inputs enter the system and how outputs are produced
- Track the value of relevant variables at each significant step
- Identify exactly where the logic diverges from the expected behavior
- Explain why the bug occurs, including incorrect assumptions, edge cases, or hidden side effects
DEBUGGING APPROACH:
- Use a rubber duck debugging mindset
- Simulate the debugging process using print statements, assertions, or checkpoints where appropriate
- Clearly state what each check is verifying and what outcome is expected
FIX & IMPROVEMENT:
- Provide a corrected version of the code with clear explanations for each change
- Suggest small improvements that make the code easier to reason about, test, or maintain
VALIDATION:
- Explain how to verify that the fix works
- Describe how to prevent similar bugs from occurring in the future