Sub topic 12
Verifying Answers and Refining Context
This chapter assumes you have read the earlier chapters on sharing files, selections, and errors, and on writing a task statement. You should be comfortable running Python and reading a traceback.
An assistant's first answer is a proposal. It can look confident and still be wrong, because it works only from the context you sent. This chapter covers how to check an answer and how to improve your context when it misses.
Verify before you accept
Check every answer against something that can fail. Reading it and thinking "that looks right" is not a check.
Use these checks, roughly in order of cost:
- Read the diff. Confirm the assistant changed only what you asked it to change.
- Re-run the original failing command. The bug should be gone.
- Run the existing tests. Nothing that passed before should fail now.
- Test an edge case the assistant was not told about.
Here is the file used throughout this tutorial, with the fix requested in the earlier chapter applied:
def average(values):
if not values:
return None
return sum(values) / len(values)
print(average([]))
print(average([2, 4, 6]))Running it should print None and then 4.0. The original error is gone, and the normal case still works. If the assistant had changed the return type for non-empty lists, the second line would show it.
Recognize why an answer missed
When an answer is wrong or vague, the cause is usually one of a few context problems. Diagnose the cause before you re-ask.
| Symptom | Likely context problem | Fix |
|---|---|---|
| Answer is generic advice | Task or code was missing | Attach the file and state the task |
| Fix targets the wrong function | Selection was too broad or absent | Select the exact lines |
| Fix does not match the error | Error was paraphrased or truncated | Paste the full traceback |
| Answer ignores your style | Conventions were not supplied | Add standing instructions |
| Answer contradicts earlier work | Old context is still in the conversation | Start a fresh request |
Refine one thing at a time
Change one part of the context per attempt. If you add a file, trim a selection, and rewrite the task all at once, you cannot tell which change helped.
A useful follow-up names what was wrong and supplies what was missing:
Your change still raises an error. Here is the new output:
Traceback (most recent call last):
File "stats.py", line 6, in <module>
print(average(None))
TypeError: object of type 'NoneType' has no len()
Task: Make average return None for None as well as for an empty list. Keep the signature.This follow-up includes the new error verbatim, restates the task, and keeps the constraint. It does not say "that's wrong, try again", which gives the assistant nothing new to work from.
The refinement loop
Know when to restart
If two or three refinements have not helped, the conversation itself may be the problem. Earlier wrong answers stay in context and can pull later answers toward the same mistake. Start a new request with a clean summary: the file, the selection, the current error, and the task. Include what you already tried, in one line, so the assistant does not repeat it.
Common errors
- Accepting an answer because it is well explained. Explanation quality says nothing about correctness.
- Pasting only the last line of a new error. Include the full traceback again.
- Re-asking with the same context and hoping for a different result.
- Letting a long, tangled conversation continue when a fresh request would be cleaner.
Exercise
An assistant changes average so that average([]) returns None, but you run the file and average([2, 4, 6]) now prints None. Name the first check you should have done, and describe one change to the context you would make in your follow-up.
Show answer
Reading the diff, or running a normal-case input, would have caught the problem before acceptance. In the follow-up, include the actual output (None for [2, 4, 6]), restate the task with the constraint "non-empty lists must still return the mean", and attach the current version of the function so the assistant sees the code it produced.
Exercise
You have asked three times and the answers keep repeating the same wrong fix. What should you do next, and what should the new request contain?
Show answer
Start a fresh request instead of continuing the conversation. It should contain the file or selection, the full current error, a one-line note of what was already tried and failed, and a clear task statement with constraints.