Prompt engineering from the ground up
Instructions that survive contact with users
- Beginner
- 10 chapters
- 150 min read
How to write prompts that behave the same way twice: the four parts every prompt needs, constraints a program can check, few-shot examples that do not leak or unbalance, structured output with a retry path, decomposition in code, the system/user hierarchy, and defences against prompt injection.
What You'll Learn
- Write a prompt as instruction, context, input and output contract
- Turn vague requirements into checkable constraints
- Choose and balance few-shot examples, and avoid leakage
- Validate structured output and retry with the actual error
- Decide when reasoning steps help and when to decompose in code
- Keep instructions and data in separate message channels
- Recognise direct and indirect prompt injection, and bound the damage
- Run a prompt harness that compares variants and gates a release
Prerequisites
- No programming experience needed beyond reading short Python
- The Evaluation course is a good follow-on, not a prerequisite
- No API key is required — every example runs on plain Python
Vocabulary
The terms the chapters assume, in plain words.
- constraint
- A limit on the answer that a program can check, such as a length, an allowed label or a required citation.
- context
- The background material the model needs to answer well, kept separate from the thing it must act on.
- continuation
- The text a model writes next, given everything that came before it.
- delimited block
- Text wrapped by matching markers, such as triple backticks, so its edges are unmistakable.
- distribution
- The pattern of how often each possible value appears, or how likely each one is.
- few-shot example
- A worked input and answer pair placed in the prompt so the model can copy the pattern.
- instruction
- The sentence that names the task, usually starting with a verb.
- JSON
- A text format for structured data built from names, values, lists and nested braces.
- model
- The trained program that reads text and predicts what comes next.
- output contract
- The part of a prompt that states the shape of a valid answer, in words a checker can enforce.
- parser
- The code that turns the model's text into a value your program can use.
- prompt
- Everything sent to the model in one request: instructions, background, the input and the answer's required shape.
- prompt injection
- Text that tries to give the model orders, either typed by a user or hidden inside a document it reads.
- register
- The level of formality and the kind of wording suited to a particular audience or setting.
- schema
- A named set of fields with their types and allowed values, used to check an answer's shape.
- system message
- The opening instruction the model treats as standing policy for the whole exchange.
- temperature
- A setting that controls how much randomness the model adds when choosing each token.
- token
- A chunk of text — often part of a word — that the model reads and bills for.
- user message
- A turn written by the person using the app, treated as data rather than standing policy.
Course Content
- 01What a prompt isNot started
Four parts, not one blob: the instruction, the context, the input and the output contract. Most bad prompts are missing one of them.
- 02Specificity and constraintsNot started
A model cannot infer a limit you did not state. Every constraint you add is one fewer dimension the answer can drift in — as long as the constraint is checkable.
- 03Few-shot examplesNot started
An example teaches a pattern faster than a paragraph of instructions. The risks are the ones a teacher would recognise: the wrong examples, too few of a class, and giving away the answer.
- 04Structured outputNot started
A schema turns a reply into a value. The prompt promises the shape, the validator enforces it, and the retry tells the model exactly what it broke.
- 05Reasoning and decompositionNot started
Asking for the steps helps on multi-step problems and hurts on simple ones. The reliable version is to decompose the task in code, not to hope the model narrates.
- 06Roles and system promptsNot started
The system message is the rule; the user message is the data. The moment they share a string, the data can rewrite the rule.
- 07Prompt injectionNot started
Any text that reaches the model can try to give it orders. Wording helps; permissions are what actually stop it.
- 08Versioning and reviewNot started
A prompt is a decision the product makes on every request, so it needs a history, a reviewer and a way back. Versions stay fixed; labels move.
- 09Prompts across modelsNot started
A prompt tuned on one model is a draft, not a portable asset. Porting it is a measurement exercise: find what the new model lacks, adapt the smallest part, and re-test.
- 10Capstone: a prompt harnessNot started
Three prompt variants, one set of cases, and a table that says which one to ship. The whole course, applied to the decision people actually argue about.
