Prompt Engineering
Prompt engineering is the practice of designing the instructions, context, and examples you give a language model so that it produces the output you need — reliably, not just once. This course treats prompts as engineering artefacts: you will structure them deliberately, constrain their output with schemas, diagnose their failures, and measure them with evaluations instead of gut feeling.
What is prompt engineering?
The discipline of designing, testing, and iterating on the input to a language model — instructions, context, examples, and output constraints — to make its behaviour accurate, consistent, and safe for a specific task.
A prompt that works once in a chat window is not the same as a prompt that works ten thousand times inside a product. Real inputs are messy, users are creative, and models change. The prompts that survive production share three properties: they are specific about the task, constrained in their output, and measured against a test set. That is what this course teaches.
Why it still matters as models improve
- Models cannot read your mind. Better models follow instructions more faithfully — which makes clear instructions more valuable, not less.
- Your context is unique. Your product's tone, rules, edge cases, and data formats exist only in your prompt.
- It is the cheapest lever. Changing a prompt costs minutes; fine-tuning costs days and money.
- Every AI system contains prompts. RAG pipelines, agents, classifiers, and evaluators are all driven by prompts.
Prompting vs RAG vs fine-tuning
| Approach | What it changes | Best for | Cost to try |
|---|---|---|---|
| Prompt engineering | The instructions and examples sent with each request | Format, tone, task definition, reasoning steps | Minutes |
| RAG (retrieval) | The facts available to the model at request time | Private, fresh, or large knowledge bases | Hours to days |
| Fine-tuning | The model's weights | Consistent style or format at scale, specialised behaviour, shorter prompts | Days, plus data and training cost |
Always start with prompting. Add retrieval when the model lacks knowledge. Consider fine-tuning only when well-engineered prompts and retrieval still fall short, or when you need to cut cost and latency at high volume.
The prompt engineering workflow
1. Define the task what input, what output, what counts as "correct"?
2. Collect examples 20-100 realistic inputs, including hard and weird ones
3. Draft the prompt role, task, context, format, constraints, examples
4. Run and inspect read the outputs - every one, at first
5. Evaluate score outputs automatically against expectations
6. Diagnose failures group errors by cause
7. Iterate change ONE thing, re-run the eval, keep what improves the score
8. Version and monitor store prompts like code; re-evaluate when models change
What you will learn
| Lesson | What you learn |
|---|---|
| Anatomy of a prompt | The seven building blocks of a prompt, delimiters, ordering, and turning vague prompts into precise ones. |
| System and developer prompts | The instruction hierarchy, what belongs in the system prompt, guardrails, and versioning prompts as code. |
| Few-shot examples | Zero-, one-, and few-shot prompting; choosing, formatting, and dynamically selecting examples. |
| Structured outputs | JSON mode, JSON Schema, Pydantic validation, and repair-and-retry loops. |
| Failure modes and fixes | Hallucination, format drift, injection, sycophancy, truncation — symptoms, causes, and fixes. |
| Evaluate a prompt | Test sets, metrics, LLM-as-judge, comparing prompt versions, and regression testing. |
Prerequisites
- Comfortable Python: functions, dicts, lists, JSON (Python for AI Developers).
- Understanding of tokens, messages, roles, and temperature (LLM Fundamentals).
- An API key for live experiments. Most code in this course runs offline with simulated models so you can learn the mechanics for free.
python -m pip install openai pydantic python-dotenv
Key terms
| Term | Meaning |
|---|---|
| Prompt | Everything the model receives for a request: system message, user message, examples, and context. |
| Instruction | The part of the prompt that tells the model what to do. |
| Context | Background information or data the model needs to complete the task. |
| Delimiter | Markers such as XML tags or triple quotes that separate parts of a prompt. |
| Zero-shot / few-shot | Prompting without examples / with a small number of examples. |
| Structured output | Output constrained to a machine-readable format, usually JSON matching a schema. |
| Eval | An automated test that scores model outputs against expectations. |
| Prompt injection | Malicious instructions hidden in user input or data that try to override your prompt. |
Prompting advice that worked for older models sometimes hurts newer ones — for example, shouting rules in capital letters or adding “think step by step” to a reasoning model. This course focuses on principles that hold across models, and on evaluation so you can verify what works for your model.
Course syllabus
Work through the lessons in order. Your progress is saved in this browser as you mark lessons done.
Syllabus