Few-Shot Prompting
Few-shot prompting embeds task examples directly in the prompt to guide output format without retraining. It excels at niche tasks and consistent formatting, but mismatched examples degrade performance more than no examples at all.
WHY IT EXISTS: Large language models are trained on vast text corpora, but they cannot know the exact format, tone, or edge-case logic your application needs. Fine-tuning is expensive and slow. Few-shot prompting exists because it is the cheapest way to adapt model behavior at inference time by leveraging the model's existing ability to recognize and continue patterns.
THE MENTAL MODEL: Think of few-shot prompting as showing a new coworker three completed forms instead of reading the employee handbook. The examples do not rewrite the coworker's brain; they temporarily anchor their next output to a visible pattern. If the forms are representative, the coworker fills out the fourth form correctly. If the forms are outliers, the coworker produces outliers.
HOW IT WORKS: You prepend a small number of input-output pairs to the actual query. Each pair demonstrates the desired transformation. The model attends to these demonstrations as local context and generates a completion that statistically continues the pattern. No weights are updated. The effect is purely contextual. Typical counts range from one to roughly ten examples; beyond that, you hit context-window limits and diminishing returns as the model loses focus on the earliest examples.
WHEN TO USE IT: Use few-shot prompting when you need strict output structure, such as JSON with specific keys, or when the task is too niche for the model to have seen it frequently during pretraining. It is also effective for style transfer, classification with custom taxonomies, and multi-step reasoning where a single instruction is ambiguous.
WHEN NOT TO USE IT: Do not use it when the prompt context is already near the token limit, because examples consume valuable space. Avoid it when consistency across millions of calls is required and the examples introduce variability. If the task can be solved with a clear zero-shot instruction, adding examples adds latency, cost, and the risk of example bias without benefit.
ONE CANONICAL EXAMPLE: A support ticket classifier receives raw customer emails and must label them as Refund, Bug, or Account. A zero-shot prompt might mislabel a refund request as an account issue. A few-shot prompt includes three labeled emails followed by the new email. The model sees the pattern and emits the correct label with higher accuracy and a stable output format.
Read the original → en.wikipedia.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.