Few-shot prompting is the technique of embedding worked examples directly into your prompt so the model infers the pattern you want — and by the end of this lesson you'll know exactly how EngineerPrep uses it to make Claude produce reliable, structured output at production scale.
It's 9 AM Monday. You open Slack and there's a thread from the on-call engineer: 'AI tutor responses are broken for ~38% of sessions. JSON parse exceptions everywhere.' You pull up Sentry. The stack trace is always the same place: LessonSectionParser.parse() throwing JsonProcessingException because the raw LLM response starts with: Here is the JSON you requested: json { "title": "..." The JSON itself is fine. But there's prose before it, a markdown fence around it, and sometimes a closing sentence after it. Your downstream parser never stood a chance. Here's the thing — your prompt says 'Return a JSON object with the following structure.' You tested it. It worked. So what changed? Nothing changed. That's the problem. Large language models are probabilistic. The instruction 'return JSON' is a weak signal.…
The Monday incident above is already in your head, so let's move straight to the answer. What Exactly Is It? Few-shot prompting means including a small number of complete input→output examples directly inside your prompt, before the real query. You're not writing a longer instruction — you're showing the model a pattern and trusting it to continue that pattern for your actual input. 'Few' literally means two to five examples. 'Zero-shot' means no examples. 'One-shot' means exactly one. These aren't marketing terms — they describe the number of demonstrations you're providing. Here's the intuition: a language model is an extremely powerful pattern-completion engine. When you write 'Return JSON', it has to guess what JSON you mean, what style, what whitespace, what field order, whether to include explanatory prose. When you show it three examples of input/output pairs, it stops guessing…
Scene Setup Imagine a horizontal stage. On the left side sits a large grey box labeled PROMPT . On the right side is a smaller box labeled MODEL OUTPUT . Between them is an arrow — the inference call. Inside the PROMPT box, think of the content as a stack of colored cards. Each card is a block of text. Blue cards are instructions. Green cards are examples. Yellow cards are the real query. The MODEL OUTPUT box starts blank. --- Animation 1 — Zero-Shot (Just an Instruction) A single blue instruction card drops into the PROMPT box: 'Given a topic, return a JSON object with fields: title (string), difficulty (string), tags (array of strings).' Then a yellow query card drops in: 'Topic: Binary Search Trees' The arrow pulses. The MODEL OUTPUT box fills. Sometimes it shows: {"title": "Binary Search Trees", "difficulty": "medium", "tags": "trees", "algorithms" } Perfect.…
The Context Window as a Conditional Distribution A transformer-based language model like Claude doesn't have a separate 'instruction-following module' that's distinct from its 'example-reading module.' It's all the same mechanism: every token in the context window influences the probability distribution over the next token. When you add a few-shot example, you're not activating a special mode — you're populating the context with tokens that shift the probability distribution for every subsequent token. Here's the key insight: the model processes your prompt left to right, attending to all previous tokens. When it reaches your real query, the key-value attention cache already contains the representation of every example you provided.…