Prompt Engineering12 min read

Prompt Techniques

Secret methods power users use to get incredible AI results
scope:Core Conceptdifficulty:Intermediate

The Toolbox Every AI Power User Needs

You've learned to talk to AI. You know that being specific matters. But there's a whole level above that β€” prompt techniques. These are proven strategies that researchers and power users have discovered to get dramatically better results from AI.

Think of it like cooking. Anyone can follow a recipe (basic prompting). But a skilled chef knows techniques β€” how to sear for a good crust, when to rest meat, how to balance acidity. These techniques work across any recipe. Prompt techniques work across any AI task.

Let's learn the five most powerful ones.

1. Zero-Shot: Just Ask

Zero-shot prompting means giving the AI a task with no examples. You describe what you want, and the AI figures it out from its training.

Classify this movie review as positive or negative: "The acting was wooden and the plot made no sense."

This works surprisingly well for straightforward tasks. The model has seen enough examples during training to understand what "classify as positive or negative" means without you showing it how.

When to use it: Simple, well-defined tasks. Classification, translation, summarization, factual questions. If the task is common and clear, zero-shot often suffices.

2. Few-Shot: Show Me First

Few-shot prompting means giving the AI a few examples of what you want before asking it to do the task. It's like showing someone sample work before asking them to do their own.

Instead of just saying "classify this," you show the AI 2-3 completed examples first:

Review: "Absolutely brilliant, best film of the year" β†’ Positive
Review: "Boring and predictable, waste of time" β†’ Negative
Review: "The acting was wooden and the plot made no sense" β†’

The AI sees the pattern and follows it. This technique is incredibly powerful because it lets you teach the AI your specific format and your specific standards without any fine-tuning.

When to use it: Tasks with a specific format, unusual classification categories, consistent output structure, or when zero-shot gives inconsistent results.

3. Chain-of-Thought: Think Step by Step

This one is almost magical. Simply adding "Think step by step" or "Let's work through this" to your prompt dramatically improves the AI's reasoning ability. It's called chain-of-thought (CoT) prompting.

Without CoT:

If a shirt costs $25 and is 20% off, and you have a $5 coupon, how much do you pay?

The AI might jump to an answer and get it wrong.

With CoT:

If a shirt costs $25 and is 20% off, and you have a $5 coupon, how much do you pay? Think step by step.

Now the AI will write out: "Step 1: Original price is $25. Step 2: 20% off = $25 Γ— 0.80 = $20. Step 3: Apply $5 coupon: $20 - $5 = $15. The answer is $15."

Why does this work? When the AI writes out intermediate steps, each step becomes part of the context for the next step. The model can use its own reasoning as scaffolding. It's like how you solve math problems β€” writing down work helps you think.

When to use it: Math problems, logic puzzles, multi-step reasoning, coding problems, any task that requires thinking through multiple steps.

4. Role Prompting: Become Someone

Role prompting means telling the AI to act as a specific expert or character. This subtly shifts how the model responds β€” it draws on the patterns associated with that role.

You are a senior software engineer at Google with 15 years of experience. Review this code for production-readiness.

The AI will now focus on things a senior engineer would care about: error handling, edge cases, performance, security, maintainability. Without the role, it might give a more generic review.

Other examples:

  • You are a patient kindergarten teacher. Explain quantum physics. β€” gets simpler, friendlier explanations
  • You are a strict academic reviewer. Evaluate this essay. β€” gets more critical, detailed feedback
  • You are a creative writing coach. Help me improve this story. β€” focuses on narrative, character, and voice

When to use it: When you want a specific perspective, expertise level, or communication style.

5. Output Formatting: Tell the AI What Shape You Want

One of the most practical techniques is explicitly specifying the output format. Most people forget this and then spend time reformatting the AI's response.

Instead of: List some healthy breakfast ideas

Try: List 5 healthy breakfast ideas. For each one, give the name, prep time, and main ingredients in this format:

**[Name]** (prep: X min)
Ingredients: ingredient1, ingredient2, ingredient3

You can ask for:

  • JSON β€” Return the result as a JSON object with keys: name, age, city
  • Tables β€” Format as a markdown table with columns: Feature, Pros, Cons
  • Bullet lists β€” Give me exactly 5 bullet points, each under 20 words
  • Code β€” Write the solution as a Python function with type hints and a docstring

When to use it: Always. Specifying format is almost always a good idea. It saves you time and makes the AI's output immediately usable.

Prompt Techniques in Python

# Demonstrating each prompt technique with actual API-style calls
# (Using a generic AI client for illustration)
# === 1. ZERO-SHOT ===
zero_shot_prompt = """Classify this review as positive, negative, or neutral:
"The battery life is amazing but the screen is too dim.""""
print("=== Zero-Shot ===")
print(f"Prompt: {zero_shot_prompt}")
print("AI would say: Neutral (mixed positive and negative)\n")
# === 2. FEW-SHOT ===
few_shot_prompt = """Classify each review. Examples:
Review: "Best purchase ever, works perfectly!" β†’ Positive
Review: "Broke after one day, total waste" β†’ Negative
Review: "It's okay, nothing special" β†’ Neutral
Now classify:
Review: "The battery life is amazing but the screen is too dim." β†’"""
print("=== Few-Shot ===")
print(f"Prompt: {few_shot_prompt}")
print("AI would say: Neutral\n")
# === 3. CHAIN-OF-THOUGHT ===
cot_prompt = """A store has a 30% off sale. You buy 3 shirts at $40 each.
You also have a loyalty card that gives an extra 10% off the
sale price. What's your total? Think step by step."""
print("=== Chain-of-Thought ===")
print(f"Prompt: {cot_prompt}")
print("""AI would reason:
Step 1: 3 shirts Γ— $40 = $120 total
Step 2: 30% off: $120 Γ— 0.70 = $84
Step 3: Extra 10% off: $84 Γ— 0.90 = $75.60
Answer: $75.60\n""")
# === 4. ROLE PROMPTING ===
role_prompt = """You are a senior Python developer who values clean,
readable code. Review this function:
def f(x):
return [i for i in range(2,x) if all(i%j!=0 for j in range(2,i))]"""
print("=== Role Prompting ===")
print(f"Prompt: {role_prompt}")
print("""AI (as senior dev) would say:
1. Rename 'f' to 'find_primes' β€” be descriptive
2. Rename 'x' to 'upper_limit'
3. Add a docstring explaining what it does
4. Add type hints: def find_primes(upper_limit: int) -> list[int]
5. Consider using math.isqrt for efficiency\n""")
# === 5. OUTPUT FORMATTING ===
format_prompt = """Compare Python, JavaScript, and Rust.
Return the result as JSON with this structure:
{
"languages": [
{"name": "...", "best_for": "...", "learning_curve": "..."}
]
}"""
print("=== Output Formatting ===")
print(f"Prompt: {format_prompt}")
print("AI returns structured JSON you can parse directly!")
Output
=== Zero-Shot ===
Prompt: Classify this review as positive, negative, or neutral:
"The battery life is amazing but the screen is too dim."
AI would say: Neutral (mixed positive and negative)

=== Few-Shot ===
Prompt: Classify each review. Examples:
...
AI would say: Neutral

=== Chain-of-Thought ===
Prompt: A store has a 30% off sale...
AI would reason:
  Step 1: 3 shirts Γ— $40 = $120 total
  Step 2: 30% off: $120 Γ— 0.70 = $84
  Step 3: Extra 10% off: $84 Γ— 0.90 = $75.60
  Answer: $75.60

=== Role Prompting ===
Prompt: You are a senior Python developer...
AI (as senior dev) would say:
  1. Rename 'f' to 'find_primes' β€” be descriptive
  2. Rename 'x' to 'upper_limit'
  3. Add a docstring explaining what it does
  4. Add type hints
  5. Consider using math.isqrt for efficiency

=== Output Formatting ===
Prompt: Compare Python, JavaScript, and Rust...
AI returns structured JSON you can parse directly!
Note: Combine techniques for maximum power! The real magic happens when you mix techniques together. Use role prompting + chain-of-thought + output formatting: "You are a math tutor. Solve this problem step by step. Format each step as a numbered list with the calculation shown." Combining techniques is what separates beginners from power users.

Choosing the Right Technique

Here's a quick guide for when to use each technique:

  • Zero-shot β€” your default. Try it first. If the task is common (translate, summarize, classify), zero-shot often works great.
  • Few-shot β€” when you need a specific format or the task is unusual. Whenever the AI doesn't "get it" on the first try, show it examples.
  • Chain-of-thought β€” anything involving math, logic, or multi-step reasoning. The magic words "think step by step" cost almost nothing and often dramatically improve accuracy.
  • Role prompting β€” when you need a specific perspective or expertise level. Great for code review, writing feedback, teaching, and creative tasks.
  • Output formatting β€” almost always. Specifying the output format saves you time and makes results more consistent and usable.

Remember: these techniques aren't mutually exclusive. The best prompts often combine two or three of them. A senior engineer (role) who thinks step by step (CoT) and returns structured JSON (formatting) will give you better code reviews than any single technique alone.

Challenge

Quick check

What is 'few-shot' prompting?

Continue reading