Beginner Technique

Few-Shot Prompting

Guide AI behavior by providing examples of the desired input-output pairs

What is Few-Shot Prompting?

Few-shot prompting involves providing the AI with one or more examples of the desired input-output pairs before presenting the actual task. This helps the model understand your expected format, style, or logic.

It's like showing someone a few samples of what you want before asking them to do the task themselves.

Types of Few-Shot

One-Shot

Single example to demonstrate the pattern

Few-Shot

2-5 examples for more complex patterns

Multi-Shot

Many examples for complex tasks

Examples

Example: Sentiment Classification
Prompt with Examples
Classify the sentiment as positive, negative, or neutral. Example 1: "I love this product!" → positive Example 2: "This was a waste of money." → negative Example 3: "The package arrived on time." → neutral Now classify: "The battery life could be better."
Output
negative
Example: Format Conversion
Prompt with Examples
Convert the following to JSON format: Input: John is 30 years old and works as a developer. Output: {"name": "John", "age": 30, "job": "developer"} Input: Sarah is a designer who is 28 years old. Output:
Output
{"name": "Sarah", "age": 28, "job": "designer"}

Best Practices

  • 01
    Use 2-5 examples

    More isn't always better. 2-5 well-chosen examples usually work best.

  • 02
    Show diverse examples

    Include edge cases and variations to help the model understand the full pattern.

  • 03
    Be consistent in format

    Keep your example structure clear and consistent.

  • 04
    Label clearly

    Use "Example 1:", "Input:", "Output:" labels to make it clear what you're showing.

When to Use Few-Shot

  • When you need specific output format
  • For consistent styling across outputs
  • When zero-shot doesn't work well
  • For complex classification tasks
  • To match your coding style
  • For domain-specific tasks