CHAIN Framework: Chain-of-Thought Prompting Guide
Master chain-of-thought prompting with the CHAIN framework. Learn the 5-step method that tripled AI accuracy on reasoning tasks, with 7 real examples.

CHAIN Framework: The Complete Chain-of-Thought Prompting Guide
When Google researchers added "Let's think step by step" to their prompts, accuracy on math problems tripled. That discovery, published by Wei et al. in 2022, launched chain of thought prompting as one of the most important techniques in prompt engineering. But "think step by step" is just the starting point. The CHAIN framework takes that core insight and structures it into five repeatable stages: Context, Hypothesis, Analysis, Inference, and Narration.
I have used CHAIN across hundreds of complex prompts, from debugging production systems to evaluating business decisions to solving logic puzzles. This guide walks through exactly how the framework works, gives you 7 full examples you can copy and adapt, and shows you when CHAIN outperforms simpler approaches.
For a quick reference version of the framework itself, see the CHAIN framework page. This tutorial goes deeper with practical examples, model-specific tips, and common pitfalls.
What Is the CHAIN Framework?
CHAIN stands for Context, Hypothesis, Analysis, Inference, Narration. Each letter represents a stage of reasoning that you explicitly build into your prompt:
- Context - Provide all relevant background, data, and constraints so the AI does not fill gaps with assumptions
- Hypothesis - State a specific, testable proposition about the answer or cause
- Analysis - List the sub-questions or dimensions the AI should examine step by step
- Inference - Ask the AI to connect findings, identify patterns, and test the hypothesis against evidence
- Narration - Specify the output format and require the reasoning trail to be visible in the final deliverable
Think of CHAIN as the scientific method applied to prompting. You observe (Context), hypothesize (Hypothesis), experiment (Analysis), conclude (Inference), and report (Narration).
Why Chain-of-Thought Prompting Works
The original chain-of-thought research from Wei et al. at Google Brain demonstrated something remarkable. On the GSM8K benchmark of grade-school math word problems, standard prompting achieved just 17.9% accuracy with a large language model. Adding chain-of-thought exemplars, where the prompt included worked-out reasoning steps, pushed accuracy to 57.1%. That is a 3x improvement from a prompting technique alone, with zero changes to the model.
Why does showing reasoning steps help? Large language models generate text token by token. When you ask for just an answer, the model has to make a single "jump" from question to solution. When you ask for reasoning steps, each intermediate token gives the model more context for the next token. The reasoning steps act as scaffolding.
Zero-shot vs. few-shot CoT:- Few-shot CoT includes 2-8 worked examples with visible reasoning in the prompt. The model learns the pattern and applies it to the new question.
- Zero-shot CoT simply appends "Let's think step by step" to the prompt. Kojima et al. (2022) showed this works surprisingly well without any examples.
- Structured CoT (CHAIN) goes further by defining what the steps should be, not just asking for steps in general.
As the Prompt Engineering Guide notes, chain-of-thought prompting is most effective for tasks that require arithmetic reasoning, commonsense reasoning, and symbolic manipulation. CHAIN extends that effectiveness to real-world tasks like debugging, strategic analysis, and multi-criteria decisions.
Step-by-Step Walkthrough: Debugging with CHAIN
Let me walk through a real debugging scenario to show how each CHAIN stage builds on the previous one.
The problem: A Node.js API is returning 504 Gateway Timeout errors for roughly 15% of requests during business hours. No recent code changes were deployed.
C - Context
Our Node.js Express API runs on 4 AWS EC2 instances behind an ALB (Application
Load Balancer). It connects to a PostgreSQL RDS instance (db.r5.xlarge). The API
handles 3,000 requests per minute during business hours. The 504 errors started
3 days ago. No code was deployed in the past 2 weeks. CloudWatch shows CPU usage
on the EC2 instances at 45% and RDS CPU at 78%. The ALB timeout is set to 30
seconds. Average response time was 200ms last week; it is now 1,800ms at the p95.This gives the AI everything a DevOps engineer would need. Specific numbers, infrastructure details, timeline, and what has not changed (no deployments).
H - Hypothesis
Hypothesis: The 504 errors are caused by PostgreSQL query degradation, likely
from table bloat or missing index usage on a query plan change, which is pushing
response times past the ALB's 30-second timeout for the slowest requests.This is specific and testable. The AI can confirm it (if the evidence supports database issues) or refute it (if the evidence points elsewhere).
A - Analysis
Analysis:
1. Compare RDS query execution times from last week vs. this week for the top 10
slowest queries
2. Check if PostgreSQL autovacuum has run recently and whether any large tables
have significant dead tuple counts
3. Examine the ALB access logs for which specific endpoints are generating 504s
4. Review the EC2 connection pool configuration and check for pool exhaustion
during peak load
5. Verify that no RDS maintenance events or failovers occurred in the past weekFive specific, answerable sub-questions. Each one targets a different possible cause while keeping the hypothesis in focus.
I - Inference
Inference: Based on the analysis, determine whether the root cause is database-side
(supporting the hypothesis) or infrastructure-side (refuting it). If multiple factors
contribute, rank them by impact. Identify the single change that would resolve the
majority of 504 errors.This asks the AI to connect the dots across all five analyses and make a judgment call.
N - Narration
Narration: Present the findings as a root cause analysis with: (1) executive summary
stating the root cause in one sentence, (2) evidence chain showing how each analysis
step supports or contradicts the hypothesis, (3) recommended fix with specific
commands or configuration changes, (4) a verification plan to confirm the fix worked.The narration specifies exactly what deliverable to produce, preserving the reasoning trail.
7 CHAIN Framework Examples
Example 1: Math Word Problem
Context: A factory produces 3 types of widgets. Type A costs $4 to make and sells
for $10. Type B costs $7 to make and sells for $18. Type C costs $12 to make and
sells for $28. The factory has a daily budget of $2,400 for materials and can
produce a maximum of 400 widgets per day across all types. Customer demand requires
at least 50 Type A, 30 Type B, and 20 Type C widgets daily.
Hypothesis: Maximizing Type B production (after meeting minimums) yields the highest
daily profit because it has the best profit-to-cost ratio.
Analysis:
1. Calculate the profit margin and profit-to-cost ratio for each widget type
2. Determine the material cost of meeting minimum demand requirements
3. Calculate remaining budget and capacity after fulfilling minimums
4. Model three allocation strategies: maximize A, maximize B, maximize C
5. Compare total daily profit under each strategy
Inference: Determine whether the hypothesis holds or whether a different allocation
maximizes profit. Identify if the budget constraint or the capacity constraint is
the binding factor.
Narration: Present the optimal production plan as a table showing units per type,
total cost, total revenue, and total profit. Include the mathematical reasoning
for each step.Example 2: Code Debugging
Context: A Python Flask application uses SQLAlchemy with a PostgreSQL database.
Users report that the /api/reports endpoint takes 45 seconds to respond when
generating reports for date ranges longer than 90 days. The same endpoint returns
in under 2 seconds for 30-day ranges. The reports table has 12 million rows and
is indexed on created_at. The query uses a JOIN with a 500K-row customers table.
Hypothesis: The query planner switches from an index scan to a sequential scan
when the date range exceeds a threshold, because PostgreSQL estimates that scanning
the full table is cheaper than using the index for large result sets.
Analysis:
1. Run EXPLAIN ANALYZE on the query for a 30-day range and a 120-day range
2. Compare the estimated vs. actual row counts in both plans
3. Check table statistics: when was the last ANALYZE run on the reports table?
4. Examine if the JOIN strategy changes between the two ranges (nested loop vs.
hash join)
5. Calculate what percentage of the table a 90-day range represents
Inference: Confirm whether the plan switch is the root cause or whether the
slowdown comes from the JOIN, data volume, or memory pressure. Recommend the
fix that addresses the actual bottleneck.
Narration: Provide the root cause with EXPLAIN ANALYZE output comparison, the
specific fix (partial index, query hint, or statistics update), and the SQL
commands to implement it.Example 3: Logical Puzzle
Context: Five houses in a row are painted different colors (red, blue, green,
yellow, white). Each owner has a different nationality (English, Spanish, Japanese,
Norwegian, Italian), drinks a different beverage (coffee, tea, milk, juice, water),
and has a different pet (dog, cat, bird, fish, horse). Clues: The English person
lives in the red house. The Spanish person has a dog. Coffee is drunk in the green
house. The Italian drinks tea. The green house is directly to the right of the white
house. The bird owner drinks juice. The yellow house owner drinks water. Milk is
drunk in the middle house. The Norwegian lives in the first house. The cat owner
lives next to the juice drinker. The horse owner lives next to the yellow house.
The Norwegian lives next to the blue house.
Hypothesis: The Norwegian lives in the yellow house (position 1), and the fish
belongs to someone in the green or white house.
Analysis:
1. Start from the fixed facts: Norwegian in position 1, milk in position 3
2. Determine house colors using the adjacency constraints
3. Assign nationalities based on house colors and remaining constraints
4. Assign beverages based on house colors and nationalities
5. Assign pets using the remaining constraints and adjacency rules
Inference: Solve the puzzle step by step. Confirm or correct the hypothesis about
the Norwegian's house color and the fish owner's location.
Narration: Present the complete solution as a table (position, color, nationality,
beverage, pet) with the logical reasoning chain that produced each assignment.Example 4: Data Analysis
Context: An e-commerce company's conversion rate dropped from 3.2% to 2.1% over
the past month. Traffic remained stable at 500K monthly visitors. The drop
coincided with a site redesign that changed the checkout flow from 3 steps to 5
steps, added a mandatory account creation screen, and introduced a new product
recommendation carousel on the cart page. Mobile traffic is 65% of total.
Hypothesis: The mandatory account creation screen is the primary cause of the
conversion drop, accounting for 60%+ of the lost conversions, because it adds
friction at the highest-intent moment in the funnel.
Analysis:
1. Compare funnel drop-off rates at each step: pre-redesign (3 steps) vs.
post-redesign (5 steps)
2. Identify which specific step has the highest new abandonment rate
3. Segment the data by device type (mobile vs. desktop) to see if mobile users
are disproportionately affected
4. Check the account creation step completion rate vs. the old guest checkout rate
5. Measure whether the product recommendation carousel increases cart
modifications or just adds load time
Inference: Quantify the contribution of each change to the overall conversion drop.
Determine if the hypothesis about account creation is correct or if the additional
steps and carousel are larger factors. Identify whether the impact differs
significantly between mobile and desktop users.
Narration: Deliver the analysis as a conversion funnel report with: a waterfall
chart description showing where users drop off, the estimated revenue impact per
change, and a prioritized list of recommended reversions or fixes.Example 5: Scientific Hypothesis
Context: A greenhouse experiment is testing whether LED grow lights with a higher
blue-to-red ratio (3:1 vs. the standard 1:2) affect tomato plant growth. After
6 weeks, the 3:1 blue-red group shows 15% shorter stems but 40% more leaf surface
area compared to the control group. Fruit production has not started in either
group. Both groups receive identical water, nutrients, and temperature conditions.
Hypothesis: The higher blue light ratio is causing compact vegetative growth with
increased photosynthetic capacity, which will translate to higher fruit yield once
flowering begins because the plants have more energy-producing leaf area.
Analysis:
1. Review existing research on blue light effects on tomato morphology and
photosynthesis rates
2. Evaluate whether the shorter stem height indicates stress or efficient growth
3. Calculate the estimated photosynthetic capacity difference based on leaf
surface area
4. Assess whether compact growth with more leaves is advantageous or disadvantageous
for fruit production in greenhouse conditions
5. Identify potential confounding variables (light intensity differences, spectral
overlap effects)
Inference: Determine whether the observed growth pattern is likely beneficial for
eventual fruit yield or whether it signals a problem. Assess confidence level in
the hypothesis given that fruit production data is not yet available.
Narration: Write a mid-experiment assessment memo with: current observations
summary, hypothesis evaluation with confidence level, recommended adjustments
to the experiment if any, and a timeline for when fruit production data should
confirm or refute the hypothesis.Example 6: Decision Matrix
Context: A marketing team with a $50K quarterly budget needs to choose between
three campaign strategies for a B2B SaaS product (ACV $15K, sales cycle 4 months).
Option A: LinkedIn ads targeting CTOs ($25 CPM, estimated 2% CTR). Option B:
Content marketing with SEO, producing 12 long-form articles per quarter (each
costing $2K to produce). Option C: Sponsoring 4 industry podcasts ($8K per
sponsorship, estimated 50K listeners each). Current organic traffic is 20K monthly
visits with a 0.5% conversion to demo requests.
Hypothesis: Content marketing (Option B) will generate the highest 12-month ROI
because the compounding nature of SEO traffic will outpace the linear returns of
ads and sponsorships after month 6.
Analysis:
1. Calculate the expected pipeline value per dollar spent for each option over
3, 6, and 12 months
2. Model the traffic growth curve for content marketing assuming standard SEO
ramp-up timelines
3. Estimate the lead quality difference: which channel produces prospects closest
to purchase intent?
4. Assess the time-to-first-result for each option
5. Calculate the break-even point for each strategy
Inference: Determine whether the hypothesis holds at each time horizon. Identify
whether a blended approach (splitting budget across options) outperforms any
single strategy. Flag the assumptions most likely to be wrong.
Narration: Present a decision matrix comparing all three options across ROI at
3/6/12 months, time to first lead, lead quality score, and scalability. Include
a recommended allocation with quarterly milestones.Example 7: Strategic Planning
Context: A 200-person software company generates $20M ARR, growing 25% YoY. 80%
of revenue comes from a single product (project management tool). The CEO wants
to launch a second product (time tracking) to reduce concentration risk. The
engineering team has 60 developers, 45 of whom work on the core product. Competitors
in time tracking include two established players with 70% market share combined.
Hypothesis: Building a time tracking product internally will dilute engineering
focus and slow core product growth by 10-15% without reaching meaningful revenue
($2M+ ARR) within 18 months, making acquisition of a smaller time tracking
startup a better path to diversification.
Analysis:
1. Estimate the engineering allocation required to build a competitive time
tracking MVP (based on feature parity with the simpler of the two competitors)
2. Model the impact on core product roadmap velocity if 15 developers are
redirected
3. Research acquisition targets: small time tracking companies with $500K-2M ARR
that could integrate with the existing product
4. Compare the 18-month total cost of build vs. buy (salaries, opportunity cost,
integration effort)
5. Assess the go-to-market advantage of each approach (cross-sell to existing
customers vs. acquiring an existing user base)
Inference: Determine whether build or buy better achieves the diversification goal
within the CEO's timeline. Identify the key risk for each path and the conditions
under which the other option becomes preferable.
Narration: Deliver an executive briefing with: a build vs. buy comparison table,
a recommended approach with 18-month timeline, the three biggest risks with
mitigation strategies, and the decision criteria for a go/no-go checkpoint at
month 6.CHAIN vs TRACE vs SCOPE: When to Use Each
| Criteria | CHAIN | TRACE | SCOPE |
|---|---|---|---|
| Best for | Reasoning, analysis, debugging | Technical tasks, development | Content creation, planning |
| Core strength | Hypothesis-driven logic | Example-guided precision | Format and structure control |
| Reasoning depth | Very high | High | Medium |
| Speed | Slower (thorough) | Medium | Faster |
| When accuracy is critical | First choice | Strong second | Not ideal |
| When format matters most | Good (Narration stage) | Good (Examples stage) | Excellent (Execution stage) |
| Learning curve | Steepest | Moderate | Gentlest |
- Need to think through a problem? Use CHAIN
- Need to build or fix something technical? Use TRACE
- Need to produce structured content? Use SCOPE
- Need a quick answer with minimal setup? Use A.P.E.
- Need expert role-based output? Use R.A.C.E.
5 Common Mistakes with CHAIN Prompting
1. Skipping the Hypothesis
Many people jump straight from Context to Analysis, treating CHAIN like a generic structured prompt. Without a hypothesis, the analysis lacks direction. The AI examines everything equally instead of testing a specific claim, producing a broad but shallow output.
Fix: Always state a hypothesis, even if you are genuinely unsure. "I suspect X because of Y" is enough. The AI can refute it, and that refutation is valuable.
2. Writing Analysis Without Sub-Questions
Saying "Analyze the situation" is like telling a researcher "go study things." Without specific dimensions to examine, the AI decides what to focus on, and it may choose poorly.
Fix: List 3-7 numbered sub-questions. Each should be answerable independently, and together they should cover the problem. If you cannot think of sub-questions, you probably need more Context first.
3. Treating Inference as a Summary
The Inference stage should generate new insight by connecting findings across the Analysis sub-questions. If your Inference prompt says "summarize the findings," you are wasting the most valuable stage of the framework.
Fix: Ask for patterns, correlations, contradictions, and a verdict on the hypothesis. Use phrases like "identify which factors interact," "determine whether the evidence supports or refutes the hypothesis," and "surface any unexpected connections."
4. Overloading Context with Irrelevant Details
Including every possible detail makes the prompt long and dilutes the AI's focus. If a detail would not change how an expert approaches the problem, leave it out.
Fix: Apply the "would this change the recommendation?" test to each piece of context. Your company's founding year probably does not matter for a debugging problem. Your database version definitely does.
5. Forgetting the Reasoning Trail in Narration
If your Narration stage just says "give me the answer," you lose CHAIN's biggest advantage: transparency. You cannot verify reasoning you cannot see.
Fix: Always ask for the reasoning trail in the output. Phrases like "show how each analysis step supports the conclusion" or "include the evidence chain" ensure the AI does not just give you a bottom line.
Tips for Different AI Models
ChatGPT (GPT-4, GPT-4o)
- GPT-4 responds well to CHAIN's structure and will typically follow all five stages faithfully
- For complex problems, consider using the "Custom Instructions" feature to set the CHAIN template as your default reasoning format
- GPT-4o sometimes compresses the Analysis stage; add "examine each sub-question in a separate section" to prevent this
Claude (Claude 3.5 Sonnet, Claude 4)
- Claude excels at the Inference stage and will often surface connections you did not anticipate
- Claude tends to be thorough with Analysis sub-questions, so you can sometimes list fewer and let it expand
- For very long CHAIN prompts, use Claude's extended context window to include relevant data directly in the Context stage
Gemini
- Gemini benefits from more explicit Narration instructions; specify section headers and formatting requirements
- For math-heavy Analysis stages, Gemini performs best when you ask it to show calculations step by step within each sub-question
- Consider using Gemini's grounding features to verify factual claims in the Context stage
Open-Source Models (Llama, Mistral)
- Smaller models may struggle with all five CHAIN stages in a single prompt; consider splitting into two prompts (C-H-A, then I-N with the analysis results)
- Be more explicit with formatting instructions in the Narration stage
- The Hypothesis stage is especially valuable for smaller models because it constrains the reasoning space
Frequently Asked Questions
What is chain-of-thought prompting?
Chain-of-thought (CoT) prompting is a technique where you include intermediate reasoning steps in your prompt to help AI models solve complex problems. Introduced by Wei et al. at Google in 2022, it dramatically improves accuracy on tasks requiring math, logic, and multi-step reasoning. The simplest form is adding "Let's think step by step" to your prompt, but structured approaches like CHAIN produce more reliable results on complex problems.
Does chain-of-thought prompting work with all AI models?
CoT works best with large language models (roughly 100+ billion parameters). Wei et al. found that chain-of-thought reasoning is an emergent property of scale, meaning smaller models do not benefit as much. For current frontier models like GPT-4, Claude, and Gemini, CoT is highly effective. For smaller open-source models, structured CoT (like CHAIN) helps more than unstructured "think step by step" prompts because it constrains the reasoning to specific, manageable steps.
How is CHAIN different from just saying "think step by step"?
"Think step by step" tells the AI how to reason (sequentially) but not what to reason about. CHAIN adds three critical elements: (1) a testable hypothesis that gives the reasoning a direction, (2) explicit analysis sub-questions that ensure nothing important gets skipped, and (3) a narration stage that converts reasoning into a specific deliverable format. On complex multi-factor problems, this directed approach produces significantly more accurate and useful outputs than open-ended step-by-step reasoning.
When should I NOT use chain-of-thought prompting?
Skip CoT and CHAIN for simple factual questions ("What is the population of Tokyo?"), straightforward formatting tasks, basic creative writing, and any task where the answer does not require multi-step reasoning. Adding chain-of-thought structure to simple tasks wastes tokens and can actually introduce errors by making the model overthink. As a rule of thumb, if the task has a single obvious answer that does not require weighing evidence or performing calculations, a direct prompt will work better. For lighter-weight structured prompting on simpler tasks, try the SMART framework.
Can I combine CHAIN with other frameworks?
Yes. CHAIN pairs well with R.A.C.E. for the Context stage (use Role and Context from R.A.C.E. to build a richer CHAIN Context). You can also use TRACE for the Analysis stage when the problem is technical and benefits from worked examples. The Narration stage can borrow format specifications from SCOPE's Execution component. As you become comfortable with multiple frameworks, mixing components from each becomes a natural part of advanced prompt engineering. See Best AI Prompt Frameworks in 2026 and GPT-5 and GPT-4 Prompting Guide for more on combining techniques.

Keyur Patel is the founder of AiPromptsX and an AI engineer with extensive experience in prompt engineering, large language models, and AI application development. After years of working with AI systems like ChatGPT, Claude, and Gemini, he created AiPromptsX to share effective prompt patterns and frameworks with the broader community. His mission is to democratize AI prompt engineering and help developers, content creators, and business professionals harness the full potential of AI tools.
Related Articles
Explore Related Frameworks
A.P.E Framework: A Simple Yet Powerful Approach to Effective Prompting
Action, Purpose, Expectation - A powerful methodology for designing effective prompts that maximize AI responses
COAST Framework: Context-Optimized Audience-Specific Tailoring
A comprehensive framework for creating highly contextualized, audience-focused prompts that deliver precisely tailored AI outputs
RACE Framework: Role-Aligned Contextual Expertise
A structured approach to AI prompting that leverages specific roles, actions, context, and expectations to produce highly targeted outputs
Try These Related Prompts
Unlock Hidden Prompts
Discover advanced prompt engineering techniques and generate 15 powerful prompt templates that most people overlook when using ChatGPT for maximum results.
Absolute Mode
A system instruction that enforces direct, unembellished communication focused on cognitive rebuilding and independent thinking, eliminating filler behaviors.
Weekly Planner Prompt Template (Copy & Paste)
Turn ChatGPT into your weekly planning accountability buddy. Set, track, and review your top priorities each week with structured check-ins and action steps.