Skip to content
ML to LLMs
Learning path

Module 28

Prompting and context engineering

Steer a model without training it: prompts as tested specifications, few-shot examples, chain-of-thought and voting, and deciding what goes into the context window.

  1. 1. Prompt engineeringWrite prompts as specifications (role, task, labels, format, edge-case rules), pick decoding settings, and prove a prompt change helped with a test set and a pass rate.40 min
  2. 2. Few-shot and chain-of-thoughtUse examples to teach format, make the model reason in steps, vote over several sampled chains, and know when each technique is worth its tokens.40 min
  3. 3. Context engineeringDecide what goes into the context window and in what order (instructions, tools, retrieved documents, history, memory) under a token budget, and keep per-call cost bounded as conversations grow.40 min

A model's behaviour at inference time is set by its weights and its context. This module is about the context: how to write instructions that specify the task, how examples and step-by-step reasoning raise accuracy, and how to assemble the window (instructions, tools, retrieved documents, history, memory) under a token budget. Every technique is measured on a test set, and all code runs offline with a scripted stand-in model that marks where a real client plugs in.

LeverWhat it changesFailure mode
Instructionslabel set, format, edge-case rulesvague spec, model guesses
Decoding settingsdeterminism versus varietynoisy outputs on extraction tasks
Few-shot examplesformat and style by demonstrationbiased or leaked examples
Chain-of-thoughtper-step error on multi-step taskswasted tokens on simple tasks
Self-consistencyvotes out random errorsamplifies systematic errors
Context assemblywhat the model sees, in what orderburied facts, growing cost
#LessonYou will be able to
1Prompt engineeringwrite prompts as specifications, build a prompt test harness, and judge a change by pass rate and standard error
2Few-shot and chain-of-thoughtchoose examples, explain why reasoning steps reduce compounding error, and compute self-consistency's accuracy and cost
3Context engineeringbudget the window, order retrieved material, compact history, select tools, and bound per-call cost

Builds on Decoding and the RAG pipeline; leads into Tool use and agents.

Next moduleModule 29: Speech and audio