Lesson 3 of 5 · Free to read
Break big tasks into a chain of small prompts
Break big tasks into a chain of small prompts
Audience: Final-year students and engineers in their first three years
Prerequisites: Lessons 1 and 2
Time: about 25 minutes
What you will keep: a three-step prompt chain for a real task, with a check between steps
This lesson does not cover: agent frameworks that run chains automatically.
Why this matters
Ask for a whole feature in one prompt and you get a long answer with mistakes buried in it. Ask for the same feature in three small steps, checking each before the next, and the mistakes show up early, when they are cheap. This is prompt chaining: the output of one prompt becomes the input of the next.
The shape of a chain
- Divide the task into steps, where each step produces something you can check.
- Check each output before passing it on.
- Join the pieces at the end.
The check in the middle is the point. A chain without checks is just a slower way to get one big, unchecked answer.
A worked example: from ticket to tests
You have a ticket: "Users should be able to reset their password by email."
Step 1 · Ticket → acceptance criteria
"Turn this ticket into acceptance criteria. Use the format 'Given / When / Then', one criterion per line. Include failure cases. Do not write code."
Check: read the list. Is anything missing, such as an expired link, an unknown email, a link used twice? Is anything invented that your product does not do? Edit the list yourself. This is the cheapest moment in the whole process to fix a misunderstanding.
Step 2 · Acceptance criteria → test cases
"For each criterion below, write one test case as a table row: name, setup, action, expected result. Do not write code."
Check: one row per criterion? Do the expected results match what you decided in step 1?
Step 3 · Test cases → test code
"Write these test cases as pytest tests for the module below. One test per row, named after the row. Output one file."
Check: run the tests. They should fail until the feature exists, which shows they test something real.
Three prompts, three checks, and the test suite reflects decisions you made, not guesses the model made.
Parallel branches
Some steps can split. For a code review you might run two prompts on the same diff, one looking only for security problems and one looking only for missing tests, and then merge the findings yourself. Narrow prompts tend to find more than one broad "review everything" prompt.
When chaining is overkill
Chaining costs time. For a one-line fix or a question you can check at a glance, a single prompt is better. Chain when:
- the task has natural stages (requirements → design → code → tests);
- a mistake in an early stage would be expensive later;
- the full answer would be too long to review carefully in one go.
Keep the chain reusable
Write the chain down so you can run it again: each step's prompt, what goes in, what comes out, and the check. Next time you only replace the input.
## Chain: ticket to tests
1. Ticket → acceptance criteria (Given/When/Then, include failures). Check: missing or invented cases.
2. Criteria → test table (name, setup, action, expected). Check: one row per criterion.
3. Table → pytest file. Check: tests run and fail before the feature exists.
Exercise: build and run a three-step chain
Pick a real task with stages, for example ticket → criteria → tests, error log → hypotheses → fix plan, or spec → API outline → README. Write the three prompts, run them on one real input, and record what you changed at each check. Save it as CHAIN.md. Note one mistake a check caught that would have cost more later.
Key points
- Divide into checkable steps, check each, then join.
- Fix misunderstandings at the first step, where they are cheapest.
- Chain only when the task has stages or the cost of a late mistake is high.