Lesson 17: Zero-Shot, Few-Shot & Chain-of-Thought
The three core techniques every prompt engineer reaches for — and when to use each one.
The Core Technique Trio
Master these three and you can handle most prompting scenarios. They are ordered by increasing structure — add structure only when the task needs it.
1. Zero-Shot (No Examples)
Give the model a task with no examples; rely on its pre-trained knowledge.
Classify this review as positive, negative, or neutral:
"The product arrived on time and works as expected."
- Use when: simple tasks, quick drafts, anything with an obvious right answer.
- Cost: cheapest, fastest.
- Risk: inconsistent for nuanced or format-sensitive tasks.
2. Few-Shot (Show, Don't Tell)
Provide 3–5 examples of the exact input → output pattern before the real task.
Classify these reviews:
Review: "Amazing quality!" -> Positive
Review: "Broke after a day." -> Negative
Review: "It's okay, nothing special." -> Neutral
Review: "The customer service was fantastic!" ->
- Use when: specific formats, style imitation, tricky classifications.
- Make examples diverse — they should cover the pattern's range, not be clones.
- 3–5 examples is the sweet spot; more rarely helps, fewer can under-teach.
3. Chain-of-Thought (Think Step by Step)
Ask the model to reason out loud before answering.
Solve step by step:
A store sells shirts for $25. A 20% discount applies when you
buy 3 or more. How much do 5 shirts cost? Show your reasoning.
- Use when: math, logic, multi-step decisions, anything where the answer path matters.
- CoT dramatically improves accuracy on reasoning tasks — and lets you read the reasoning to spot errors.
- Few-shot + CoT (show a reasoning example, then ask) is even stronger.
Choosing the Right Technique
| Task | Technique |
|---|---|
| Simple classification | Zero-shot |
| Strict output format | Few-shot |
| Math / logic | Chain-of-thought |
| Style imitation | Few-shot with style examples |
| Critical reasoning | Few-shot + CoT |
| Creative brainstorm | Zero-shot + high temperature |
Common Mistakes
- Mistake: using few-shot where zero-shot suffices → wasted tokens.
- Mistake: examples too similar → model learns a narrow pattern.
- Mistake: asking for "step by step" but not actually checking the steps.
- Mistake: one attempt, then giving up — iterate instead.
Key Takeaways
- Zero-shot = task only; few-shot = task + examples; CoT = task + reasoning.
- Start zero-shot, add examples only when output isn't good enough.
- Few-shot needs 3–5 diverse examples; CoT shines on reasoning tasks.
- Combine techniques: few-shot + CoT is the power move.
Next up: Advanced patterns — structured outputs, templates, and agentic prompting.
# Few-shot and chain-of-thought prompts, built in code
examples = [
("meeting pushed to 3pm", "The meeting has been rescheduled to 3 PM."),
("need the report asap", "Please share the report at your earliest convenience."),
("can't make the call", "I am unable to attend the call."),
]
few_shot = "Rewrite each informal message in professional business English:\n\n"
for informal, formal in examples:
few_shot += f'Informal: "{informal}"\nFormal: "{formal}"\n\n'
few_shot += 'Informal: "gonna be late tomorrow"\nFormal: '
chain_of_thought = (
"Question: A store sells shirts for $25. A 20% discount applies when "
"you buy 3 or more. How much do 5 shirts cost?\n"
"Answer step by step:\n"
)
print("=== FEW-SHOT PROMPT ===\n")
print(few_shot)
print("\n=== CHAIN-OF-THOUGHT PROMPT ===\n")
print(chain_of_thought)Lesson Code (Python)
# Few-shot and chain-of-thought prompts, built in code
examples = [
("meeting pushed to 3pm", "The meeting has been rescheduled to 3 PM."),
("need the report asap", "Please share the report at your earliest convenience."),
("can't make the call", "I am unable to attend the call."),
]
few_shot = "Rewrite each informal message in professional business English:\n\n"
for informal, formal in examples:
few_shot += f'Informal: "{informal}"\nFormal: "{formal}"\n\n'
few_shot += 'Informal: "gonna be late tomorrow"\nFormal: '
chain_of_thought = (
"Question: A store sells shirts for $25. A 20% discount applies when "
"you buy 3 or more. How much do 5 shirts cost?\n"
"Answer step by step:\n"
)
print("=== FEW-SHOT PROMPT ===\n")
print(few_shot)
print("\n=== CHAIN-OF-THOUGHT PROMPT ===\n")
print(chain_of_thought)Console Output
=== FEW-SHOT PROMPT ===
Rewrite each informal message in professional business English:
Informal: "meeting pushed to 3pm"
Formal: "The meeting has been rescheduled to 3 PM."
Informal: "need the report asap"
Formal: "Please share the report at your earliest convenience."
Informal: "can't make the call"
Formal: "I am unable to attend the call."
Informal: "gonna be late tomorrow"
Formal:
=== CHAIN-OF-THOUGHT PROMPT ===
Question: A store sells shirts for $25. A 20% discount applies when you buy 3 or more. How much do 5 shirts cost?
Answer step by step:
Code Visualization Tips
- Draw the three techniques as an escalation ladder: Zero-shot → Few-shot → CoT.
- Annotate a few-shot prompt, coloring examples vs. the real task so the pattern is visible.
- Trace a CoT answer step by step with arrows, checking each reasoning stage.
Professional Tips & Tricks
- Prefix CoT with 'Let me think through this step by step' — reliably boosts reasoning.
- Use delimiters (--- or |||) between few-shot examples and the real task.
- For strict formats, few-shot beats any amount of prose instructions.
Python Code Judge & Practice Arena
LeetCode StyleRun real Python 3.12 WebAssembly code directly in your browser against automated test suites.
Combine Few-Shot + CoT
Up next · Continue learning
Structured Outputs & Reusable Templates
Force consistent, machine-readable outputs with JSON, tables, and XML tags — and stop rewriting prompts from scratch.