Lesson 16
Advanced Prompting Patterns
AI-generated
- Understand and use chain-of-thought prompting
- Apply few-shot prompting with examples
- Use persona/role assignment effectively
- Know when to use which technique
- Combine techniques for complex tasks
You know the basics of prompting. You can write clear, specific prompts and iterate to get better results. Now it is time to level up.
This lesson introduces advanced prompting patterns that significantly improve AI output quality for complex tasks. These are not tricks or hacks. They are well-researched techniques backed by academic study and used by professionals daily.
By the end, you will have a toolkit of patterns you can apply whenever basic prompting falls short.
Chain-of-thought prompting is one of the most powerful techniques in the AI toolkit. The idea is simple: ask AI to think through a problem step by step before giving the final answer.
Why It Works
AI language models predict the most likely next words. When you ask for just an answer, AI jumps straight to what "sounds right." When you ask AI to show its reasoning first, the step-by-step work creates context that leads to better final answers.
Research from Google showed that chain-of-thought prompting can dramatically improve performance on math, logic, and reasoning tasks.
How to Use It
The simplest version: add "Think through this step by step" or "Show your reasoning" to your prompt.
Without chain-of-thought: "A store has 47 apples. They sell 23 and receive a shipment of 15. How many do they have?"
With chain-of-thought: "A store has 47 apples. They sell 23 and receive a shipment of 15. How many do they have? Think through this step by step before giving your final answer."
When Chain-of-Thought Helps Most
| Task Type | Improvement |
|---|---|
| Math problems | Significant |
| Logic puzzles | Significant |
| Multi-step reasoning | Significant |
| Cause-and-effect analysis | Moderate |
| Simple factual questions | Minimal |
| Creative writing | Usually unnecessary |
Advanced Chain-of-Thought
For complex problems, you can guide the reasoning structure:
"Analyze whether I should accept this job offer. Think through it in these stages: (1) List my priorities, (2) Evaluate how this job meets each priority, (3) Consider what I would be giving up, (4) Make a recommendation."
Few-shot prompting means giving AI examples of what you want before asking it to do the task. It is like saying "do it like this" instead of explaining what you want.
The Basic Pattern
Zero-shot (no examples): "Write a user story for a password reset feature."
Few-shot (with example): "Here's an example of how I write user stories:
Feature: Account login User Story: As a registered user, I want to log in with my email and password so that I can access my account securely.
Now write a user story for: Password reset feature"
Why Examples Work
Examples communicate things that are hard to explain:
- The exact format you want
- Your preferred level of detail
- Tone and style
- How to handle edge cases
One good example is often clearer than a paragraph of instructions.
Best Practices for Few-Shot
- Use 1-3 examples: More examples help, but diminishing returns set in quickly
- Make examples representative: Show the typical case, not the exception
- Match complexity: If you want detailed output, show detailed examples
- Include edge cases: If certain situations need special handling, show how
Few-Shot for Formatting
Few-shot is especially powerful for consistent formatting:
"Convert these product descriptions to this format:
Input: 'Our comfortable cotton t-shirt comes in blue, red, and green. Machine washable. $29.99' Output:
- Product: Cotton T-Shirt
- Colors: Blue, Red, Green
- Care: Machine washable
- Price: $29.99
Now convert: 'Leather wallet with 6 card slots and bill compartment. Available in black and brown. $45'"
Assigning AI a role or persona shapes how it responds. This is not just about fun roleplay. It is a practical technique that changes AI's default assumptions, vocabulary, and approach.
How Role Assignment Works
When you say "You are a financial advisor," AI shifts its response style to match what a financial advisor would say: professional tone, appropriate caution, relevant terminology, and suitable recommendations.
Effective Role Prompts
Basic: "You are a [role]."
Better: "You are a [role] with [specific characteristics]. Your audience is [description]. Your goal is [objective]."
Example: "You are an experienced high school chemistry teacher known for clear explanations and memorable analogies. Your student is a curious 10th grader who finds chemistry confusing. Your goal is to make complex concepts click."
Roles That Work Well
| Role | When to Use |
|---|---|
| Teacher/Tutor | When you need explanations adapted to a level |
| Editor | When reviewing and improving text |
| Devil's Advocate | When you want pushback on ideas |
| Career Counselor | When exploring professional decisions |
| Technical Writer | When you need clear documentation |
| Creative Director | When brainstorming needs direction |
Combining Role with Other Techniques
"You are a senior software architect reviewing code for a junior developer. I'm going to show you my code. Think through potential issues step by step, then give me prioritized feedback. Here's the code: [paste]"
This combines: role (architect), audience awareness (junior dev), chain-of-thought (step by step), and structured output (prioritized).
Sometimes you need AI output in a specific format: JSON, a table, a particular outline structure. Structured output prompting makes this reliable.
Specifying Format
Be explicit about the structure you want:
"Analyze this restaurant review and respond with:
- Sentiment: [positive/negative/mixed]
- Main topics: [list 3-5 topics]
- Would recommend: [yes/no]
- Summary: [one sentence]
Review: [paste review]"
Getting JSON Output
For technical use cases, AI can output valid JSON:
"Extract the key information from this contact and return it as JSON with these fields: name, email, phone, company, role. If a field is not present, use null.
Contact info: 'Sarah Chen, Senior PM at TechCorp, [email protected], 555-0123'"
Tables and Lists
"Compare these three options in a table format with columns: Option Name, Cost, Time to Implement, Main Risk, Best For"
Templates with Placeholders
"Fill in this template based on the information provided:
Subject: [Meeting Type] - [Date] Hi [Name],
Following up on our conversation about [Topic]. Key points:
- [Point 1]
- [Point 2]
Next steps: [Action items]
Best, [Sign-off]
Information: We discussed Q2 marketing budget on Tuesday with Jennifer. Need to finalize ad spend and timeline."
The real power comes from combining techniques. Here is a framework for complex tasks:
The RICE Framework
- Role: Who should AI be?
- Instructions: What exactly should it do?
- Context: What background does it need?
- Examples: What does good output look like?
Example combining all four:
"Role: You are an executive coach who specializes in helping new managers.
Instructions: Help me prepare for a difficult conversation with an underperforming employee. Walk through how to structure the conversation step by step.
Context: I'm a first-time manager. The employee is talented but has missed three deadlines in a row. I want to be supportive but also clear about expectations. The conversation is tomorrow.
Example of tone I want: 'I've noticed some challenges with recent deadlines. I want to understand what's happening and how I can support you in getting back on track.'"
- Chain-of-thought: Add "think step by step" for reasoning tasks
- Few-shot: Show 1-3 examples of what you want
- Role assignment: Give AI a persona to shape its approach
- Structured output: Specify exact format you need
- Combine techniques: Use RICE (Role, Instructions, Context, Examples) for complex tasks
Take a complex question you want answered. Try it three ways:
- Plain question: Just ask it directly
- With chain-of-thought: Add "Think through this step by step before giving your final answer"
- With role assignment: Add "You are an expert in [relevant field]"
Compare the three responses. Notice which technique improved the output most for your specific question. Different questions benefit from different techniques.
- Chain-of-thought prompting research: https://arxiv.org/abs/2201.11903
- Few-shot learning in language models: https://arxiv.org/abs/2005.14165
- Anthropic prompt engineering guide: https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering
- OpenAI best practices: https://platform.openai.com/docs/guides/prompt-engineering