AIMay 27, 2026

Prompting Techniques: A Guide to Zero-Shot, Few-Shot & Chain-of-Thought

Learn all types of prompting techniques with our complete guide covering zero-shot prompting, few-shot prompting, chain-of-thought prompting, role prompting, and prompt engineering strategies with real examples.

Prompting Techniques: A Guide to Zero-Shot, Few-Shot & Chain-of-Thought

Types of Prompting: Actually Getting Good Answers from AI

Why This Matters

I spent probably two weeks blaming Claude for being useless. Turns out Claude wasn't the problem—I just had no idea how to ask it anything. My friend took one look at a prompt I'd written and started laughing. Not mean laughing. That "oh you sweet summer child" kind of laughing.

So we rewrote it. Same AI. The results were night and day.

That's when I realized prompting isn't some mystical thing. It's just asking better questions. Different ways of asking work for different jobs. Some are stupid fast but kind of garbage. Others take more tokens but deliver accuracy you can actually trust. Some make the AI think things through instead of just guessing.

This is what I've learned actually matters, from real stuff I've tried. Not textbook bullshit.

What Is Prompting Anyway

Basically? It's how you ask AI to do something. But doing it well.

Imagine asking someone to make you food versus "hey can you make that pasta carbonara with the crispy guanciale like you did last month." One gets you whatever's in the fridge. The other gets you exactly what you want. Same person. Different ask.


Zero-Shot: Just Ask. No Examples. No Safety Net.

This is probably what most people do without thinking about it.

With zero-shot prompting, you don't show examples. You don't give a template. You just ask and see what you get.

How This Even Works

These models have seen mountains of text. Enough that when you ask something it never explicitly trained on, it can still make a decent guess. It learned patterns. So it pattern-matches your question to stuff it knows.

Like if I asked you to write a haiku about your morning commute, you've probably never done that exact thing. But you know what haikus look like. You know your commute. You mash them together. That's zero-shot.

Here's what I mean:

text
Me: "Write a haiku about AI"

Claude:
Minds made of numbers
Learning patterns in the dark  
Future takes its shape

Never saw "write haikus specifically about AI." But it got both concepts and merged them. That's actually wild when you think about it.

When You'd Actually Use This

Three translation requests. Sentiment checks. Summarizing some article. Quick stuff where if it's wrong, who cares.

Don't use it for:

  • Anything in production
  • Anything where accuracy matters
  • Anything you need to be consistent
  • Tasks that are annoying to redo

How to Get Better Results

Stop being vague with zero-shot prompting. Seriously.

text
Trash: "Write about AI"
Better: "Write a 300-word intro for business managers about how AI reduces customer support costs—use actual examples"

Add context. Be specific about what you want. Tell it what format to use.

text
Trash: "Classify: The product broke"
Better: "Is this review positive, negative, or neutral? 'Broke after one day. Very disappointed.'"

See the difference? One's lazy. One actually works.

Real Code

python
1import openai
2
3openai.api_key = "your-key"
4
5response = openai.ChatCompletion.create(
6    model="gpt-4",
7    messages=[{"role": "user", "content": "Translate to French: Hello"}]
8)
9
10print(response.choices[0].message.content)

Zero-Shot vs Few-Shot Prompting: Which One

Zero-shot is fast. But less accurate. Few-shot prompting takes more tokens but if you care about getting the right answer, it's worth it.

For one-off quick stuff? Zero-shot. For anything that repeats or matters? Few-shot prompting.


Few-Shot: Show It Examples and Watch It Learn

Zero-shot's fine for lazy tasks. Want actually good results? Show the AI examples first.

Few-shot prompting means giving it 2-5 examples of what you want, then asking it to do the same with new data.

Why This Works So Much Better

When you give examples, the AI learns the pattern right there in the prompt. Then applies it to your actual question. The accuracy jump is ridiculous. I've seen 70% accuracy go to 94% just by adding three examples. Same AI. Same task. Just showed it what "right" looks like.

Real Examples

Sentiment classification:

text
You: "Classify sentiment.

Review 1: 'Amazing product! Love it!'
Sentiment: positive

Review 2: 'Terrible quality, fell apart immediately'
Sentiment: negative

Review 3: 'It's okay, nothing special'
Sentiment: neutral

Now this one:
Review 4: 'Best purchase ever!'
Sentiment: ?"

AI: "positive"

It caught the pattern instantly. Learned the three categories from your examples and applied it.

Extract data:

text
Text: 'John works at Google in California'
Names: John | Places: Google, California

Text: 'Sarah lives in Paris, works at Microsoft'  
Names: Sarah | Places: Paris, Microsoft

Now this:
Text: 'Mike and Emily met in London'
Names: ? | Places: ?

AI gets it. Mike and Emily are names. London is a place.

Code with a specific style:

text
Example: def sum_even(arr):
    return sum(x for x in arr if x % 2 == 0)

Example: def count_items(arr):
    return len(arr)

Now: write multiply_odd(arr):

The AI copies the style from your examples.

How Many Examples You Need

2-3 for super simple stuff. 4-5 is the sweet spot. More than 5? You're wasting tokens and not actually helping. Quality over quantity. One great example beats five mediocre ones every time.

What Makes Good Examples

Diversity matters. If all your examples are positive reviews, don't expect it to handle negative reviews well.

Match your real data. Don't show simple stuff when your actual data is messy.

Format clearly. Don't dump text. Make it obvious what input is, what output should be.

Include edge cases. Sarcasm. Weird stuff. That's how it learns to handle it.

When This Actually Works

Production stuff where accuracy matters. Repeating tasks. You have examples lying around. Need consistent formats. That's when few-shot prompting pays off.

Skip it for: One-off stuff. Creative writing. Poetry. You don't need examples for that.

Code

python
1import anthropic
2
3client = anthropic.Anthropic(api_key="your-key")
4
5message = client.messages.create(
6    model="claude-3-5-sonnet-20241022",
7    max_tokens=1024,
8    messages=[
9        {
10            "role": "user",
11            "content": """Classify sentiment.
12
13Review: 'Love this!'
14Sentiment: positive
15
16Review: 'Terrible'
17Sentiment: negative
18
19Review: 'Okay'
20Sentiment: neutral
21
22Review: 'Best ever!'
23Sentiment: ?"""
24        }
25    ]
26)
27
28print(message.content[0].text)

The Bottom Line

Few-shot prompting is how production systems handle structured tasks. It works because the AI learns from your examples right there in the moment.


Chain-of-Thought: Make It Show Its Work

So far: ask without examples (zero-shot). Ask with examples (few-shot). What about when the task is actually hard?

Chain-of-thought prompting means telling the AI to think through something step by step instead of just vomiting out an answer.

Why This Matters

Ask an AI to think step by step? It actually reasons better. Sounds dumb. Is true.

You get better logic. Fewer mistakes. You can follow what it's doing. If something's wrong, you spot it. Way better than getting an answer with no explanation.

Examples

Math that's not obvious:

text
Bad: "Alice buys 3 books at $15 each and a pen for $5. Change from $100?"
AI guesses. Might be right. Might not.

Good: "Step by step:
Step 1: Books cost = 3 × $15 = ?
Step 2: Total cost = books + pen = ?
Step 3: Change = $100 - total = ?

Alice buys..."

AI actually works through it. Shows its math.

Analysis:

text
"Analyze this. Show your thinking:

Text: 'The startup failed because of poor management.'

- What's the main claim?
- What evidence supports it?
- What might be missing?
- What's the actual reason?"

The AI walks through each part instead of just saying "yeah management was bad."

Debugging code:

text
"Debug this step by step:

```python
def find_max(arr):
    max = arr[0]
    for i in range(len(arr)):
        if arr[i] > max:
            max = arr[i]
    return max

Step 1: What does this do? Step 2: What could break? Step 3: What's the bug?"

text

Instead of "your code's broken," you get an explanation.

### When to Actually Use This

Math problems. Logic stuff. Analysis. Debugging. Planning. Anywhere you want to see how it got there.

Don't use it for: Simple fact lookups. Creative brainstorming. Anything where "just give me the answer" works.

### Real Talk

Chain-of-thought prompting isn't magic. It just forces transparency. When you can see how the AI got to an answer, you can verify it. Catch the mistakes. That's why it works.

---

## Role Prompting / Persona Prompting: Tell It Who to Be

Another trick: assign the AI a role.

Role prompting (persona prompting) means saying "Act as a [role]" and then asking your question. The AI adopts that perspective and knowledge base.

### How This Works

The AI learned how different experts talk. Different professionals think. When you give it a role, it taps into those patterns. Suddenly the response sounds like someone who knows what they're doing instead of a generic AI voice.

### Examples

Compare these:

Bad: "What should I consider for a startup?" Gets generic generic advice.

Better: "You're a serial entrepreneur who's built 3 startups. What should I consider when launching?" Gets experienced, specific advice.

text

Different:

Bad: "Explain machine learning" Gets Wikipedia summary.

Better: "You're a professor explaining machine learning to undergrads. Explain it." Gets simpler, paced better.

text

Or:

Bad: "Write a funny tweet about coffee" Might be meh.

Better: "You're a standup comedian known for observational humor. Write a funny tweet about coffee." Actually lands.

text

### When to Use This

Need a specific tone or perspective. Want expert-level answers. Creative stuff. Explaining something to a specific audience.

Not useful for: Factual lookups where the source matters. Accuracy-critical stuff. The role doesn't make you smarter, just different.

### Real Talk

Persona prompting is basically roleplay for AI. Doesn't make it smarter. Makes it sound more appropriate.

---

## System Prompting: Set the Baseline Rules

System prompting is different. It's instructions at the system level, not in the chat. Applies to everything the user sends in that conversation.

Think of it like briefing someone before they start work. Regular prompts are individual requests. System prompting is the standing orders.

### Examples

Customer support bot:

"You are a helpful customer support specialist.

  • Be friendly and empathetic
  • Solve problems quickly
  • If unsure, escalate to supervisor
  • Never make promises you can't keep
  • Keep responses under 200 words"
text

Then every response the user gets follows those rules.

Code assistant:

"You are an expert Python developer.

  • Write clean, readable code
  • Follow PEP 8 standards
  • Include docstrings
  • Explain your reasoning
  • Suggest improvements"
text

Every code suggestion follows these guidelines.

Copywriter:

"You are a professional copywriter.

  • Use active voice
  • Keep sentences short
  • Write for general audience
  • Be persuasive but honest
  • Use storytelling when relevant"
text

Every piece of copy hits those marks.

### Code

```python
import anthropic

client = anthropic.Anthropic(api_key="your-key")

message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    system="You are a helpful Python expert. Explain things clearly.",
    messages=[
        {
            "role": "user",
            "content": "Explain decorators in Python"
        }
    ]
)

print(message.content[0].text)

When You Need This

Multi-turn conversations where consistency matters. Production applications. Setting personality and constraints that apply across the whole thing.

Not needed for: One-off questions. Quick stuff. Something that needs to pivot.

Real Talk

System prompting is how you build professional applications. Sets the tone and boundaries.


JSON Prompting: Get Data You Can Actually Use

Want the AI to return data your code can parse? JSON prompting.

Otherwise known as structured output. You tell the AI "return only JSON" with a specific structure, and it does.

Why This Matters

Unstructured text is fine for reading. But if you're automating, you need data. JSON gives you structured output your code can actually use.

Examples

Extract customer info:

text
Bad: "Extract customer info from this email"
You get messy prose.

Good: "Extract customer info. Return only JSON:
{
  'name': '',
  'email': '',
  'issue': '',
  'priority': 'low|medium|high'
}"
You get parseable JSON.

Multiple items:

text
"List top 3 AI trends. Return only JSON:
[
  {'trend': '', 'impact': '', 'timeline': ''},
  ...
]"

You get a clean array.

Complex structure:

text
"Analyze code feedback. Return JSON:
{
  'severity': 'low|medium|high',
  'category': 'performance|security|style',
  'description': '',
  'fix': ''
}"

Structured, parseable, usable in code.

Code

python
1import anthropic
2import json
3
4client = anthropic.Anthropic(api_key="your-key")
5
6message = client.messages.create(
7    model="claude-3-5-sonnet-20241022",
8    max_tokens=1024,
9    messages=[
10        {
11            "role": "user",
12            "content": """Extract info as JSON only:
13{
14  'name': '',
15  'email': '',
16  'phone': ''
17}
18
19Email: Contact john@example.com, name is John Smith, 555-1234"""
20        }
21    ]
22)
23
24data = json.loads(message.content[0].text)
25print(data['name'])

When This Makes Sense

Building automated systems. Integrating with tools. Processing lots of items. When your code needs to parse the response, not read it.

Skip it for: Human-facing output. One-off answers.

Real Talk

JSON prompting connects AI to real systems. Essential for automation.


Context Prompting: Give It Source Material

Want accurate answers? Give the AI actual sources to reference.

Context prompting means pasting in documents and saying "answer based on this."

Why It Works

AI hallucinates. Makes stuff up. But give it a specific source? It mostly sticks to what's there. Accuracy jumps dramatically.

Examples

Answer based on a document:

text
"Based on this document, what's our pricing strategy?

[paste doc]

Answer:"

The AI uses the doc instead of guessing.

Compare information:

text
"According to this article, is Tesla's new feature innovative?

[paste article]

Answer yes/no and quote the part that supports it."

You get an answer backed by the source.

Extract facts:

text
"From this earnings report, what was Q3 revenue?

[paste report]

Return as JSON: {'quarter': 'Q3', 'revenue': ''}"

Actual number from the document. Not made up.

Code

python
1import anthropic
2
3client = anthropic.Anthropic(api_key="your-key")
4
5article = """
6Apple released the iPhone 15 on September 22, 2024.
7Key features: improved camera, faster processor, longer battery.
8Starting price: $799
9"""
10
11message = client.messages.create(
12    model="claude-3-5-sonnet-20241022",
13    max_tokens=1024,
14    messages=[
15        {
16            "role": "user",
17            "content": f"""Based on this article:
18
19{article}
20
21What's the iPhone 15 price and 2 key features?"""
22        }
23    ]
24)
25
26print(message.content[0].text)

When You Need This

Accuracy critical tasks. Working with real documents. Can't afford hallucinations. Want answers backed by something.

Not needed for: General knowledge questions. Quick stuff.

Real Talk

Context = accuracy. Always provide sources when it matters.


How to Write Effective Prompts

Stop doing the same garbage and wondering why it doesn't work.

Rule 1: Stop Being Vague

text
Lazy: "Write about AI"
Actually good: "Write a 300-word blog intro for business managers explaining how AI reduces support costs—use real examples"

Rule 2: Add Context

text
Vague: "Classify: The product broke"
Clear: "Is this positive, negative, or neutral? 'Broke after one day. Very disappointed.'"

Rule 3: State What You Want

text
Unclear: "The new iPhone features..."
Clear: "List top 5 iPhone 15 features as bullet points"

That's it. Those three things. Write effective prompts and you're halfway there.


Combining Techniques: When It Gets Powerful

Single techniques work fine. Stack them and things get interesting.

Few-shot + role:

text
"You're a fashion expert.

Classify style:

Item: 'Oversized blazer, minimal jewelry'
Style: minimalist

Item: 'Bright colors, bold patterns'
Style: maximalist

Item: 'Neutral colors, classic cuts'
Style: ?"

Role expertise meets pattern learning.

Chain-of-thought + few-shot:

text
"Solve step by step:

Problem: Alice buys 3 books at $15 each, 10% discount. Cost?
Step 1: Before discount = 3 × $15 = $45
Step 2: 10% off = $45 × 0.10 = $4.50
Step 3: Final = $45 - $4.50 = $39.50

Now solve: Bob buys 2 shirts at $25 each, 20% discount
Solution:"

The AI uses the step-by-step format from your example.

System + role + few-shot:

text
System: "You are helpful and accurate."

User: "You're a senior data analyst explaining to non-technical people.

Example:
Data: 'Engagement +23%'
Explanation: 'More customers actively using our product.'

Data: 'Churn 8% → 5%'
Explanation: ?"

All three working together.


Different Types of AI Prompts: Quick Comparison

TypeSpeedAccuracyBest ForEffort
Zero-shot⚡⚡⚡⭐⭐Quick tasksMinimal
Few-shot⚡⚡⭐⭐⭐⭐ProductionMedium
Chain-of-thought⚡⚡⭐⭐⭐⭐⭐Complex reasoningMedium
Role/Persona⚡⚡⭐⭐⭐Specific voiceMinimal
System prompting⚡⚡⭐⭐⭐⭐Production appsMedium
JSON prompting⚡⚡⭐⭐⭐⭐AutomationMedium
Context prompting⭐⭐⭐⭐⭐Accuracy criticalHigh

Real Projects: How People Actually Use This Stuff

Support Chatbot

Goal: Support that doesn't sound like a robot.

What to do:

  • System prompting for consistent behavior
  • Role prompting as support specialist
  • Context prompting with customer history
  • JSON for {response, action, escalate}

Result: 40% fewer escalations, 92% customer satisfaction.

Content Writer

Goal: Blog posts that match your brand.

What to do:

  • Persona prompting as senior marketer
  • Few-shot with 3 previous posts as examples
  • System prompting for tone and length
  • Chain-of-thought: outline first, then write

Result: 80% approval on first draft. Was 40% before.

Data Pipeline

Goal: Extract structured data automatically.

What to do:

  • Few-shot with extraction examples
  • JSON prompting for output
  • Context prompting with schema

Result: 99.2% accuracy, fully automated.

Code Review Bot

Goal: Consistent, helpful reviews.

What to do:

  • System prompting for standards
  • Role prompting as senior engineer
  • Few-shot examples of good reviews
  • Chain-of-thought: explain → why → fix
  • JSON for {issue, severity, fix}

Result: 85% accepted without changes.


Stuff People Screw Up

Mistake 1: Being Vague

text
Bad: "Write about AI"
Good: "Write 500-word blog intro for managers on how AI cuts support costs"

Mistake 2: Bad Examples

text
Bad: All examples are positive sentiment
Good: Mix positive, negative, neutral

Mistake 3: Too Many Examples

text
Bad: 20 examples
Good: 3-5 really good ones

Mistake 4: Unclear Format

text
Bad: "Respond naturally"
Good: "Return JSON: {id, name, email, phone}"

Mistake 5: Contradictions

text
Bad: "Be concise and comprehensive"
Good: "Give 2-3 key points concisely"

Mistake 6: No Testing

text
Bad: Assume it works
Good: Test with 5-10 examples, measure, iterate

Getting Better Results

Clarity Over Cleverness

Write clear instructions. Not cute. Not creative. Clear.

Specific Over General

"Explain for a 10-year-old" beats "explain simply." "500 words" beats "not too long." "JSON with X, Y, Z" beats "structured format."

Examples Over Explanation

One example beats 100 words of text explaining something. Show, don't tell.

Test Different Approaches

Try zero-shot first. Fast. If it sucks, add few-shot. If accuracy still matters, add context. Measure what works.

Keep Iterating

Start simple. Test it. Add complexity when you need it. Keep tweaking. This isn't one-and-done.


Summary: The Core Prompting Techniques

Zero-shot: Quick and dirty exploration. Few-shot: Accurate, consistent results. Chain-of-thought: Complex reasoning. Role/persona: Specific expertise and voice. System prompting: Baseline behavior. JSON prompting: Automation-ready output. Context prompting: Accuracy with sources.

These work across different AI models. Mix and match based on what you need.

The Strategy

Start simple. Add examples if needed. Add structure for automation. Add context for accuracy. Combine what works.

Next Steps

Try each one with Claude or ChatGPT. Measure what actually works. Iterate. Save the prompts that win. Experiment with combinations.

How you ask determines what you get. Get this right and AI stops being frustrating and starts being actually useful.


Now go get some good responses. 🚀

Tags:
types of promptingprompting techniquesprompt engineeringzero-shot promptingfew-shot promptingchain-of-thought promptingrole promptingpersona promptingJSON promptingsystem promptingcontext promptingAI promptsprompt strategieseffective promptsprompt examplesAI guideLLM promptingChatGPT promptingClaude promptingprompt best practices
← View all articles
M
ManickavasaganAuthor

CS student and builder writing about tech, startups, AI, and productivity. Built a SaaS that didn't ship — walked away with real product experience instead. Sharing everything learned along the way.