From understanding AI to controlling it
Part 3 shifts the module from how assistants behave to how you steer them. A prompt should define the same things you would clarify for another developer: the context, the exact task, the boundaries, and the shape you expect back.
Key ideaA prompt is a compact technical specification, not a search query or casual request. Better specifications usually produce better AI output.
The four-part anatomy
Every structured prompt in the course carries these four parts. The prompt library asks you to keep all four even when you adapt a prompt.
| Part | Purpose | Example |
|---|---|---|
| Role / context | Sets the lens and project situation. | You are a senior FastAPI developer reviewing production readiness. |
| Task | Defines the work to do. | Generate, refactor, validate, review, or explain a specific artifact. |
| Constraints | Defines boundaries and negative constraints. | No auth. No external libraries. Return 422 for invalid input. |
| Output format | Defines the shape of the answer. | Return only code in one block. No explanation. |
Weak to strong: the login example
The notes rewrite one weak prompt. The role shapes the perspective, the task removes guessing, the constraints prevent hallucinated project logic, and the output format makes the result usable.
| Weak prompt | Structured prompt |
|---|---|
| Generate a user login function. | You are a senior backend developer building a FastAPI API. Write a POST /login endpoint. Requirements: accept email and password in JSON; return 400 if either field is missing; return 401 if credentials are invalid; do not implement user lookup. Return only the endpoint function. |
Read with careThis example returns 400 for missing fields, while the Task Tracker examples return 422 for invalid input. Neither is a universal rule: the status code is a decision your prompt states. Note too that login is only an anatomy example; authentication is out of scope for the Task Tracker.
Four common prompt mistakes
Each mistake has a better habit beside it.
| Mistake | Better habit |
|---|---|
| Assuming the assistant knows your stack or codebase. | State the language, framework, version when relevant, and project conventions explicitly. |
| Asking for too many things at once. | Split authentication, tests, docs, refactoring, and debugging into separate prompts. |
| Using vague verbs such as fix, improve, or clean up. | Say what improvement means: safer, faster, shorter, more readable, or more defensive. |
| Omitting negative constraints. | Say what the output must not include: no auth, no logging, no new libraries, no extra prose. |
Key ideaThe absence of a constraint is often treated as permission. If you don’t want a database, authentication, Docker, logging or extra libraries, say so.
The first response is a draft
A weak workflow treats the first answer as binary: accept it or throw it away. A better one treats it as a draft. Inspect it, keep what works, identify what is missing, and write a targeted follow-up that names the exact gap and what must stay the same.
Targeted follow-up from the notesThe endpoint accepted a whitespace-only title. Add validation that strips whitespace before checking emptiness and returns 422 with a clear error message. Keep the existing function signature.
Exercise: rewrite the prompt
Rewrite each weak prompt with role or context, task, constraints and output format. For the first, include the stack, expected behavior, actual behavior and the relevant code. For the second, include the test framework, endpoints or scenarios, constraints and output format. Prompt P2 in the library is a worked answer to the first one.
- Weak prompt 1: “Fix the bug in my task filtering code.”
- Weak prompt 2: “Write me some tests for the API.”
Key takeaways
- Role or context, task, constraints, output format: every prompt, every time.
- State the stack, split large asks, define “better,” and write negative constraints.
- What you don’t forbid, the assistant may add.
- Improve a first draft with a targeted follow-up that names the gap and what must stay.