ASAmol Shukla
Projects
Courses
Prompts
Skills
Contact
Resume
Course Outline
Syllabus Overview

AI Tools: LLM & Prompt Engineering Mastery

Courses/AI Tools: LLM & Prompt Engineering Mastery/Lesson 17: Zero-Shot, Few-Shot & Chain-of-Thought
50 mins lesson duration•10 mins read

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.

Interactive Lesson Code Snippet
# 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)
Language: python

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 Style

Run real Python 3.12 WebAssembly code directly in your browser against automated test suites.

Solved:0 / 1
0 / 20 XP
Challenges:
Problem 1 of 1

Combine Few-Shot + CoT

Medium+20 XP
Build a few-shot + chain-of-thought prompt that classifies customer sentiment AND explains the reasoning, using 2 diverse examples.
main.pyPython 3.12 (WASM)
1
2
3
4
5
6
7
8
9
10
11
12
Press Run Code to test or Submit to verify test cases

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.

10 mins read50 mins
Start next lesson
Previous: The Anatomy of an Effective PromptNext: Structured Outputs & Reusable Templates
Made withbyAmol Shukla·amolshukla.online
ASAmol Shukla

AI Developer, Trainer & Agentic AI Expert building practical learning systems and real-world AI applications.

Explore

  • Projects
  • Courses
  • Prompts
  • Skills
  • Contact
  • Experience
  • Blogs

Connect

  • Resume
  • Contact
© 2026 Amol Shukla·Created withbyamolshukla.online
Back to top