Advanced

Advanced Prompt Techniques:
Chain-of-Thought, Few-Shot & More

Standard prompting techniques — role assignment, context setting, output formatting — cover the majority of everyday use cases well. But some tasks are more demanding: multi-step reasoning, consistent classification across many inputs, structured data extraction, or maintaining a specific persona across a long conversation. For these, a set of advanced techniques from the AI research community significantly improves results.

This guide covers five techniques drawn from published research and widely validated in practice. Each includes a concrete example you can adapt immediately.

1. Chain-of-Thought (CoT) Prompting

Chain-of-thought prompting instructs the AI to reason through a problem step by step before giving its final answer. This technique was formalized in a 2022 Google Research paper and has since become a cornerstone of advanced prompting for reasoning-heavy tasks.

The key insight is that AI models produce more accurate answers to complex problems when they "show their work" first, rather than jumping directly to a conclusion.

Basic CoT trigger:

Solve this problem step by step, showing your reasoning at each stage before giving the final answer.

Full CoT example:

Act as a financial analyst.

A company has revenue of $4.2M, COGS of $1.8M, operating expenses of $900K, and interest expense of $120K. The tax rate is 28%.

Calculate the net income. Think through it step by step: start with gross profit, then operating income, then pre-tax income, then apply the tax rate.

CoT prompting is most valuable for: math and logic problems, multi-step analysis, debugging, legal or ethical reasoning, and any task where the process of arriving at an answer matters as much as the answer itself.

2. Few-Shot Prompting

Few-shot prompting provides the AI with 2–5 examples of the exact input/output pattern you want before giving it the actual task. This is one of the most reliable ways to enforce a specific format, style, or classification scheme without writing exhaustive instructions.

The examples serve as a template that the model matches, dramatically reducing the variance in how it interprets your task.

Few-shot classification example:

Classify customer support tickets by urgency: Critical (system down), High (major feature broken), Medium (minor issue), Low (question or request).

Examples:
Input: "Our entire API is returning 500 errors — all production requests are failing"
Classification: Critical

Input: "The export to CSV button stopped working after your last update"
Classification: High

Input: "The font in the settings page looks slightly off on mobile"
Classification: Low

Input: "How do I add a new team member to my organization?"
Classification: Low

Now classify this ticket:
Input: "Users in our Europe region can't log in — started about 30 minutes ago"
Classification:

Few-shot prompting is particularly effective for: sentiment analysis, content classification, tone matching, data extraction in a specific format, and generating consistent variations of a style or structure.

3. Structured Output Prompting

When you need AI output to be reliably parseable — for use in code, databases, or downstream processing — instruct the model to respond in a strict format like JSON, XML, or a custom delimiter-separated structure. Define the schema explicitly.

JSON schema example:

Extract the following information from this job posting and return it as a JSON object. Use exactly this schema:

{
  "job_title": "string",
  "company": "string",
  "location": "string (city, state/country or Remote)",
  "employment_type": "Full-time | Part-time | Contract | Unknown",
  "salary_min": number or null,
  "salary_max": number or null,
  "required_skills": ["string"],
  "experience_years_min": number or null,
  "remote_friendly": true | false
}

If a field is not mentioned, use null. Do not include any text outside the JSON object.

Job posting:
[PASTE JOB POSTING HERE]

Key tips for structured output:

  • Always provide an explicit schema or template
  • Specify the fallback value for missing fields (null, empty string, "Unknown")
  • Add "Do not include any text outside the [format]" to prevent preamble or explanation
  • For critical applications, validate the output programmatically

4. Role Chaining

Role chaining sequences multiple specialized roles within a single prompt or across a conversation. One agent produces output that a second "reviews," "criticizes," or "builds upon." This mimics a real team review process and often catches errors or blind spots that a single-role prompt misses.

Single-prompt role chain example:

I need you to take on two roles in sequence:

STEP 1 — Act as a startup founder:
Write a 100-word pitch for an AI-powered personal finance app targeting Gen Z users. Focus on the problem, the solution, and the market opportunity.

STEP 2 — Act as a skeptical venture capitalist who has seen 500 pitches:
Critically evaluate the pitch you just wrote. Identify the two weakest claims and explain what evidence or data would make them more convincing.

Complete Step 1 first, then Step 2. Label each section clearly.

Role chaining is powerful for: writing and editing cycles, code review, argument and counter-argument generation, strategy stress-testing, and any task that benefits from multiple perspectives.

5. Self-Consistency Prompting

Self-consistency is a technique where you ask the AI to solve the same problem multiple times with explicit variation instructions, then identify the most consistent or highest-confidence answer. This is especially useful for tasks where the AI might produce different outputs on different runs.

Self-consistency example:

I need to name a new productivity app for remote engineering teams. Generate 3 entirely different name concepts using 3 different creative directions:

Direction A: Technical/precise — names that signal efficiency and engineering
Direction B: Human/warm — names that signal collaboration and team culture
Direction C: Abstract/memorable — names that prioritize uniqueness and brandability

For each direction, provide 3 name options with a one-sentence rationale for each.

After generating all 9 options, identify the single strongest name across all three directions and explain why it stands out.

Combining Techniques

The real power emerges when you combine these techniques. Here is an example that uses chain-of-thought, few-shot, and structured output together:

Act as a senior UX researcher.

Task: Analyze user feedback comments and classify each by: sentiment (positive/negative/neutral), category (onboarding/performance/design/support/feature-request), and priority (high/medium/low).

Think step by step for each comment: (1) identify the core complaint or praise, (2) determine sentiment, (3) assign category, (4) assess priority based on how many users are likely affected.

Examples:
Comment: "Setting up took forever, couldn't find where to import my data"
→ Sentiment: negative | Category: onboarding | Priority: high

Comment: "Love the new dashboard — looks clean and loads faster!"
→ Sentiment: positive | Category: performance | Priority: low

Output Format: Return a JSON array where each object has: comment (string), sentiment, category, priority, reasoning (1 sentence).

Feedback to analyze:
1. "The mobile app crashes every time I try to upload a file"
2. "Would love a dark mode option"
3. "Your support team responded in 5 minutes — incredible service"

When to Use Each Technique

A quick reference for choosing the right technique:

  • Chain-of-Thought: Math, logic, analysis, debugging, any multi-step reasoning
  • Few-Shot: Classification, style matching, format enforcement, consistent extraction
  • Structured Output: Data extraction, anything feeding into code or a database
  • Role Chaining: Writing + editing, strategy + critique, code + review
  • Self-Consistency: Creative generation, naming, ideation, decisions with multiple valid answers

Mastering these five techniques — alongside the foundational seven from the previous guide — puts you in the top percentile of AI prompt writers. The difference in output quality is significant and immediately noticeable.

Use the PromptUse Formatter and Templates to apply these patterns to your own prompts without starting from scratch.

← Better Prompts Guide Try the Tool →