Sub topic 12
Verifying Answers and Refining Context
This chapter assumes you have read the earlier chapters on files, selections, errors, and task statements. You should be comfortable writing a request that names a file, a selection, an error, and a task. Here the focus is what happens after the assistant replies: how to check the answer, and how to change your context when the answer misses.
Why an answer is a draft
An assistant produces text that fits the context it received. It does not run your code unless it has a tool that does, and it cannot see anything you left out. A reply can read well and still be wrong for your project. Treat every answer as a draft to check, not a result to accept.
Most wrong answers have one of three causes:
- The context was missing something the answer depended on.
- The context contained something misleading, such as an outdated file or an unrelated error.
- The task statement left room for a different reading than the one you meant.
Verification tells you whether the answer is wrong. Refinement fixes the cause. The two steps form a loop.
Verifying an answer
Check in order, from cheapest to most expensive.
Read it against your task
Before running anything, compare the answer to what you asked. Did it change only what you allowed? In the running example, the task was: change average so an empty list returns None, keep the signature, and leave other code alone. A good answer touches only the function body.
def average(values):
if not values:
return None
return sum(values) / len(values)
print(average([]))Check each constraint from your request:
- The signature
average(values)is unchanged. - The empty case returns
None. - The non-empty case behaves as before.
- Nothing else in the file was edited.
If the answer rewrote the print line, added a new import, or renamed the parameter, it ignored a constraint. That is a signal about your request, and it is covered below.
Run it
Reading catches scope problems. Running catches behavior problems. Run the file again:
python stats.pyFor the fixed version, the output is None. The original traceback should be gone. If a different error appears, you have new error context, and it is usually more useful than the first one.
Test the edges
A fix that handles the reported case can break a nearby one. Try inputs around the original failure:
def average(values):
if not values:
return None
return sum(values) / len(values)
assert average([]) is None
assert average([4]) == 4
assert average([1, 2, 3]) == 2
assert average([0, 0]) == 0
print("all checks passed")The last case matters. A careless fix such as if not sum(values): return None would pass the first three checks and fail on [0, 0], because the sum is zero even though the list is not empty. Checks like this one catch answers that look right.
If your project has tests, run them too. A passing suite is stronger evidence than a single manual run, but only for behavior the suite covers.
Check claims you cannot run
Some answers include facts instead of code: a function name from a library, a command flag, a version number. These can be invented. Confirm them against the official documentation or by running the command with --help. If the assistant says a method exists, check that your installed version has it.
Diagnosing a miss
When a check fails, resist the urge to repeat the request with more force. Instead, ask which kind of failure you have. The symptom usually points to the cause.
| Symptom | Likely cause | What to change |
|---|---|---|
| Answer refers to a function or file that does not exist | Missing context; the assistant guessed | Attach the file that defines it |
| Answer fixes a different problem than yours | Error context was incomplete or misleading | Share the full traceback, not one line |
| Answer is correct but changes too much | Task had no constraints | Add scope limits to the task |
| Answer is generic and does not use your code | No file or selection was given | Attach the file and select the relevant lines |
| Answer contradicts your style or tooling | Conventions were not stated | Add standing instructions |
| Answer was right earlier in the session but now drifts | Context has become cluttered or stale | Start fresh with a clean summary |
This table works as a checklist. Find the row that matches what you see before editing the request.
Refining the context
Change one thing at a time. If you add a file, rewrite the task, and trim the error all at once, you will not know which change helped.
Add what was missing
Suppose the assistant answered with a version of average that raises a custom exception, but your project returns None for missing data everywhere. The assistant could not know that. Add the evidence, not just a correction:
Context: stats.py (attached), selection: the average function (lines 1-2).
Your last answer raised ValueError. In this project, helpers return None for missing data (see median in stats_helpers.py, attached, lines 10-14).
Task: Redo the change so average([]) returns None, matching median's behavior. Keep the signature and do not change other code.This request does three things. It says what was wrong, it points to a concrete example in attached code, and it repeats the constraints. Pointing at an existing example works better than describing a style in words.
Remove what misled
Extra context can hurt. If you pasted a traceback from last week's bug along with today's, the assistant may try to fix both. Remove the old one. If an attached file is out of date, replace it with the current version. The chapter on keeping context uncluttered covers this in more detail. Here the point is that when an answer is confused, subtraction is often the right move.
Tighten the task
If the answer is plausible but not what you wanted, the task may be ambiguous. Compare these two:
Fix the empty list problem in average.Change average so an empty list returns None instead of raising. Keep the function signature and do not change other code.The first allows a return value of 0, a raised error with a better message, or a rewritten module. The second allows one outcome. State the desired result, then the limits.
Ask for the reasoning when the answer is surprising
If an answer takes an approach you did not expect, ask the assistant to explain which part of your context it relied on. This shows whether it used the file you attached or made an assumption. If it relied on something you did not provide, you now know what to add.
Which lines of stats.py did you base this on, and what did you assume that is not in the file?Treat the explanation as a lead to check, not as proof. Assistants can give a plausible account that does not match how the answer was produced. Still, a stated assumption is a useful thing to confirm or correct.
Knowing when to start over
Long sessions pick up leftovers: abandoned attempts, corrected misunderstandings, and stale file versions. After several rounds of refinement, the assistant may weigh early mistakes as heavily as later corrections.
Consider starting a new conversation when:
- You have corrected the same misunderstanding more than twice.
- The answers have started to repeat earlier rejected approaches.
- You have changed the files substantially since you attached them.
- The session is long enough that early details may be cut off by the context limit.
Carry over only what is still true. Write a short new request from the current state of the files, with the constraints you learned along the way. For instance, if you discovered that the project returns None for missing data, put that in the new request or in your standing instructions:
# Project conventions
- Language: Python 3
- Tests: pytest, files named test_*.py
- Keep functions small and add type hints to new code
- Helpers return None for missing data; do not raiseA lesson that appears in every request belongs in standing instructions. A lesson that applies to one task belongs in that task's request.
Common errors in the loop
- Accepting after reading only. The code looks right, so you skip running it. Run it at least once.
- Verifying only the reported case. The fix passes your example and breaks a neighbor. Test edges.
- Repeating the same request louder. The same context gives the same kind of answer. Change the context or the task.
- Changing everything at once. You cannot tell which edit helped.
- Blaming the assistant first. Check whether the file was current, the error complete, and the task unambiguous.
- Never stopping. If three rounds of refinement have not converged, the problem may be larger than one request. Break the work into smaller tasks, or investigate the code yourself and return with a narrower question.
A complete example
Here is one full pass through the loop.
- Request. You send the request from the earlier chapter: file, selection, error, and a task that returns
None. - Answer. The assistant returns a version using
tryandexcept ZeroDivisionError, and it also adds a logging import. - Check. Reading shows the signature is intact, but the logging import and a new
loggerline violate "do not change other code." Running showsNoneis returned. - Diagnose. The behavior is correct. The scope constraint was ignored, probably because "other code" was easy to read as "other functions."
- Refine. You tighten only the task: "Do not add imports, and do not change any line outside the body of
average." - Re-check. The new answer adds an
if not valuesguard, no imports. The assertions pass, including[0, 0]. - Accept. You apply the change.
Notice that only one part of the request changed between rounds. That made the cause of the improvement clear.
Summary
- Treat every answer as a draft. Read it against your task, run it, test edges, and check claims you cannot run.
- When a check fails, identify the cause before editing: missing context, misleading context, or an unclear task.
- Change one thing per round. Add missing evidence, remove misleading material, and tighten the task.
- Start a new conversation when corrections pile up, and carry over only what is still true.
- Move lessons you keep repeating into standing instructions.
Exercise
You ask an assistant to make average return None for an empty list. It replies with if not sum(values): return None before the division. Name one input where this is wrong, and say which kind of refinement you would make to your request.
Show answer
The input [0, 0] (or any list whose sum is zero) is wrong: the list is not empty, but the function returns None instead of 0.0. Verifying with an edge-case check would catch it. To refine, tighten the task rather than add files: state that only an empty list should return None and that a non-empty list with a zero sum must still return its average, and include [0, 0] as an example of the expected result.
Exercise
After two rounds, an assistant keeps proposing a fix for a traceback you pasted earlier in the session, even though you have since fixed that bug and moved on to a new one. What is the likely cause, and what are two ways to correct it?
Show answer
The old traceback is stale context still present in the conversation, so the assistant keeps weighing it. One fix is to state explicitly that the earlier error is resolved and paste only the current traceback. A cleaner fix is to start a new conversation with the current file version, the new full traceback, and a fresh task statement.