Introduction
You've mastered the fundamentals. You know how to be clear, use examples, encourage thinking, refine iteratively, and provide context.
Now it's time to level up.
This chapter introduces advanced prompting patterns that professional AI engineers use for sophisticated tasks. These aren't just "tips and tricks" — they're systematic techniques that unlock Claude's full potential for complex work.
Think of the difference between cooking from a recipe and understanding the culinary techniques that let you improvise. The fundamentals got you following recipes. These advanced patterns let you create your own.
What you'll learn:
- Chain-of-thought prompting for systematic reasoning
- Output constraints for precise formatting
- XML structuring for complex requests
- Few-shot prompting for pattern learning
- Layered prompting for multi-step tasks
- Pattern combinations for expert-level results
Ready? Let's dive into the advanced playbook.
Pattern 1: Chain-of-Thought (CoT) Prompting
What it is: Explicitly asking Claude to show its reasoning process step-by-step before giving an answer.
Why it works: Forces systematic thinking, reduces errors, makes logic transparent, and improves accuracy on complex problems.
Basic Format
[Your question]
Think through this step-by-step before answering:
1. First, [step 1]
2. Then, [step 2]
3. Finally, [step 3]
After thinking through each step, provide your answer.
Real Example
Without Chain-of-Thought:
A store sells apples for $2 each. If you buy 5 or more, you get 20% off.
You buy 6 apples. How much do you pay?
Claude might jump to an answer, potentially making an error.
With Chain-of-Thought:
A store sells apples for $2 each. If you buy 5 or more, you get 20% off.
You buy 6 apples. How much do you pay?
Think through this step-by-step:
1. Calculate the base price (price × quantity)
2. Determine if the discount applies
3. Calculate the discount amount
4. Calculate the final price
Show your work for each step, then give the final answer.
Claude's response now shows:
- Step 1: $2 × 6 = $12
- Step 2: 6 apples ≥ 5, so discount applies
- Step 3: 20% of $12 = $2.40
- Step 4: $12 - $2.40 = $9.60
Final answer: $9.60
The reasoning is transparent, verifiable, and more likely to be correct.
When to Use Chain-of-Thought
- ✅ Math problems — Multi-step calculations
- ✅ Logic puzzles — Complex reasoning
- ✅ Analysis tasks — Breaking down information
- ✅ Debugging — Systematic troubleshooting
- ✅ Strategy development — Thinking through options
Pattern 2: Constrained Outputs
What it is: Specifying the exact format, structure, or constraints for the response.
Why it works: Ensures Claude's output fits directly into your workflow without manual reformatting.
Constrain by Format
Example:
List 5 productivity tools for remote teams.
Requirements:
- JSON format
- Each tool must include: name, category, price_range, best_for
- Sort by price (lowest to highest)
- Price ranges must be: "free", "budget", "premium"
Result: Clean JSON you can paste directly into code.
Constrain by Length
Example:
Explain quantum computing.
Constraints:
- Exactly 3 paragraphs
- Paragraph 1: What it is (50 words max)
- Paragraph 2: How it works (75 words max)
- Paragraph 3: Real applications (50 words max)
Result: Precise length for a specific context (website copy, presentation slide, etc.)
Constrain by Structure
Example:
Analyze this product launch strategy.
Provide your analysis in this exact format:
STRENGTHS (3 bullet points max)
WEAKNESSES (3 bullet points max)
OPPORTUNITIES (2 bullet points max)
THREATS (2 bullet points max)
RECOMMENDATION (1 paragraph, 100 words max)
Result: Structured SWOT analysis ready to present.
Industry Example: Marketing Brief
Create a campaign brief for our Q3 product launch.
OUTPUT FORMAT:
Campaign Name: [single line]
Target Audience: [2-3 sentences]
Key Message: [1 sentence, under 20 words]
Channels: [bullet list, 3-5 items]
Budget Allocation: [table format with percentages]
Timeline: [week-by-week breakdown, 8 weeks]
Success Metrics: [numbered list, 4-5 metrics]
Keep total output under 400 words.
Pattern 3: XML Tags for Structure
What it is: Using XML-like tags to organize complex prompts with multiple sections.
Why it works: Clear separation of different information types, easy for Claude to parse, handles complexity elegantly.
Basic Structure
<context>
[Background information]
</context>
<task>
[What you want Claude to do]
</task>
<data>
[Input data or examples]
</data>
<constraints>
[Rules and limitations]
</constraints>
<output_format>
[How to structure the response]
</output_format>
Real Example: Investment Analysis
<context>
I'm a startup founder raising a Series A. We have $2M ARR, growing 15% MoM.
Enterprise SaaS in the HR tech space.
</context>
<task>
Analyze this investment opportunity using systematic reasoning.
</task>
<data>
- Current ARR: $2M
- Growth rate: 15% month-over-month
- Burn rate: $400K/month
- Team size: 25 people
- Market size: $10B TAM
- Competitors: 3 major players, market leader at $50M ARR
</data>
<analysis_framework>
STEP 1: Market Analysis
- Market size and growth trajectory
- Competitive landscape assessment
- Defensibility and moat
STEP 2: Financial Health
- Unit economics evaluation
- Growth sustainability analysis
- Path to profitability timeline
STEP 3: Risk Assessment
- Market risks
- Execution risks
- Financial risks
STEP 4: Valuation
- Comparable companies analysis
- Growth-adjusted valuation
- Recommended valuation range
</analysis_framework>
<output_format>
For each step:
- Analysis (show your reasoning)
- Key findings (3-5 bullet points)
- Risk score (1-10 scale)
Final recommendation:
- Decision: INVEST / PASS / WATCH
- Rationale (2-3 sentences)
- Conditions (if applicable)
</output_format>
This combines:
- Clear context separation
- Structured analysis framework
- Defined output format
- Chain-of-thought reasoning
Pattern 4: Few-Shot Prompting
What it is: Providing 2-4 examples of the pattern you want Claude to follow.
Why it works: Shows Claude exactly what you mean, better than explaining. Especially powerful for style, format, or tone.
The Pattern
Convert [INPUT] into [OUTPUT].
Examples:
INPUT: [Example 1 input]
OUTPUT: [Example 1 output]
INPUT: [Example 2 input]
OUTPUT: [Example 2 output]
INPUT: [Example 3 input]
OUTPUT: [Example 3 output]
Now convert these:
[Your actual inputs]
Real Example: Feature → Benefit Copy
Convert product features into benefit-focused marketing copy.
Examples:
Feature: "256-bit encryption"
Benefit: "Your data stays private and secure, protected by bank-level encryption"
Feature: "Real-time sync across devices"
Benefit: "Start on your phone, finish on your laptop—your work is always up to date"
Feature: "Automated backups every hour"
Benefit: "Never lose your work. We save your progress automatically, so you can focus on creating"
Now convert these features:
- Unlimited cloud storage
- Advanced analytics dashboard
- API access with 99.9% uptime
- Custom branding options
Claude learns the pattern: technical feature → user-focused benefit.
When Few-Shot Shines
- ✅ Style transfer — Match a specific writing voice
- ✅ Format conversion — Transform data structures
- ✅ Tone matching — Replicate communication style
- ✅ Pattern extraction — Learn from examples
Pattern 5: Role Assignment
What it is: Asking Claude to adopt a specific role or perspective before responding.
Why it works: Frames the response from an expert viewpoint with appropriate depth and terminology.
The Pattern
<role>
You are a [specific role] with [X years] experience in [domain].
Your expertise includes [key areas].
</role>
<task>
[Your question or request]
</task>
Real Example
<role>
You are a senior DevOps engineer with 10 years of experience scaling
cloud infrastructure. Your expertise includes Kubernetes, AWS, CI/CD
pipelines, and cost optimization.
</role>
<task>
Our API response times increased from 200ms to 2000ms after deploying
a new microservice. Walk me through your debugging approach.
</task>
Claude now responds with the depth, terminology, and systematic approach of an experienced DevOps engineer.
Pattern 6: Constrain-Then-Expand
What it is: First get a constrained/simplified response, then progressively expand with detail.
Why it works: Ensures clarity before complexity, creates scaffolding for understanding.
The Pattern
LEVEL 1 (Simplest):
Explain [topic] in [constraint: 2 sentences for a 10-year-old]
LEVEL 2 (Moderate):
Now expand that explanation for [target: college student] in [constraint: 1 paragraph]
LEVEL 3 (Advanced):
Finally, provide a technical explanation for [target: professional] in [constraint: 2-3 paragraphs with terminology]
Real Example: Machine Learning Explanation
Explain machine learning.
LEVEL 1: Give me a 2-sentence explanation suitable for a 10-year-old.
LEVEL 2: Expand that explanation for a college student (1 paragraph).
LEVEL 3: Provide a technical explanation for a software engineer
(2-3 paragraphs with proper terminology).
Build each level on the previous one.
Result: Three explanations, each adding appropriate complexity.
Pattern 7: Conditional Logic
What it is: Asking Claude to handle different scenarios differently based on conditions.
Why it works: One prompt adapts to various situations, reduces back-and-forth.
The Pattern
Analyze [input].
IF [condition A]:
- [Action A1]
- [Action A2]
IF [condition B]:
- [Action B1]
- [Action B2]
IF [condition C]:
- [Action C1]
- [Action C2]
[Input here]
Real Example: Code Review
Review this code for bugs and optimization opportunities.
IF the code has bugs:
- Identify each bug
- Explain why it's a bug
- Provide corrected code
IF the code is correct but inefficient:
- Explain the inefficiency
- Suggest optimization approach
- Show optimized version with comments
IF the code is correct and efficient:
- Confirm it's well-written
- Suggest minor improvements (if any)
- Provide edge cases to test
[Your code here]
This ensures Claude provides the RIGHT type of feedback for the situation.
Combining Patterns: Expert-Level Prompting
The real power comes from combining multiple patterns strategically.
Example: Comprehensive Business Analysis
<role>
You are a senior strategy consultant with 15 years experience in SaaS.
</role>
<context>
Client: B2B marketing automation platform, $5M ARR, 200 customers.
Challenge: Considering expansion into SMB market (currently enterprise-focused).
</context>
<task>
Analyze this market expansion opportunity using chain-of-thought reasoning.
</task>
<analysis_framework>
STEP 1: Market Assessment
Think through:
- SMB market size vs current TAM
- Competitive landscape in SMB
- Buyer behavior differences
STEP 2: Business Model Impact
Think through:
- Pricing implications (enterprise vs SMB)
- Sales motion changes (high-touch vs self-serve)
- Support requirements
STEP 3: Operational Feasibility
Think through:
- Product adaptations needed
- Team/hiring implications
- Timeline to market
STEP 4: Financial Modeling
Think through:
- Revenue projections (3-year)
- Cost structure changes
- Break-even timeline
For each step, show your reasoning process before conclusions.
</analysis_framework>
<output_format>
For each step above:
ANALYSIS (your thinking)
- [Bullet points showing reasoning]
KEY FINDINGS
- [3-5 critical insights]
RISK LEVEL: [LOW / MEDIUM / HIGH]
After all 4 steps, provide:
FINAL RECOMMENDATION
Decision: [EXPAND / DON'T EXPAND / PHASE APPROACH]
Rationale: [2-3 sentences]
Conditions: [If conditional, what must be true]
Next Steps: [3-5 immediate actions]
</output_format>
This combines:
- Role assignment (expertise)
- XML structure (organization)
- Context provision (background)
- Chain-of-thought (reasoning)
- Constrained output (format)
- Layered analysis (progressive depth)
When to Use Advanced Patterns
Use Advanced Patterns For:
- ✅ Complex analysis requiring multiple steps
- ✅ Professional deliverables needing specific formats
- ✅ High-stakes decisions requiring systematic thinking
- ✅ Technical tasks with precise requirements
- ✅ Situations where generic responses won't work
Stick to Simple Prompts For:
- ❌ Quick questions
- ❌ Straightforward tasks
- ❌ Exploratory conversations
- ❌ Learning and understanding
Rule: Match prompt complexity to task complexity.
Common Mistakes with Advanced Patterns
Mistake 1: Over-Engineering Simple Tasks
❌ Using XML tags and chain-of-thought for "What's the capital of France?"
✅ Just ask the question
Mistake 2: Unclear Constraints
❌ "Make it concise"
✅ "Maximum 100 words, 2 paragraphs"
Mistake 3: Contradictory Requirements
❌ "Be comprehensive but brief, detailed but concise"
✅ "Cover these 3 points in 150 words total"
Mistake 4: Too Many Patterns at Once
❌ Trying to use 5 different patterns in one prompt
✅ Pick 2-3 that complement each other
Key Takeaways
- Advanced patterns unlock complex capabilities — Go beyond simple Q&A
- Chain-of-thought improves accuracy — Explicit reasoning reduces errors
- Constraints ensure usability — Specify format, length, structure
- XML tags organize complexity — Clear separation of prompt components
- Few-shot teaches patterns — Examples show better than explanations
- Combine patterns strategically — Mix techniques for powerful results
- Match complexity to task — Don't over-engineer simple questions
Your Turn: Assignment
Challenge: Pick a complex task you need to do. Design an advanced prompt using at least 2 patterns from this chapter.
Requirements:
- Choose appropriate patterns for your task
- Structure the prompt clearly
- Test it with Claude
- Refine based on results
- Compare to how you would have asked before
Reflection Questions:
- Which patterns did you combine?
- How did the output quality compare to simpler prompts?
- What would you do differently next time?
Share: What patterns worked best for your use case?