Chapter 2 of 3
Core Prompting Techniques
1. Zero-Shot Prompting
Give the AI a task with no examples — rely on its training data to figure it out. Works well for straightforward tasks.
Zero-shot exampletext
Classify the sentiment of this review as positive, negative, or neutral:
"The battery life is amazing but the camera quality is disappointing."
→ AI Output: Mixed/Neutral2. Few-Shot Prompting
Provide a few examples of the input-output pattern you want. The AI learns the pattern and applies it to new inputs.
Few-shot exampletext
Classify these reviews:
Review: "Best phone I've ever owned!"
Sentiment: Positive
Review: "Broke after two days."
Sentiment: Negative
Review: "It's okay, nothing special."
Sentiment: Neutral
Review: "The screen is gorgeous but it overheats."
Sentiment:Pro Tip
3–5 examples is the sweet spot for few-shot prompting. Too many examples waste tokens; too few may not establish the pattern.
3. Chain-of-Thought (CoT)
Ask the AI to think step by step before giving an answer. This dramatically improves accuracy for reasoning tasks.
Chain-of-thought exampletext
Question: If a store has 25 apples and sells 40% of them,
how many are left?
Think step by step:
1. 40% of 25 = 0.4 × 25 = 10 apples sold
2. 25 - 10 = 15 apples remaining
Answer: 15 apples4. Role-Based Prompting
Assign a specific role or persona to the AI. This shapes the tone, depth, and perspective of the response.
Role-based prompttext
You are a senior software engineer at Google with 15 years of experience.
A junior developer asks you: "Should I use Redux or Context API for state management in React?"
Give practical, opinionated advice with pros and cons.