What is zero-shot, one-shot, and few-shot prompting?

These terms describe how many examples you include in your prompt - zero examples, one example, or a few (2–10). More examples help the model match the pattern you want.

AILLMPrompt Engineering

Overview

Large language models can perform tasks they were never explicitly trained on, simply by being shown examples in the prompt. "Shot" refers to the number of (input, output) examples you include. Zero-shot asks the model to do something with only instructions. One-shot gives a single example. Few-shot gives 2–10 examples. This technique lets you guide output format, tone, and reasoning style without any model training.

Key Points

  • β€’**Zero-shot**: instructions only, no examples. Works well for simple tasks and powerful models.
  • β€’**One-shot**: one example. Sufficient for format-sensitive tasks (output a specific JSON shape).
  • β€’**Few-shot**: 2–10 examples. Dramatically improves consistency for classification, extraction, and custom formats.
  • β€’The quality of examples matters more than the quantity. 3 excellent examples beat 20 mediocre ones.
  • β€’Order matters slightly - the model tends to follow the pattern of the last example most closely.
  • β€’Few-shot prompting is cheaper and faster to iterate than fine-tuning, and can match fine-tuned quality for most tasks.

Examples

Zero-shot: instructions only

typescript
// Zero-shot - just describe the task
const response = await client.chat.completions.create({
  model: 'gpt-4o',
  messages: [{
    role: 'user',
    content: `Classify the following customer message as: billing, technical, or general.
Message: "I was charged twice this month."
Category:`,
  }],
});
// β†’ "billing"

Few-shot: show examples to establish the pattern

typescript
// Few-shot - model learns format and decision logic from examples
const prompt = `Classify customer messages. Output ONLY the category: billing | technical | general

Message: "My payment didn't go through."
Category: billing

Message: "The app crashes when I open settings."
Category: technical

Message: "What are your business hours?"
Category: general

Message: "I was charged twice this month."
Category:`;

const response = await client.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: prompt }],
  max_tokens: 5,      // we only need a single word
  temperature: 0,
});
// β†’ "billing"

Few-shot for structured data extraction

typescript
const extractionPrompt = `Extract name, company, and role from the bio. Output JSON only.

Bio: "Sarah Chen is VP of Engineering at Stripe where she leads the payments platform team."
Output: {"name": "Sarah Chen", "company": "Stripe", "role": "VP of Engineering"}

Bio: "Retired NASA astronaut Mark Kelly served as Commander of the ISS."
Output: {"name": "Mark Kelly", "company": "NASA", "role": "Commander"}

Bio: "${userBio}"
Output:`;

// With 2 examples, the model reliably outputs parseable JSON
// without needing response_format: json_object

Chain-of-thought few-shot: teach reasoning

typescript
const mathPrompt = `Solve each problem step by step.

Problem: A store sells apples for $0.50 each. If I buy 7 apples and pay with a $5 bill, how much change do I get?
Reasoning: 7 apples Γ— $0.50 = $3.50. Change = $5.00 βˆ’ $3.50 = $1.50.
Answer: $1.50

Problem: A recipe needs 3 eggs per batch. If I want to make 4 batches, how many eggs do I need?
Reasoning: 4 batches Γ— 3 eggs = 12 eggs.
Answer: 12

Problem: ${userMathQuestion}
Reasoning:`;

// The model mimics the step-by-step format, improving accuracy

Pro Tip

When building few-shot prompts, use real examples that cover edge cases - not just the happy path. Include one example of a "tricky" case (e.g. an ambiguous message that you want classified as "general") so the model learns your decision boundary. For highest accuracy, curate examples from actual inputs your system has received.