Lesson 2 of 6 · Free to read
Four prompt patterns that do most of the work
Four prompt patterns that do most of the work
Audience: Final-year students and engineers in their first three years
Prerequisites: Lesson 1
Time: about 25 minutes
What you will keep: four prompt templates you can reuse
This lesson does not cover: prompt engineering for building AI products (that is a separate module).
Why this matters
Most people prompt the same way every time: they describe the feature and hope. When the answer is wrong, they describe it again, louder. Skilled engineers switch patterns on purpose. Four of them cover nearly every coding situation.
The four patterns
| Pattern | Use it when | What you add to the prompt |
|---|---|---|
| Specify | You know the contract | Inputs, outputs, errors, and what "done" means |
| Iterate | The output is close but wrong | What to keep, the one thing to change |
| Constrain | The AI is overbuilding or wandering | Which files, no new dependencies, no refactors |
| Critique | You need a review, not more code | "List risks, rank them, do not rewrite yet" |
Specify
Weak: "Add a tasks endpoint."
Strong: "Add POST /tasks to app/main.py. Body: title (non-empty string) and due (ISO date). Return 201 with the saved task including an id. Return 422 for an empty title. Add three pytest tests: valid task, empty title, missing due date. Run the tests and show me the output."
The strong version is longer, and it saves you three rounds of correction. A good specify prompt reads like a ticket a teammate could pick up.
Iterate
When an answer is 80% right, do not restate the whole request. Name what stays and what changes:
"Keep the function signature and the tests. Fix only the date comparison: tasks due before today are overdue. Do not rename anything."
Iterating in small steps keeps the parts that already work from drifting.
Constrain
When the AI keeps touching things you did not ask about, fence it in:
"Change only app/main.py and tests/test_tasks.py. Do not add packages. Do not reformat unrelated code. Output a diff."
Constraints are also how you keep an agent safe. A boundary the AI can read is better than a boundary you meant to set.
Critique
Sometimes the best next prompt asks for no code at all:
"Here is my diff. List the five biggest risks, ranked by severity. For each, say what test would catch it. Do not rewrite the code yet."
Critique turns the model from a code generator into a reviewer. It is especially useful just before you open a pull request.
Switching patterns
The skill is noticing which one you need. A typical sequence on a real bug:
- Specify: "Here is the failing test and the stack trace. List three likely causes. No fix yet."
- You pick the likely cause. Specify again: "Fix cause 2 in
list_tasksonly, and run the tests." - The AI also "improved" two other functions. Constrain: "Revert everything outside
list_tasks." - Tests pass. Critique: "What edge case does this fix still miss?"
Four prompts, each with a clear job, beat ten vague ones.
Exercise: write your templates
Create a file called PROMPT-TEMPLATES.md. Write one template for each pattern, with blanks for the parts that change, for example:
## Specify
Add ___ to ___. Inputs: ___. Output: ___. Errors: ___.
Done means: ___. Run ___ and show me the output.
Use them in the lab in lesson 5 and adjust whatever did not work.
Key points
- Specify the contract, iterate in small steps, constrain the scope, ask for critique.
- Switch patterns on purpose when the current one stops working.
- Ask to see test output; do not accept "done" without it.