Debugging with ChatGPT and Pair Programming
Debugging with ChatGPT and Pair Programming
ChatGPT shines in debugging when you treat it as a rubber duck that knows a lot of stack traces. The rule is to hand over reproducible facts, not vague symptoms: paste the code, the exact error, and the input that triggered it.
Feed the Model a Repro, Not a Story
Describe what you expected and what actually happened. Include the smallest failing input you can construct. The model reasons best about short, complete examples; a 500-line file produces vague guesses.
Debug the Error Message First
Paste the traceback and ask what each line means. Understanding the exception class and the line it points to usually reveals the bug before any code reading.
Traceback (most recent call last):
File "main.py", line 12, in <module>
result = divide(a, b)
File "main.py", line 5, in divide
return a / b
ZeroDivisionError: division by zeroPrompt: explain this traceback, then suggest three possible fixes ranked by safety.
Use the Model as a Second Set of Eyes
Ask for a code review in a fixed structure: bugs, style issues, performance wins, and security concerns, each with a severity. Then go through each item yourself. Reviews from a model are fast and broad, but they can be wrong, so never apply edits blindly.
A Pair Programming Loop
Work in small turns: describe the next step, get a skeleton, fill the details, run the tests, and feed failures back. This turn-based rhythm keeps you in control while ChatGPT handles typing, formatting, and boilerplate.
Key Points
- Give reproducible facts: code, error, and input.
- Understand the traceback before touching the code.
- Ask for structured reviews and verify each item.
- Keep a turn-based loop with the model as your partner.