Craft, not magic wording
The notes are plain about it: prompt engineering is not magic wording. It is a learnable craft built from a few practical patterns used consistently. The module teaches three, and in real work you often combine them.
Key ideaPrompt engineering is a learnable craft built from a few practical patterns used consistently.
Pattern 1: role prompting
A role assigns a specific professional lens. Avoid vague roles such as “expert.” Use roles that tell the assistant what to pay attention to: here, error handling, input validation and status codes.
Prompt from the notesYou are a senior FastAPI developer reviewing a REST API for production readiness. Review the following endpoint and identify issues related to error handling, input validation, and HTTP status codes. [paste endpoint code]
Pattern 2: few-shot prompting
Few-shot prompting gives the assistant one or more examples to imitate. The notes stress that the example sets the quality ceiling, not just the format: weak acceptance criteria in your example produce weak criteria in every story. Best uses are user stories, test cases, ADRs, API docs and commit messages.
Prompt from the notesGenerate user stories for the Task Tracker in this format. Example: Story: As a team member, I want to create a task so that I can track work. Acceptance Criteria: - Title is required; missing title returns 422. - Description is optional. - Created task appears in the list. Now generate 5 more stories in the same format.
Key ideaThe example sets the quality ceiling, not just the format.
Pattern 3: constraint-based prompting
Constraint-based prompting lists what the output must and must not include. It is the most direct way to prevent scope creep, unexpected dependencies and the wrong output shape.
Prompt from the notesWrite a function to validate a task object before saving it. Constraints: - Use only Python standard library and Pydantic. - Do not add logging. - Return: { valid: bool, errors: list[str] }. - Title must be non-empty after stripping whitespace. - Status must be ToDo, InProgress, or Done. - Priority must be Low, Medium, or High. Return only the function. No explanation.
When to use each pattern
Pick by what the task needs. When the output is complex or high-stakes, use all three together.
| Pattern | Use when... | Example course use |
|---|---|---|
| Role prompting | A specific professional perspective is needed. | Review an API endpoint for validation, errors, and status codes. |
| Few-shot prompting | The desired structure or quality is easier to show than describe. | Generate user stories matching a strong example. |
| Constraint-based prompting | You need to prevent extras, scope creep, dependencies, or wrong return shapes. | Scaffold only the skeleton; do not add auth, database, or full CRUD. |
| All three together | The output is complex or high-stakes. | Architecture analysis, ADR drafts, security reports, structured test cases. |
The AI interaction loop
This is the module’s core workflow. Don’t submit and accept. Each step has a concrete meaning, and “it looked right” is not a test.
- AskStructured prompt
- InspectRead before using
- RunExecute or apply
- TestVerify behavior
- RefineSmallest correction back
Do not submit and accept.
| Step | What it means | What it looks like in practice |
|---|---|---|
| Ask | Write a clear structured prompt. | Include role/context, task, constraints, and output format. |
| Inspect | Read the output before using it. | Check imports, function names, assumptions, error cases, and return shape. |
| Run | Execute the code or apply the artifact. | Start the server, paste the function into the project, or review the requirement for buildability. |
| Test | Verify behavior explicitly. | Use test cases, curl, Swagger, or acceptance criteria. “It looked right” is not a test. |
| Refine | Feed the smallest correction back. | Use the exact error, failing case, or missing requirement as the next prompt. |
The loop on a validation function
The loop also applies to non-code artifacts. For requirements, “run” means checking whether a story can actually be built and tested. For architecture, it means weighing trade-offs before accepting a proposal. Here is the loop on code, as the notes walk it.
| Step | Example |
|---|---|
| Ask | Write a validation function for title, status, and priority. Return { valid, errors }. |
| Inspect | Does it trim whitespace? Does it use the exact allowed values? Does the return shape match? |
| Run | Paste it into the project and check imports and execution. |
| Test | Try empty title, whitespace-only title, invalid status, and a valid object. |
| Refine | If whitespace-only title is accepted, ask for a trim check and exact error message. |
Exercise: apply all three patterns
Generate user stories for a Task Tracker that supports priorities and assignees. Write three separate prompts: one role prompt, one few-shot prompt and one constraint-based prompt. Submit them to your AI tool and compare the outputs for structure, acceptance criteria and edge cases. The library’s P3, P4 and P5 are worked versions of each pattern.
Key takeaways
- Role prompting sets a lens; few-shot sets a quality ceiling; constraints set boundaries.
- Combine all three when the output is complex or high-stakes.
- Ask, inspect, run, test, refine, and never submit and accept.
- Refine with the exact error or failing case, not a general complaint.