Choose between asking the model directly (zero-shot) or showing it a few examples first (few-shot). Often the difference between brittle and robust answers.
Telling someone to paint this (zero-shot) vs showing them three paintings in the style you want first (few-shot).
zero-shot:
classify sentiment: 'I love it!' ->
few-shot:
'I love it.' -> Positive
'I hate it.' -> Negative
'Not sure.' -> Neutral
'Pretty good.' ->
Zero-shot is the simplest prompt: task plus instruction. Few-shot adds complete input/output pairs as in-context examples that dramatically reduce ambiguity. The downside: examples consume tokens and can be over-fit if too narrow. Start zero-shot; escalate to few-shot when outputs are inconsistent or format is wrong.
import openai
resp = openai.chat.completions.create(
model='gpt-4o-mini',
messages=[{'role':'user','content':"Classify sentiment of: 'I love it!'. Reply Positive or Negative only."}])
print(resp.choices[0].message.content)
Zero-shot is the minimal viable prompt — useful for quick probes.
few_shot = [
{'role':'user','content':"'I love it.' Sentiment:"},
{'role':'assistant','content':'Positive'},
{'role':'user','content':"'I hate this.' Sentiment:"},
{'role':'assistant','content':'Negative'},
{'role':'user','content':"'I love it!' Sentiment:"},
]
resp = openai.chat.completions.create(model='gpt-4o-mini', messages=few_shot)
print(resp.choices[0].message.content)
Few-shot examples lock the format and reduce variance.
resp = openai.chat.completions.create(
model='gpt-4o-mini',
messages=[
{'role':'system','content':'Reply with exactly one of Positive, Negative, Neutral.'},
{'role':'user','content':"Examples:\n'good' -> Positive\n'bad' -> Negative\n'okay' -> Neutral\nNow classify: 'I love it!'"},
])
print(resp.choices[0].message.content)
Mixing a zero-shot system prompt with a few-shot user prompt gives instructions AND examples.
Using 30 examples when 3 would suffice. Examples steal tokens and risk teaching the model to imitate noise.
Start zero-shot. Escalate to few-shot when outputs vary in format or quality. Use 3-5 canonical examples; move to fine-tuning if you need 50+.