Zero-shot, Few-shot and Chain-of-Thought
Three core prompting techniques: ask directly, show examples, or ask the model to reason step-by-step before answering.
Zero-shot, Few-shot and Chain-of-Thought is a free AI Agents lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AI Agents learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Three Foundational Techniques
Three prompting techniques every agent engineer must know:
- Zero-shot — ask directly, no examples
- Few-shot — show 1-5 examples of the desired behavior
- Chain-of-thought (CoT) — make the model reason step by step before answering
Zero-shot Example
Zero-shot is the default: just ask.
prompt = 'Translate to French: Hello, how are you?'
# Model output: 'Bonjour, comment allez-vous?'
model_output = 'Bonjour, comment allez-vous?'
print("Prompt:", prompt)
print("Model output:", model_output)
When Zero-shot Fails
Zero-shot fails when:
- The task format is unusual (custom JSON, weird tags)
- The domain is narrow (your company's lingo)
- The instruction is ambiguous
In those cases, examples help dramatically.
Few-shot Example
Show the model what you want with 2-3 examples:
prompt = '''
Classify sentiment as POSITIVE, NEGATIVE, or NEUTRAL.
Text: I loved this movie!
Sentiment: POSITIVE
Text: The plot dragged on forever.
Sentiment: NEGATIVE
Text: It was okay, nothing special.
Sentiment: NEUTRAL
Text: The acting saved an otherwise weak script.
Sentiment:
'''
print(prompt.strip())
How Many Shots?
Empirically:
- 1-2 examples is usually enough for format
- 3-5 helps for nuance
- 10+ rarely helps and burns tokens
Quality of examples > quantity.
Cover Edge Cases
Your examples should cover the corner cases that confuse the model. Include:
- The common case
- One tricky case
- One example of what NOT to do
Chain-of-Thought (CoT)
Ask the model to think before answering. Magic phrase: "Let's think step by step."
prompt = '''
Q: Roger has 5 tennis balls. He buys 2 cans, each with 3 balls. How many balls does he have?
A: Let\'s think step by step.
Roger starts with 5 balls.
2 cans * 3 balls = 6 new balls.
5 + 6 = 11.
The answer is 11.
'''
print(prompt.strip())
Why CoT Helps
For multi-step problems, CoT lets the model "use" extra tokens to compute intermediate results. Without CoT, the model has to compute the answer in a single forward pass.
Especially powerful for math, logic, and code.
CoT in Modern Models
Models like o1 and o3 do CoT internally — they "think" before producing the visible answer. For these models, asking for CoT in the prompt is unnecessary and can even hurt.
Self-Consistency
Run CoT multiple times with temperature > 0 and take the most common answer. This majority vote often beats single-sample CoT, especially on hard math.
Combining Techniques
You can mix all three. A typical agent prompt has:
- A system prompt explaining the task (zero-shot)
- 2-3 few-shot examples
- An instruction to think step by step
Pick the Technique
You are getting incorrect arithmetic in agent outputs. Which technique helps most?
Recap
Three core techniques: zero-shot, few-shot, CoT. Pick based on the task; combine when needed.
Frequently asked questions
Is the “Zero-shot, Few-shot and Chain-of-Thought” lesson free?
Yes — the full text of “Zero-shot, Few-shot and Chain-of-Thought” is free to read here on the web, and the AI Agents course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AI Agents course, upgrade to CoddyKit PRO.
What will I learn in “Zero-shot, Few-shot and Chain-of-Thought”?
Three core prompting techniques: ask directly, show examples, or ask the model to reason step-by-step before answering. You practise AI Agents with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AI Agents?
No prior experience is required. AI Agents on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Zero-shot, Few-shot and Chain-of-Thought” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AI Agents lesson?
Yes. Every AI Agents lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Zero-shot, Few-shot and Chain-of-Thought
- System vs User vs Assistant Roles
- Output Formatting (JSON, XML, Markdown)
- Avoiding Prompt Injection in Inputs