Introduction
In our last lesson, we focused on few-shot learning, where you learned to guide a model by showing it examples of what you want the final output to look like. This is incredibly powerful for controlling format and style. However, for problems that require multiple logical steps—like solving a math word problem or planning a sequence of actions—simply showing the final answer isn't enough. The model might guess the right answer for the wrong reasons.
Today, we'll address this by learning how to show the model how to think. This lesson introduces Chain-of-Thought (CoT) prompting, a transformative technique that guides a model through a multi-step reasoning process before it arrives at a final answer. By making the reasoning explicit, we significantly improve the accuracy and reliability of LLMs on complex tasks, providing a crucial window into their "thought process" that is invaluable for debugging and building trust in your applications.
1. The Core Idea: Eliciting Reasoning
The concept of Chain-of-Thought was formally introduced in a groundbreaking 2022 paper by Google Research. The core idea is surprisingly simple: instead of just providing a question and a direct answer in an example, you also include the intermediate reasoning steps that a human would take.
Let's start with a short, high-level explanation of what CoT is and why it's so effective.
Chain-of-thought explained | Aravind Srinivas and Lex Fridman
In this clip from the Lex Fridman Podcast, Aravind Srinivas (CEO of Perplexity AI) provides a concise and intuitive explanation of Chain-of-Thought prompting. He describes it as a way to force the model to articulate its reasoning, thereby unlocking the intelligence compressed within its parameters.
Watch the first two minutes of the video (00:00 - 02:04). Pay close attention to how he contrasts standard prompting with CoT and the insight that we extract a model's intelligence by talking to it in natural language.
As Srinivas notes, forcing the model to generate a reasoning chain helps it avoid overfitting to superficial patterns and allows it to tackle novel problems more effectively.
To dig deeper into the original research, we'll turn to the paper that started it all.
Chain-of-Thought Prompting Elicits Reasoning in Large...
The paper 'Chain-of-Thought Prompting Elicits Reasoning in Large Language Models' provides the empirical evidence and conceptual framework for this technique. Reading excerpts from it will give you a foundational understanding of why this works.
Please read the following sections: The Abstract and Section 1 (Introduction) to understand the motivation and key results. Note the comparison in Figure 1. Section 2 (Chain-of-Thought Prompting) for a clear definition and its attractive properties (decomposition, interpretability, etc.).
The key takeaways from the paper are:
- Decomposition: CoT allows the model to break down a multi-step problem into smaller, manageable intermediate steps.
- Interpretability: It provides a window into the model's reasoning, allowing you to identify where it went wrong. This is critical for debugging and improving your prompts.
- Emergent Ability: CoT's effectiveness is an emergent property of model scale. It provides little to no benefit for smaller models but yields significant gains for models with ~100B+ parameters. This is because larger models have developed more robust internal reasoning capabilities that can be "elicited" by the prompt.
2. Applying Chain-of-Thought in Practice
There are two primary ways to implement CoT prompting, which build directly on the zero-shot and few-shot paradigms we've already covered.
a) Zero-Shot CoT
This is the simplest method and works remarkably well on modern instruction-tuned models (like GPT-4, Claude 3, Llama 3-Instruct). You simply append a magic phrase like "Let's think step-by-step." to the end of your question.
This phrase acts as a trigger, prompting the model to switch into a mode where it first generates a reasoning chain and then provides the final answer.
Example: Zero-Shot CoT
Question:
I have a budget of $150 for a team lunch. I need to buy 15 sandwiches that cost $7 each and 15 drinks that cost $2 each. After buying the sandwiches and drinks, how much money will I have left for desserts?
Let's think step-by-step.
Expected Model Output:
First, I need to calculate the total cost of the sandwiches.
15 sandwiches * $7/sandwich = $105.
Next, I need to calculate the total cost of the drinks.
15 drinks * $2/drink = $30.
Then, I'll find the total cost of the lunch so far by adding the cost of sandwiches and drinks.
$105 + $30 = $135.
Finally, I'll subtract the total cost from the budget to find the remaining money for desserts.
$150 - $135 = $15.
The answer is $15.
b) Few-Shot CoT
This is the more robust and original method, which directly extends what you learned in the previous lesson on few-shot prompting. Instead of just providing input/output pairs, you provide input/reasoning_chain/output examples.
This explicitly teaches the model the desired format and logic for its reasoning process.
Example: Few-Shot CoT
Here are some examples of solving math word problems.
---
Question: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can has 3 tennis balls. How many tennis balls does he have now?
Answer:
Roger started with 5 balls.
2 cans of 3 tennis balls each is 6 tennis balls.
5 + 6 = 11.
The final answer is 11.
---
Question: The cafeteria had 23 apples. If they used 20 to make lunch and bought 6 more, how many apples do they have?
Answer:
The cafeteria started with 23 apples.
They used 20, so they had 23 - 20 = 3 apples left.
Then they bought 6 more, so they now have 3 + 6 = 9 apples.
The final answer is 9.
---
Question: I have a budget of $150 for a team lunch. I need to buy 15 sandwiches that cost $7 each and 15 drinks that cost $2 each. After buying the sandwiches and drinks, how much money will I have left for desserts?
Answer:
By providing this pattern, the model is guided not just to give an answer, but to first lay out the logical steps, just as it saw in the examples.
For a comprehensive overview of these and other CoT variants, the following guide is an excellent resource.
Chain of Thought Prompting Guide
The 'Chain of Thought Prompting Guide' from PromptHub is a practical manual that covers the main CoT techniques with clear examples. It's a great reference for implementation.
Please read the sections 'Zero-shot Chain of Thought example' and 'Few-Shot Chain of Thought Example'. This will solidify your understanding of how to apply these two core techniques.
Test your understanding!
You are building a system to help a junior logistics coordinator plan a delivery route. The model needs to determine the total driving time, accounting for breaks.
Problem: A driver needs to go from City A to City B (4 hours), then to City C (2.5 hours). The company policy requires a 30-minute break for any trip segment longer than 3 hours. What is the total time for the journey, including driving and mandatory breaks?
Task: Write a few-shot CoT prompt to solve this problem. Include one distinct example in your prompt before posing the final question.
- Example to include: A trip from City X to City Y takes 5 hours. The policy requires a 30-minute break. The total time is 5.5 hours.
Show answer
Here is a well-structured few-shot CoT prompt for this task.
You are a logistics planning assistant. Calculate the total journey time, including mandatory breaks. The policy is to add a 30-minute (0.5 hour) break after any single driving segment that is longer than 3 hours.
---
Question: A driver needs to go from City X to City Y. The drive is 5 hours. What is the total journey time?
Answer:
The drive from City X to City Y is 5 hours.
This segment is longer than the 3-hour threshold, so a mandatory 30-minute break is required.
Total time = Driving time + Break time
Total time = 5 hours + 0.5 hours = 5.5 hours.
The final answer is 5.5 hours.
---
Question: A driver needs to go from City A to City B (4 hours), then to City C (2.5 hours). What is the total time for the journey, including driving and mandatory breaks?
Answer:
Why this works: The example demonstrates the rule-based reasoning required: check the duration of each segment, apply the break rule if the condition is met, and then sum the times. This guides the model to correctly analyze the new, two-segment problem. It will identify that the A-to-B segment needs a break but the B-to-C segment does not.
3. Interactive CoT for Development and Debugging
For an applied engineer, one of the most powerful variations of CoT is making it interactive. Instead of letting the model generate the entire chain at once, you can instruct it to present one step at a time and wait for your confirmation before proceeding. This is invaluable for debugging complex logic or co-creating a solution with the AI.
Essential AI prompts for developers
This clip from the Visual Studio Code channel demonstrates a 'stepwise Chain of Thought' prompt. It shows how you can instruct the model to perform a complex task (like refactoring code) one step at a time, waiting for a keyword like 'next' before continuing.
Watch the segment from 04:11 to 06:07. Notice the specific instruction given to the model: 'wait for the keyword next before proceeding'. This is a simple but powerful technique for controlling the generation flow.
This interactive pattern is a precursor to more complex AI agent behavior, where the model must plan, execute a step, observe the result, and then plan the next step.
4. Advanced Concepts Preview: From Chains to Trees
Chain-of-Thought is a foundational reasoning technique, but it's not the end of the story. It represents a single, linear path of reasoning. What if that path leads to a dead end or is based on a faulty initial assumption?
To address this, researchers have developed more advanced methods:
- Self-Consistency (CoT-SC): Run the same CoT prompt multiple times with a higher
temperatureto generate several different reasoning chains. Then, take the most common answer as the final one (a sort of majority vote). This improves robustness by mitigating the impact of a single flawed chain. - Contrastive Chain-of-Thought (CCoT): Provide the model with examples of both good and bad reasoning to teach it what mistakes to avoid.
- Tree-of-Thoughts (ToT): This is the next major evolution. Instead of a single chain, the model explores a tree of possible reasoning paths, evaluating the viability of different steps and pruning unpromising branches. This allows for backtracking and a more comprehensive exploration of the problem space. We will dive deep into ToT in the next module on Advanced Prompting.

Conclusion
You have now learned how to move beyond simple instruction-following and guide an LLM's reasoning process. This is a fundamental skill for unlocking high-level performance on any task that requires logic, calculation, or planning.
Key Takeaways:
- Chain-of-Thought (CoT) prompting makes a model's reasoning process explicit, significantly improving performance on complex, multi-step tasks.
- It works by instructing the model to break a problem down and "think step-by-step" before providing a final answer.
- Zero-Shot CoT uses a simple trigger phrase like "Let's think step-by-step."
- Few-Shot CoT provides examples that include the reasoning chain, creating a powerful pattern for the model to follow.
- The effectiveness of CoT is an emergent property of scale—it's most beneficial when using large, capable models.
- Interactive or stepwise CoT is a valuable technique for debugging and controlling the generation process.
What's Next?
We've now covered how to guide a model with examples (few-shot) and how to guide its reasoning (CoT). In the next lesson, we will synthesize these ideas and formalize the structure of a high-quality prompt. You will learn to design prompts that explicitly specify role, context, task, and desired output format (RCTAFT). This framework will serve as a robust checklist for constructing clear, effective, and reliable prompts for any scenario.