Few-Shot Prompting Best Practices

Estimated time: 20 minutes

Few-shot prompting is the most reliable way to communicate edge cases and consistent output formats. This lesson covers when to use few-shot, how many examples to provide, and what makes an example effective.

When Few-Shot Prompting Earns Its Tokens

  • Ambiguous scenarios. When tool selection or category choice has multiple plausible answers, examples disambiguate.
  • Consistent output format. When you need the same structure across many calls — examples lock in the format better than schema descriptions alone.
  • Reducing false positives. Show two examples of false-positive cases that should NOT trigger; the model learns the boundary.
  • Varied document structures. When inputs come in inline citation format, bibliography format, and footnote format, show one example of each.

How Many Examples?

Two to four targeted examples is the sweet spot for most tasks. Fewer than two doesn't disambiguate. More than four is mostly noise — the model has learned the pattern by example #4. Past that, you're paying tokens for diminishing returns.

Show Reasoning, Not Just Answers

An example that just shows input → output gives the model the correlation but not the reasoning. An example that shows input → reasoning → output gives the model the full thought process to imitate. The reasoning makes the example portable to inputs that don't exactly match.

Input: "I want a refund for order #1234."
Reasoning: This is a clear refund request with an order ID. The
  customer hasn't asked for a human and the request is in scope.
  Use process_refund after verifying the customer.
Output: { tool: "get_customer", … then process_refund }

Input: "Can someone help me with my order?"
Reasoning: This is a vague help request. No specific action stated.
  Don't escalate yet — ask a clarifying question first.
Output: "Can you tell me what specifically you need help with?"

Include Edge Cases, Not Just Happy Path

Three happy-path examples teach the model the obvious case. The model already knew the obvious case. Use examples to teach the non-obvious cases: customer asks for human directly, ambiguous order ID, multiple matching customers, refund over policy limit.

Demonstrate Varied Input Formats

If you're extracting citations and inputs come in three formats — inline (Smith, 2020), footnote (¹), and bibliography list — show one example of each. The model learns to recognize all three and produce a consistent output format.

Few-Shot Position in the Prompt

Examples typically go after instructions and before the actual input. The structure: instructions explaining the task, 2-4 examples demonstrating the task, then the live input. This order lets the model build its model of the task before seeing the input it must process.

When NOT to Use Few-Shot

  • The task is simple and well-described — examples are wasted tokens.
  • The output is highly variable and examples would constrain it incorrectly.
  • You can use a tool schema instead — schemas with descriptions are more reliable than examples for structured output.

Skills to Develop

  1. Use 2-4 targeted examples for ambiguous scenarios.
  2. Show reasoning, not just input/output pairs.
  3. Include edge cases that demonstrate the boundaries of correct behavior.
  4. Demonstrate varied input formats when input is heterogeneous.
Exam tip: When false positives are a problem, few-shot examples that demonstrate cases that should NOT trigger are highly effective. They show the model where the boundary is.