Skip to main content
Mujtaba Farooq logoMujtaba
Back to BlogPrompt Engineering

Few-Shot Prompting: A Complete Guide With Examples

Feb 17, 20263 min read
Share:

What Few-Shot Prompting Is

Few-shot prompting means including a small number of example input-output pairs directly in the prompt, before asking the model to handle a new case. Instead of explaining the rules abstractly, you demonstrate them — and LLMs are often dramatically better at following a demonstrated pattern than a described one.

Zero-Shot vs. Few-Shot

Zero-shot

"Classify the sentiment of this review as positive, negative, or neutral." — No examples given. Works fine for genuinely simple, common tasks, but ambiguous edge cases (sarcasm, mixed sentiment) are handled inconsistently.

Few-shot

Same instruction, but preceded by three or four example reviews with their correct classifications, including one tricky case (a review that's sarcastically negative while using positive words). The model now has a concrete pattern to follow, including how to handle the tricky case, rather than guessing from the instruction alone.

How Many Examples Do You Need?

Usually somewhere between two and eight. Below two, you're not really demonstrating a pattern. Above roughly eight to ten, you start hitting diminishing returns and burning context window for marginal gains — and for most well-defined tasks, the model has already generalized the pattern by then.

Choosing the Right Examples

  • Cover the range of cases you'll actually see, including the tricky ones — not just clean, obvious examples
  • Keep the format of each example identical to what you want as output, since the model mimics structure as much as content
  • Order matters less than coverage, but placing a tricky example last sometimes helps it stick in the model's attention
  • Avoid examples that are themselves ambiguous or debatable — every example should clearly demonstrate the correct behavior

A Worked Example: Extracting Structured Data

Task: extract a customer's name, order number, and issue type from a support email into JSON. A zero-shot prompt describing the JSON schema often produces inconsistent field names or misses edge cases like emails referencing multiple orders. Adding three few-shot examples — including one email with no order number mentioned, and one with two order numbers — teaches the model exactly how to handle those specific edge cases, which a schema description alone rarely conveys.

Few-Shot vs. Fine-Tuning

Few-shot prompting is the right starting point for almost every task because it requires no training infrastructure and can be updated instantly. Fine-tuning becomes worth considering only when you have a large, stable dataset of examples and need to reduce per-request token costs (since few-shot examples consume tokens on every call) or need behavior that few-shot prompting genuinely can't achieve.

Common Mistakes

  • Using examples that don't match the real distribution of inputs you'll see in production
  • Forgetting to update examples when the task requirements change, leaving stale patterns in the prompt
  • Over-stuffing the prompt with examples instead of fixing an unclear instruction first

The Practical Takeaway

Before reaching for a more complex technique, ask whether a well-chosen handful of examples would teach the model what you're struggling to describe in words. Few-shot prompting is often the single highest-leverage change you can make to a struggling prompt.

Mujtaba Farooq

Mujtaba

Senior Full-Stack Software Engineer with 7+ years of experience building scalable FinTech and SaaS platforms.

Prompt EngineeringLLM