DEV Community

Manickavasagan
Manickavasagan

Posted on

Types of Prompting: Complete Guide to Prompting Techniques

I spent two weeks blaming Claude for being useless. Turns out Claude wasn't the problem—I just had no idea how to ask it anything.

That's when I realized prompting isn't mystical. It's asking better questions. Different ways work for different jobs.

What Is Prompting?

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

Asking someone to "make food" gets you whatever's in the fridge. Asking for "that pasta carbonara like you made last month" gets you exactly what you want. Same person. Different ask.

Here are the 7 techniques that actually matter:

1. Zero-Shot: Just Ask. No Examples.

You don't show examples. You just ask and see what you get.

These models learned patterns from massive amounts of text. So when you ask something new, it pattern-matches to what it knows.

Example:

"Write a haiku about AI"

Minds made of numbers
Learning patterns in the dark  
Future takes its shape
Enter fullscreen mode Exit fullscreen mode

When to use: Quick translations, sentiment checks, summarizing articles.

How to get better results: Stop being vague.

  • ❌ "Write about AI"
  • ✅ "Write a 300-word intro for business managers about how AI reduces customer support costs—use actual examples"

2. Few-Shot: Show Examples, Then Ask

Give it 2-5 examples of what you want, then ask it to do the same with new data.

Why it works: When you show examples, the AI learns the pattern right there. The accuracy jump is ridiculous—I've seen 70% accuracy jump to 94% just by adding three examples.

Example:

Classify sentiment:

Review: "Amazing product! Love it!"
Sentiment: positive

Review: "Terrible quality, fell apart immediately"
Sentiment: negative

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

Now this:
Review: "Best purchase ever!"
Sentiment: ?
Enter fullscreen mode Exit fullscreen mode

AI: "positive"

Sweet spot: 3-5 good examples. Quality over quantity. One great example beats five mediocre ones.

3. Chain-of-Thought: Make It Show Its Work

Tell the AI to think through something step-by-step instead of just guessing.

Why it matters: Ask an AI to think step by step? It reasons better. You get better logic, fewer mistakes, and you can follow what it's doing.

Example:

Step by step:

Step 1: Books cost = 3 × $15 = $45
Step 2: Total cost = books + pen = $45 + $5 = $50
Step 3: Change = $100 - $50 = $50

Now solve: Alice buys...
Enter fullscreen mode Exit fullscreen mode

When to use: Math problems, logic, analysis, debugging, planning. Anywhere you want to see how it got there.

4. Role/Persona Prompting: Tell It Who to Be

Assign the AI a role and it adopts that perspective and knowledge base.

Examples:

  • ❌ "What should I consider for a startup?"
  • ✅ "You're a serial entrepreneur who's built 3 startups. What should I consider when launching?"

  • ❌ "Explain machine learning"

  • ✅ "You're a professor explaining machine learning to undergrads. Explain it."

The response sounds like someone who knows what they're doing instead of generic AI voice.

5. System Prompting: Set the Baseline Rules

System prompting applies to everything the user sends. It's like briefing someone before they start work.

Example:

System: "You are a helpful customer support specialist.
- Be friendly and empathetic
- Solve problems quickly
- Keep responses under 200 words"
Enter fullscreen mode Exit fullscreen mode

Every response follows those rules.

6. JSON Prompting: Get Data You Can Actually Use

Want structured output your code can parse? Tell the AI to return only JSON with a specific structure.

Example:

Extract customer info. Return only JSON:
{
  "name": "",
  "email": "",
  "issue": "",
  "priority": "low|medium|high"
}
Enter fullscreen mode Exit fullscreen mode

You get parseable JSON instead of messy prose.

7. Context Prompting: Give It Source Material

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

Why it works: AI hallucinates. But give it a specific source? It mostly sticks to what's there. Accuracy jumps dramatically.

Example:

Based on this earnings report, what was Q3 revenue?

[paste report]

Return as JSON: {"quarter": "Q3", "revenue": ""}
Enter fullscreen mode Exit fullscreen mode

Actual numbers from the document. Not made up.

Combining Techniques: When It Gets Powerful

Stack them:

Few-shot + role:

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: ?
Enter fullscreen mode Exit fullscreen mode

Chain-of-thought + few-shot:

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...
Enter fullscreen mode Exit fullscreen mode

Quick Comparison

Type Speed Accuracy Best For
Zero-shot ⚡⚡⚡ ⭐⭐ Quick tasks
Few-shot ⚡⚡ ⭐⭐⭐⭐ Production
Chain-of-thought ⚡⚡ ⭐⭐⭐⭐⭐ Complex reasoning
Role/Persona ⚡⚡ ⭐⭐⭐ Specific voice
System prompting ⚡⚡ ⭐⭐⭐⭐ Production apps
JSON prompting ⚡⚡ ⭐⭐⭐⭐ Automation
Context prompting ⭐⭐⭐⭐⭐ Accuracy critical

The Strategy

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


Want the full guide with code examples, real-world projects, and common mistakes to avoid?

Read the complete interactive guide on TechBasics

It includes practical examples, code snippets, and how professionals actually use these techniques in production.


Top comments (0)