Few-Shot Prompting
Few-shot prompting means giving the model a few examples of the task before asking it to perform. The examples teach the model the pattern, format, and style you want.
Prompt
Convert these product descriptions to short taglines.
Description: "A lightweight laptop with a 15-hour battery
and a stunning 4K display, perfect for professionals."
Tagline: "Power meets portability. All day, all yours."
Description: "Noise-canceling headphones with 40mm
drivers, 30-hour battery life, and premium comfort."
Tagline: "Silence the world. Hear what matters."
Description: "A smart water bottle that tracks your
hydration and glows to remind you to drink."
Tagline:
The model follows the pattern established by the examples — matching the length, tone, and style.
Response
"Stay bright. Stay hydrated."
Few-shot works great for classification too. Here we teach the model our custom labeling scheme with examples.
Prompt
Label each message with a department.
Message: "I can't log into my account"
Department: Account Support
Message: "Do you offer bulk pricing?"
Department: Sales
Message: "The app crashes when I upload photos"
Department: Technical Support
Message: "I'd like to cancel my subscription"
Department:
The model infers the department from the pattern of examples, correctly routing the request.
Response
Account Support
How many examples? Generally 2–5 examples are enough. More examples help when the task is unusual or when output format matters a lot.
When to use few-shot:
- Custom output formats the model wouldn't guess
- Domain-specific terminology or labels
- Tasks where zero-shot gives inconsistent results
- When you need a very specific style or tone
When zero-shot is fine:
- Common tasks (summarization, translation)
- When you can describe the task clearly in words
Key takeaway: Examples are the most powerful way to steer an LLM. When words alone don't convey what you want, show the model with 2–5 examples.
Tips:
- Keep examples representative and diverse
- Use the same format for all examples
- Put the hardest/edge cases in your examples
- The last example (without answer) is the actual task