Lesson 9: Prompt Engineering
A language model does only one thing — predict the next token — so the entire art of using it well comes down to one skill: giving it the right tokens to continue from. That skill is called prompt engineering, and it is less like programming and more like briefing a very capable, very literal colleague. The model will do exactly what your prompt points it towards, including following your mistakes, your ambiguities and your false assumptions. A good prompt is therefore specific, structured, and written with the model's habits in mind.
The first habit to build is to say what you want, not just what you are asking about. 'Tell me about the French Revolution' gives the model almost no guidance: a paragraph or an essay? For a child or an expert? Instead, say what you want: 'Explain the French Revolution in three short paragraphs for a 14-year-old, ending with why it still matters today.' The role, the audience, the length, the format and the purpose are all part of the instruction, and each one narrows the space of likely continuations towards something useful.
Show, don't just tell
The second habit is to give examples. If you want the model to sort feedback into categories, show it two or three examples of feedback already sorted, and it will follow the pattern for the rest. This is called few-shot prompting — a few examples, or shots, in the prompt itself — and it works because the model is a pattern-completer: give it a pattern and it continues it. Examples are often more powerful than instructions, because they show the exact format, tone and level of detail you want, which words alone struggle to convey.
Think step by step
The third habit is to ask the model to show its working. Adding 'think step by step' or 'work through this in stages, showing each step' often improves answers to reasoning problems dramatically. The reason is built into how the model works: each token it generates becomes part of the context for the next one, so writing out intermediate steps gives it more to work with, and errors in one step are easier to spot. It does not make the model a reliable reasoner — a wrong step early on still poisons the rest — but it makes its reasoning visible, so you can check it.
Testing and versioning prompts
A prompt is not a piece of prose you write once and forget; it is part of a system, and it should be treated like one. Good teams keep their prompts in files, with version numbers, so that when an answer gets worse they can tell exactly what changed. They also test prompts the way software is tested: a small set of example inputs with expected outputs, run every time the prompt changes, so that a fix for one case does not quietly break three others. And they keep a record of the failures — the prompts that produced invented facts, rude answers or wrong formats — because those failures are the specification for the next version. If you take one working habit from this lesson, let it be this: never edit a prompt that matters without saving the old version and testing the new one on the same examples. The model will not tell you when you made it worse; only your tests will.
A final habit: iterate. Almost no good prompt is written in one go. Ask, read the answer, notice what is missing or wrong, and adjust the prompt: add a constraint, give an example, change the format. Treat the model as a collaborator you are learning to brief, not as an oracle you must phrase perfectly the first time. And remember that prompting cannot fix what the model does not know: no prompt will make it tell you a fact that is not in its training data, or check a fact against the world. For that you need the tools of the next two lessons.
Key Terms
- Prompt engineering
- The skill of writing prompts that steer a language model towards useful output: specific, structured and aware of how the model works.
- Prompt
- The text given to a model, telling it what to generate or do.
- Few-shot prompting
- Giving the model a few examples in the prompt, so it continues the pattern for new cases.
- Zero-shot prompting
- Asking the model to do a task with no examples, relying only on the instruction.
- Step-by-step reasoning
- Asking the model to show its working in stages, which improves reasoning answers and makes errors visible.
- Role
- A part assigned to the model in the prompt, such as 'act as a patient tutor', which steers its tone and approach.
Discussion Questions
- Why is 'Explain the French Revolution in three short paragraphs for a 14-year-old' a better prompt than 'Tell me about the French Revolution'?
- Give an example of a task where showing the model two examples would work better than describing the task in words.
- Why does asking a model to show its working help it get reasoning questions right more often?
Practice Questions
- What is prompt engineering?
- Why should a prompt say what you want, not just what you are asking about?
- What is few-shot prompting, and why does it work?
- Why does asking for step-by-step working improve reasoning answers?
- What can prompting not fix?
Show answers
- The skill of writing prompts that steer a language model towards useful output. It means being specific, structured and aware of how the model works.
- Because the model needs guidance on role, audience, length, format and purpose. Without them it must guess, and its guess may not match what you needed.
- Giving a few examples in the prompt so the model continues the pattern. It works because the model is a pattern-completer, and examples show the exact format and tone wanted.
- Because each generated step becomes context for the next, and errors become visible. Writing out intermediate steps gives the model more to work with, though a wrong early step still poisons the rest.
- A model not knowing a fact, or being unable to check facts against the world. No prompt can make the model tell you something outside its training data or verify a claim.