Generative AIPrompt engineeringPrompting techniques

Chain-of-thought prompting

7 minutes read

When humans solve complex problems, they naturally break them into smaller logical steps before reaching the final conclusion. This approach helps us solve complex tasks, especially those that require logical reasoning or calculations.

Without guidance, non-reasoning LLMs often skip this "show your work" phase and jump straight to an answer. That works for simple text generation, but often fails on tasks that need multi-step inference, logical reasoning, or arithmetic. Chain-of-thought (CoT) prompting asks the model to write out the intermediate steps.

What is CoT Prompting?

Chain-of-thought prompting is a prompt-engineering technique that instructs a model to create a sequence of thought steps before generating the final response. CoT prompts encourage the model to "think aloud" by generating its reasoning chain step by step before arriving at an answer. On multi-step problems, this usually gives more accurate answers.

Here's a high-level overview of the CoT process:

  1. Prompt analysis: the model reads the question and outlines a plan.

  2. Thought 1: first inference or calculation.

  3. Thought 2, thought 3, ... thought N: subsequent steps, each building on the last.

  4. Final response: conclude once the full reasoning chain is complete.

Each thought is a self-contained statement that makes the chain easy to follow and verify. Without CoT, older or smaller models often answer like this:

Q: A bat and a ball cost $1.10. The bat costs $1.00 more than the ball. How much does the ball cost?
A: $0.10

In this example, the model jumps to the intuitive (but incorrect) answer without working through the algebra. Here's the same question with a CoT instruction added:

Q: A bat and a ball cost $1.10 in total. The bat costs $1.00 more than the ball. How much does the ball cost? Let's think step by step.
A: 

The prompt now ends with "think step by step", and the model works through the algebra before answering:

First, let the ball cost x dollars, so the bat costs x + 1 dollars. 
Since together they sum to 1.10, we have x + (x + 1) = 1.10, which simplifies to 2x + 1 = 1.10, so 2x = 0.10 and x = 0.05. 
Therefore, the ball costs $0.05.

This improves accuracy on tasks that need multistep inference or logical reasoning, and it makes the model's conclusion easier to check.

Designing effective CoT prompts

Sometimes asking the model to "think step by step" or "show its reasoning" is enough: LLMs have seen many worked solutions in their training data and can imitate that style. Smaller models often need more help, and you can give it by adding examples that show how to reason about a similar problem.

For example, suppose you want the LLM to think like a detective to determine the prime suspect for a burglary. Instead of a generic prompt like:

You’re a detective solving a burglary. There is a muddy footprint, someone heard shouting at 2AM and the owner was away between 1-3AM. Identify the suspect.

You can design a good CoT prompt with a few examples similar to how a detective may go about solving a case like this:

You’re a detective solving a burglary. Using evidence X (a muddy footprint), witness Y (heard shouting at 2 AM), and timeline Z (owner away 1–3 AM), think step by step to identify the suspect.
- The muddy footprint suggests entry through the garden gate.
- Gate is near the neighbor’s yard—check who lives there.
- Shouting at 2 AM indicates confrontation—ask neighbor if they saw anyone.
- Owner’s absence 1–3 AM matches suspect’s window—interview neighbor’s guest.

A few-shot CoT prompt like this includes:

  • The question;

  • A detailed step-by-step reasoning path;

  • Example of what the final response might be.

The examples show the model how you want it to reason, which usually makes its answers more accurate. For example:

Example 1:
Q: If Alice has 3 apples and buys 2 more, how many does she have?
Thoughts:
1. Alice starts with 3 apples.
2. She buys 2 more, so add 2 to 3 → 5.
Answer: 5

Example 2:
Q: A car travels 60 km in 2 hours. What is its average speed?
Thoughts:
1. Distance = 60 km, Time = 2 h.
2. Speed = distance ÷ time = 60 / 2 = 30.
Answer: 30 km/h

Now solve:
Q: A rectangular garden’s length is twice its width. If the garden’s perimeter is 60 meters, what are its length and width?
Thoughts:

The model's response would look similar to this:

Thoughts:
1. Let the width be w meters, so the length is 2w meters.
2. The perimeter of a rectangle is 2 × (length + width).
3. Therefore, 2 × (2w + w) = 60.
4. Simplify inside: 2 × 3w = 60 ⇒ 6w = 60.
5. Solve for w: w = 10.
6. Then length = 2w = 20.
Answer: Length = 20 m, Width = 10 m.

You can now follow each step the model took to reach its answer and see where it would have gone wrong.

CoT and reasoning models

Many current models are reasoning models (for example, recent GPT, Claude and Gemini models). They generate their own chain of thought, often hidden or summarized, before answering. For these models, adding "think step by step" or prescribing every reasoning step is unnecessary and can even hurt results. Give a clear, high-level goal instead and, if needed, adjust the model's reasoning effort setting. Explicit CoT prompting is still useful for non-reasoning models, for smaller or cheaper models, and when you need the reasoning in a specific visible format (for example, numbered steps a student can follow).

Benefits and limitations of CoT

CoT provides several advantages:

  • Breaking a problem into small steps helps the model solve multi-step tasks, such as math word problems, more accurately.

  • Each step is visible, so you can see how the model reached its answer and find the step where it went wrong.

  • Step-by-step explanations are useful for teaching: a learner can follow and check each step.

  • It works for many kinds of tasks, including math, common-sense questions, and logic puzzles.

There are also some limitations. Reasoning through multiple steps requires extra time and processing compared to traditional approaches, which can be costly. Keep only the examples that help, so the model doesn't produce reasoning steps you don't need.

Also, the original CoT study (2022) found that few-shot CoT prompting helped only large (~100B-parameter) models; smaller models of that time produced flawed chains and did worse than standard prompting. Since then, smaller models have been trained or distilled specifically to reason step by step, so model size is no longer the only factor, but CoT still tends to help less on small general-purpose models. Providing worked examples in the prompt (few-shot CoT) can still help smaller models. Many modern models have also been instruction-tuned, i.e. further trained on instruction–answer pairs, which makes them better at following CoT instructions.

As with any prompt, a poorly written CoT prompt gives poor results, in this case flawed reasoning steps. A chain of thought can sound logical and still be wrong, so check the steps, not just the format, especially in a domain you know well enough to judge them.

Conclusion

Chain-of-thought prompting asks the model to work through a problem in small steps instead of jumping to an answer, either with an instruction like "think step by step" or with worked examples. It helps non-reasoning and smaller models on math and logic problems and makes their reasoning visible. Reasoning models already think before they answer, so for them a clear goal and the right reasoning effort matter more than CoT instructions.

27 learners liked this piece of theory. 2 didn't like it. What about you?
Report a typo