Sub topic 7
Telling the Assistant What to Do
This chapter assumes you have used an AI chat or coding assistant, can read a Python traceback, and know how to attach a file or selection in your editor or terminal. Files, selections, and errors tell the assistant what the situation is. The task statement tells it what to do about it. Without one, the assistant has to guess.
Why context alone is not enough
Suppose you attach stats.py and paste the traceback, then send nothing else. The assistant might explain the error, rewrite the whole file, add tests, or raise an exception with a nicer message. Each of those is a reasonable reading of your input. Only one matches what you want.
A task statement removes that guesswork. It names the action and the limits on that action.
The parts of a good task statement
A useful task statement has three parts:
- An action verb. Say "change", "explain", "review", "write a test for", or "find the cause of". Each verb produces a different kind of answer.
- The target. Name the function, file, or behavior to work on.
- Constraints and the expected result. State what must stay the same, what must not be touched, and what "done" looks like.
Here is the request from the running example:
Context: stats.py (attached), selection: the average function (lines 1-2).
Error: ZeroDivisionError: division by zero when average([]) is called.
Task: Change average so an empty list returns None instead of raising. Keep the function signature and do not change other code.The action is "change". The target is average. The expected result is that an empty list returns None. The two constraints are to keep the signature and to leave other code alone.
Vague versus specific
Compare these two tasks for the same bug.
| Vague task | Specific task |
|---|---|
| "Fix this." | "Change `average` so an empty list returns `None`. Keep the signature." |
| "Make it better." | "Add type hints to `average` without changing its behavior." |
| "What's wrong?" | "Explain why line 2 raises `ZeroDivisionError` for an empty list. Do not edit the file." |
The specific versions say what output you expect. The last row shows that an explanation request can include a limit too. If you only want to understand a problem, say that no edits are wanted.
Choosing the kind of task
The same context can serve different goals. Pick the one you need and say so.
- Diagnose: ask for the cause, not a fix. This suits errors you do not yet understand.
- Change: ask for a specific edit, with the scope stated.
- Review: ask what could go wrong, and name what to look for, such as edge cases.
- Explain: ask for a walkthrough of a selection you did not write.
If you are unsure what the fix should be, start with diagnosis. Then send a second request with a change task once you know the cause.
Constraints that prevent surprises
Constraints are the most useful part of a task statement. They stop the assistant from making changes you did not ask for. Common ones are:
- Keep the function signature and public names.
- Change only the selected lines.
- Do not add new dependencies.
- Return the result as a diff or only the changed function.
- Follow the conventions in the project file.
Keep it to one task
Ask for one thing at a time. A request such as "fix the bug, add tests, rename the function, and update the docs" is hard to check, and a mistake in one part hides problems in the others. Send the fix first, check it, then ask for tests in a follow-up.
Check the result against the task
The task statement also gives you a way to check the answer. For the example, run the code and confirm each part:
def average(values):
if not values:
return None
return sum(values) / len(values)
print(average([]))
print(average([2, 4, 6]))The first call prints None, and the second prints 4.0. The signature is unchanged, so the constraint holds. If the assistant had also edited other code, you would point to the "do not change other code" constraint and ask it to revert.
Exercise
You attach stats.py and the traceback, and you want to understand why average([]) fails without any edits to the file. Write a one-sentence task statement that includes an action, a target, and a constraint.
Show answer
For example: "Explain why line 2 of average raises ZeroDivisionError when the list is empty, and do not edit the file." The action is "explain", the target is line 2 of average, and the constraint is "do not edit the file".
Exercise
A colleague sends this request: "Fix the bug, add tests, and rename the function." Why is this a weak task statement, and how would you improve it?
Show answer
It bundles three tasks, so the result is hard to check and an error in one part can hide problems in another. Split it into separate requests, such as "Change average so an empty list returns None. Keep the signature." Then review the result before asking for tests.