Skip to content
NeuralSkills
Prompting

Few-Shot Examples

Use examples to guide AI output format and quality by showing it exactly what you expect.

Beginner Free Published: April 15, 2026
Compatible Tools claude-codechatgptgeminicopilotcursorwindsurfuniversal

The Problem

When you give AI a task without showing what the output should look like, you get inconsistent results. The model guesses at format, tone, and level of detail, which means you spend more time editing than if you had been specific upfront. Few-shot examples solve this by anchoring the model to your exact expectations.

The Prompt

I will show you examples of the format I want, then give you a new task to complete in the same format.

EXAMPLE 1:
Input: [example input 1]
Output: [example output 1 in your desired format]

EXAMPLE 2:
Input: [example input 2]
Output: [example output 2 in your desired format]

EXAMPLE 3:
Input: [example input 3]
Output: [example output 3 in your desired format]

NOW YOUR TASK:
Input: [your actual input]
Output:

Example Output

EXAMPLE 1:
Input: Python function that reverses a string
Output: def reverse_string(s: str) -> str:
    """Reverse the input string."""
    return s[::-1]

EXAMPLE 2:
Input: Python function that checks if a number is prime
Output: def is_prime(n: int) -> bool:
    """Return True if n is a prime number."""
    if n < 2:
        return False
    return all(n % i != 0 for i in range(2, int(n**0.5) + 1))

NOW YOUR TASK:
Input: Python function that flattens a nested list
Output: def flatten(lst: list) -> list:
    """Flatten a nested list into a single list."""
    return [item for sub in lst for item in (flatten(sub) if isinstance(sub, list) else [sub])]

When to Use

Use few-shot examples whenever you need consistent formatting across multiple outputs — generating code in a specific style, writing product descriptions with a fixed structure, or classifying data into predefined categories. The more examples you provide, the more reliably the model matches your pattern.

Pro Tips

  • Three examples is the sweet spot — fewer may not establish the pattern; more wastes context window space.
  • Include edge cases — if your task has tricky variations, make one example cover the edge case so the model knows how to handle it.
  • Keep examples diverse — use different content in each example but identical structure to teach format without overfitting to specific content.
  • Order matters — put your best, most representative example last, closest to the actual task.