📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Prompt Engineering Few-Shot Prompting

Few-Shot Prompting

5 min read Quiz at the end
Few-shot examples teach the LLM your exact desired format and pattern — 2-5 examples is the sweet spot.

Few-Shot Prompting

Provide 2-5 input-output examples to teach the model your exact desired pattern and format.

# Few-shot classification
Classify each tweet as Spam or Ham.

Tweet: 'Win a FREE iPhone! Click now!'
Label: Spam

Tweet: 'Can we reschedule our meeting to 3pm?'
Label: Ham

Tweet: 'URGENT: Your account has been compromised!'
Label: Spam

Tweet: 'Great presentation today, really enjoyed it.'
Label: Ham

Tweet: 'Congratulations! You have been selected for a prize.'
Label:

# Few-shot extraction
Extract name and role.

Sentence: 'Alice Smith leads the backend team.'
Name: Alice Smith | Role: Backend Team Lead

Sentence: 'Bob joined as a senior data scientist.'
Name:
Topic Quiz · 2 questions

Test your understanding before moving on

1. How many examples is optimal for few-shot prompting?
💡 2-5 examples is the sweet spot — enough to teach the pattern without wasting context tokens.
2. Why does example ORDER matter in few-shot prompting?
💡 The most recent examples have the strongest influence — put the most representative example last.