AI

Few-Shot

AI EngineerPrompt Engineering

Few-shot prompting includes a handful of worked examples — input paired with the output you want — before the actual task. Instead of describing the format, you demonstrate it: two or three question-answer pairs, then the real question. The model picks up the pattern through in-context learning, matching your examples’ structure, tone, labels, and level of detail without any training or fine-tuning.

The reason this earns its token cost is that examples communicate things instructions can’t. You can spend a paragraph describing your ideal summary style, or show two summaries and let the model infer the rest — the examples usually win. Few-shot shines exactly where zero-shot wobbles: enforcing a precise output format, teaching domain-specific label definitions (“we call this a P1, not that”), and pinning down edge cases. The trade-off is real, though: every example is billed on every request, and the model imitates your examples faithfully — including their mistakes and biases.

In practice, you’ll place examples in the prompt with consistent delimiters (Input: / Output:, or XML tags), or as alternating user/assistant turns in the messages array, which chat models treat as prior conversation. Use two to five diverse examples that cover your tricky cases, keep formatting identical across them, and mix the label distribution so the model doesn’t learn “the answer is usually A.” When examples still aren’t enough for multi-step reasoning, chain-of-thought is the next tool.

Resources

0/6 completed