Chapter 02
Zero-shot and few-shot prompting
When to rely on instructions alone and when to show the model worked examples of the input and output you want.
Zero-shot prompting
- What
- Asking for a task with instructions only and no examples.
- Why
- Modern models handle most common tasks zero-shot, so start here and add examples only when the output drifts.
Few-shot prompting
Also called in-context learning, examples, shots
- What
- Including a few input and output pairs before the real input so the model copies the pattern, format and tone.
- Why
- Examples pin down format and edge cases faster than paragraphs of rules, especially for classification and extraction.
Classify the ticket as bug, feature or question.
<example>
Ticket: App crashes when I upload a PNG
Label: bug
</example>
<example>
Ticket: Can you add dark mode?
Label: feature
</example>
Ticket: {{TICKET}}
Label:Diverse, representative examples
- What
- Choose examples that cover different cases, including tricky ones, rather than three near-copies of the easy case.
- Why
- Models copy surface features: three short examples teach "be short", three positive ones teach "say positive".
Watch out
Putting all examples of one label first, so the model leans towards the last label it saw.
Output primers and prefill
Also called prefill, response prefix
- What
- Ending the prompt with the start of the answer, such as
Label:or an opening{, so the model continues in that shape. Some APIs let you prefill the assistant turn directly. - Why
- It is a cheap way to skip preambles like "Sure, here is..." and force a format.
Watch out
Relying on prefill where the API or model version does not support it; check the provider docs.
When examples beat instructions
- What
- Use examples for format, tone and fuzzy labels; use instructions for hard rules, limits and anything that must never happen.
- Why
- Examples show the target, rules draw the fence. Most production prompts need both.