Sub topic 6
Check the diagnosis against the evidence
This chapter assumes you can read a Python traceback, run a script from a terminal, and write a prompt that includes the code and the full error. Once the assistant answers, you still have to decide whether the answer is right before you change anything.
Why a diagnosis needs checking
An assistant produces a plausible explanation quickly, and a plausible explanation is not always a correct one. It may not have seen your real environment, your full code, or the exact input that failed. Your job is to compare its claims with the evidence you already have: the traceback, the failing line, and the reproduction.
Take the example from earlier chapters.
def average(values):
return sum(values) / len(values)
print(average([]))Traceback (most recent call last):
File "stats.py", line 5, in <module>
print(average([]))
File "stats.py", line 2, in average
return sum(values) / len(values)
ZeroDivisionError: division by zeroSuppose the assistant replies: "The sum of an empty list is undefined, so sum(values) fails. Wrap it in a try block." Compare that with the evidence. The traceback points at the division, not at sum. In Python, sum([]) returns 0. The claim contradicts the error, so you reject it.
A checklist for any diagnosis
Run each answer through these questions:
- Does it name the line and error type from the traceback? A diagnosis that ignores the last line of the traceback is guessing.
- Does it explain the mechanism? "Division by zero happens because
len(values)is 0 when the list is empty" is a mechanism. "Something is wrong with the input" is not. - Does it match your reproduction? The cause it names must be true for the input that fails and false for the input that works. Here,
average([2, 4, 6])works because the length is 3. - Can you confirm it cheaply? Print a value, run one line in a REPL, or read the documentation.
- Does it explain all the symptoms? If two errors appear and the diagnosis covers one, it is incomplete.
Confirm before you fix
Test the claim directly. Do not take the assistant's word for it.
values = []
print(sum(values))
print(len(values))This prints 0 twice. That confirms len(values) is the zero in the denominator and that sum is not the problem. The check took ten seconds. Applying the wrong fix and debugging the result would take much longer.
Ask for evidence, not confidence
If a diagnosis is vague, ask the assistant to show its work. These prompts help:
- "Which line of the traceback supports this?"
- "What would I see if your explanation were wrong?"
- "Give me one command or print statement that confirms this cause."
A good answer points to something you can observe. A weak answer repeats the claim more firmly. Confident wording is not evidence.
Common errors when evaluating
- Accepting the first answer because it sounds fluent. Fluency says nothing about accuracy.
- Checking only that the explanation sounds reasonable. Check it against your actual output.
- Skipping the reproduction. Without a reproduction you cannot tell whether a diagnosis explains your failure or a different one.
- Ignoring missing context. If the assistant never saw the calling code, its claim about the caller is a guess. Supply the code and ask again.
Exercise
An assistant says average([]) fails with ZeroDivisionError because "the list is None". The traceback shows average([]). Name one fact from the evidence that contradicts this and one quick check that settles it.
Show answer
The call passes [], an empty list, not None. Passing None would raise a TypeError from sum(None), not a ZeroDivisionError. A quick check is print(len([])), which prints 0, the divisor in the failing line.