Deep Dives10 min read25 May 2026
Zero-Shot, Few-Shot, and Chain-of-Thought: The Three Fundamental Prompting Strategies
Three techniques that unlock dramatically better AI outputs. Learn what they are, when to use each, and how to combine them for maximum effect.
Diversity in your few-shot examples matters more than quantity. Three examples covering three different edge cases outperform five examples that are all similar. Include examples that cover the hardest cases — that is where your few-shot examples have the most impact.
python
import anthropic
client = anthropic.Anthropic()
def build_few_shot_cot_prompt(
task_description: str,
examples: list[dict], # each dict: {"input": str, "reasoning": str, "output": str}
query: str
) -> str:
"""
Builds a few-shot chain-of-thought prompt dynamically.
examples: list of {"input": ..., "reasoning": ..., "output": ...}
"""
prompt_parts = [task_description, ""]
for i, ex in enumerate(examples, 1):
prompt_parts.append(f"Example {i}:")
prompt_parts.append(f"Input: {ex['input']}")
prompt_parts.append(f"Reasoning: {ex['reasoning']}")
prompt_parts.append(f"Output: {ex['output']}")
prompt_parts.append("")
prompt_parts.append("Now process this input:")
prompt_parts.append(f"Input: {query}")
prompt_parts.append("Reasoning:") # model continues from here
return "\n".join(prompt_parts)
# ── Example: customer priority classification ─────────────────────────────────
task = "Classify customer support messages as Urgent, Normal, or Low priority. Show reasoning first."
examples = [
{
"input": "The payment gateway is throwing 500 errors and we can't process any orders",
"reasoning": "Core business function (payments) is completely broken. Revenue impact is immediate. No workaround exists.",
"output": "Urgent"
},
{
"input": "How do I export my data to CSV?",
"reasoning": "Feature/how-to question with no urgency signal. Can be answered asynchronously.",
"output": "Low"
},
{
"input": "Our trial ends in 2 days and I need a quick decision from my manager — can we extend it?",
"reasoning": "Time-sensitive (2 days) but not blocking current work. Sales/retention concern, not technical.",
"output": "Normal"
},
]
query = "We're giving a product demo in 45 minutes and the dashboard isn't loading for our client"
prompt = build_few_shot_cot_prompt(task, examples, query)
response = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=500,
temperature=0, # deterministic for classification tasks
messages=[{"role": "user", "content": prompt}]
)
print(response.content[0].text)
# Expected output:
# Reasoning: Hard deadline (45 min) with client-facing consequences.
# Technical issue (dashboard not loading) during a high-stakes sales situation.
# Reputational and sales risk if not resolved immediately.
# Output: UrgentStore your few-shot examples in a config file or database, not hardcoded in your prompts. This lets you update examples without code changes, A/B test different example sets, and track which examples produce the best results. Treat your examples as data, not code.
promptingchain-of-thoughtfew-shotdeep diveszero-shot
🎓Interactive Courses
Ready to go further?
Take the interactive course — daily lessons, real exercises, XP and streaks. Turn reading into lasting skills.
Daily streaksXP & levels
