A good prompt gives what the assistant lacks
A good prompt is a request that gives a coding assistant the goal, the facts it cannot see and the limits the answer must keep. It matters because the assistant fills every gap with a guess, and a guess that looks fine is hard to spot.
Compare "make it better" with "in shop.js, only change asPounds so that it shows two decimal places". The second can be checked.
By the end of this lesson
Note
I can write a request that gets a usable answer.
Key words
| Word | What it means |
|---|---|
| Request | the words you give an assistant to say what you want |
| Constraint | a limit the answer must keep |
| Example | a sample input with the output you want |
| Scope | how much you ask for at one time |
| Iterate | to ask again with a correction |
The cells students fill in are left blank in this preview.
A request has five parts
Say the goal: what should exist when the work is done. Say where: the file or the function. Say the constraints: what must not change, and what style to follow.
Give an example: one input and the output you want. Say how you will check: for example, that a test must pass.
Worked example: a weak request made strong
| Part | Weak request | Strong request |
|---|---|---|
| Goal | Make it better | Show prices with two decimal places |
| Where | In the code | The asPounds function in shop.js |
| Constraint | Nothing said | Change nothing else, keep the tests as they are |
| Example | Nothing said | asPounds(5) should give £0.05 |
| Check | Nothing said | The tests must still pass |
The cells students fill in are left blank in this preview.
Send a vague request
docker exec -w /home/node/project agent opencode run "Tell me about this project."Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Send a specific request
docker exec -w /home/node/project agent opencode run "In shop.js, list each function with its parameters, one per line, and say in one short sentence what it is for. Do not change any file."Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Compare what the two requests got back
Both requests only ask a question, so nothing in the project changes. The words you get back will differ from a classmate's and from your own next try.
Look at the shape instead. Which answer is easier to check against the file? Which tells you more than you could see for yourself? The specific request names a file, a format and a limit.
Ask for one small step at a time
The more you ask for at once, the more the assistant decides for you. Ask for one function, read it, then ask for the next.
When an answer is wrong, do not start again. Iterate: say what is wrong and what you want instead. "The total ignores the last item" is far more useful than "that is wrong".
A common mistake
Warning
Many people think a longer prompt is a better prompt. Length is not the point: facts are. Add the file, the limit and an example, and cut every sentence that adds none of them.
Say what shape the answer should take
You can ask for an answer in a form you can check. Examples are "one function only", "a list, one item per line" and "the changed lines and nothing else".
A small, shaped answer is quick to read and quick to run. A long essay of code is hard to review, which is the next lesson.