Lesson 8.4core2 h 30 min

Prompting as programming

Conditioning a model precisely: instructions, examples, structure and evaluation

A prompt is a program that a probabilistic interpreter runs. Learning to write them well is the cheapest way to improve any LLM application, it is the interface through which agents (10.1 What is an agent? Loops, autonomy and workflows vs agents) and RAG systems (9.6 Generation side: context assembly, citations, structured outputs and tool calling) talk to models, and bad prompting is the most common cause of "the model can't do X". This lesson treats prompting as engineering: components, techniques with evidence, evaluation, and the security caveat that follows you into every later phase.

You'll be able to

  • Decompose a prompt into role, context, instructions, examples and output specification
  • Use zero-shot, few-shot, chain-of-thought and self-consistency appropriately and know when each stops helping
  • Control output structure and reliability with schemas, delimiters, prefills and grounding instructions
  • Set up a prompt evaluation loop with a test set, metrics and versioning
  • Recognize prompt injection and why data must never be treated as instructions

Key ideas

  1. A prompt conditions p(output | prompt); structure it as role, context, instructions, examples, output spec and user turn, with explicit delimiters.
  2. Few-shot examples teach format and label conventions; order and label space matter, and more examples are not always better.
  3. Chain-of-thought helps multi-step tasks because generated tokens are computation; self-consistency votes over k sampled chains.
Show 4 more key ideas
  1. Reasoning models already deliberate internally — give them goals, constraints and budgets rather than step-by-step scripts.
  2. Enforce structure with schemas, prefills and grounding instructions; permit 'I don't know'.
  3. Prompts are code: keep a test set, score with metrics or a judge, version prompts with the model they were validated on.
  4. Everything in the context can act as an instruction — prompt injection means external content must be treated as data.

Suggested path through this lesson