Few-shot examples
Few-shot means putting several “input → acceptable output” demonstrations in the prompt. Models often learn format, edges, and tone faster from examples than from three more adjectives. OpenAI: keep examples in a short YAML or bullet block that a team can edit. Anthropic: wrap examples like real inputs so they do not glue onto instructions.
Zero-shot, one-shot, few-shot
More examples are not always better. Repeated easy cases burn context, hurt a cacheable prefix, and teach “only these happy paths exist.” Cover failure edges, not twenty happy paths.
What an example should show
A good example locks three things:
- What inputs look like (noise, missing fields, mixed languages)
- The output contract (field names, order, how empty values look)
- Refusal policy (what to emit when the model must not invent)
The third example is not an attack tutorial. It shows refuse and escalate: sensitive or out-of-scope asks should not close as a normal how-to.
Anti-patterns
Changing examples changes product behavior. Commit them, and attach gold questions from Evaluation.
Prefill and “continue from here”
Some APIs let you prefill the assistant (for example {) to push the model onto a JSON track. That is format help, not a reasoning guarantee. When the vendor offers structured output / schema, prefer the schema (Structured output); treat prefill as a fallback.
Using “whatever happened last turn” as an example bloats the window. Put durable demos in the system prompt or a dedicated example block, not in accidental chat history.
Relation to the four blocks
- Role / constraints say in sentences “do not invent IDs”
- Examples show “when there is no ID, the field is
null” - They must agree; on conflict the model often follows the example
In tool-free chat, few-shot is often the strongest lever. For tool-using agents, examples should show when to call a tool vs answer directly, not a fake dump of tool JSON (that is the API’s job). See Tools and agents.