Skip to content

Debug Code

Debug and Fix a Failing Piece of Code

AI Tool: ChatGPTCategory: Coding

Get a systematic diagnosis of a bug: likely cause, minimal fix, and the test that proves it.

The Prompt

Act as a senior engineer doing a focused debugging session. Do not rewrite the whole file.

Language / framework: {{language}}
What the code should do: {{expected_behaviour}}
What actually happens: {{actual_behaviour}}
Error message or stack trace:
{{error}}
Relevant code:
```
{{code}}
```
What I already tried: {{attempts}}

Respond in this order:
1. Diagnosis: the most likely root cause, and why the symptom matches it
2. Two alternative causes I should rule out, with a one-line check for each
3. Minimal fix as a diff-style snippet, changing as few lines as possible
4. Why the fix works
5. A test that fails before the fix and passes after
6. Any other place in the shown code with the same class of bug

If the code provided is insufficient, say exactly what you need before guessing.

Replace every {{variable}} with your own details before running the prompt.

Variables to fill in

6 variables

{{language}}required
Language and framework.
{{expected_behaviour}}required
What should happen.
{{actual_behaviour}}required
What happens instead.
{{error}}
Error output or stack trace.
{{code}}required
The relevant code.
{{attempts}}
Fixes you already tried.

Scroll to see every variable.

Best for

  • Developers
  • Students
  • Technical founders