What Is Chain of Thought Prompting? Definition and Examples
Quick answer
Chain of thought prompting explained: the definition, few-shot and zero-shot versions, a prompt-building code example, and when to skip it.
Chain of thought prompting is a way of asking a large language model to write out its intermediate reasoning steps before giving a final answer. Instead of jumping to a result, the model works through the problem in sequence, which tends to help on multi-step tasks such as arithmetic word problems and planning.
Key takeaways
- A chain of thought is a series of intermediate reasoning steps written out before the answer.
- It can be triggered with worked examples (few-shot) or with a single phrase such as "Let's think step by step" (zero-shot).
- It suits multi-step problems and is wasted effort on simple lookups or formatting.
- The reasoning written by a model is useful but should still be checked.
On this page:
- What chain of thought prompting means
- How it works, with a prompt-building example
- Where it is used
- Common mistakes and confusions
- Related terms
- Frequently asked questions
| Technique | What you give the model | Best for |
|---|---|---|
| Direct prompting | Only the question | Simple lookups, formatting |
| Few-shot prompting | A few input and output examples | Fixing a format or label set |
| Few-shot chain of thought | Examples that include the reasoning steps | Multi-step arithmetic and logic |
| Zero-shot chain of thought | The question plus "Let's think step by step" | Quick reasoning with no examples to hand |
What does chain of thought prompting mean?
It means prompting a model so that it produces its reasoning, not just its answer. In their paper, Wei and co-authors (Jason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma, Brian Ichter, Fei Xia, Ed Chi, Quoc Le and Denny Zhou) define a chain of thought as a series of intermediate reasoning steps. The paper appeared at the NeurIPS 2022 conference and was first posted to arXiv on 28 January 2022.
The authors report that reasoning abilities emerge naturally in sufficiently large language models when a few chain of thought demonstrations are given as exemplars in the prompt. The abstract does not give a size threshold, so treat "sufficiently large" as a general statement. According to the NeurIPS abstract, one 540-billion-parameter model prompted with eight exemplars reached state-of-the-art accuracy on the GSM8K benchmark of math word problems.
How does chain of thought prompting work?
You show the model what good reasoning looks like, or you ask for it. In the few-shot form, each exemplar contains a question, the worked steps and the answer. The model tends to copy that pattern for the new question.
An illustrative example: "A shop in Pune sells 3 packets of biscuits at Rs 40 each and gives Rs 15 off. What is the bill?" A direct answer may skip the steps. A chain of thought answer reads: "3 x 40 = 120. 120 - 15 = 105. Answer: Rs 105."
The zero-shot version needs no examples. According to Kojima et al. on arXiv, adding "Let's think step by step" before each answer makes large language models decent zero-shot reasoners, and the authors report that it significantly outperforms plain zero-shot prompting on diverse reasoning benchmarks.
The snippet below builds a few-shot chain of thought prompt. It needs no API; it only prints the text you would send to a model of your choice.
examples = [
("A pen costs Rs 10. How much do 4 pens cost, with Rs 5 off?",
"4 x 10 = 40. 40 - 5 = 35.", "Rs 35"),
("A bus ticket is Rs 25. What do 3 tickets cost?",
"3 x 25 = 75.", "Rs 75"),
]
question = "A shop in Pune sells 3 packets of biscuits at Rs 40 each and gives Rs 15 off. What is the bill?"
prompt = ""
for q, steps, ans in examples:
prompt += f"Q: {q}\nReasoning: {steps}\nAnswer: {ans}\n\n"
prompt += f"Q: {question}\nReasoning:"
print(prompt)Sending this to a model is up to your provider. For the zero-shot version, drop the examples and end the prompt with "Let's think step by step."
Where is chain of thought prompting used?
It is used for tasks that need several steps: word problems, rule-based decisions and planning. An illustrative Indian case: a support team asks a model to work out a refund amount from an order value, a coupon and a delivery fee, and wants each step visible so an agent can check it.
A simple decision rule: use it when a human would need pen and paper, and skip it for simple lookups or formatting tasks. This is general guidance, not a measured result.
What are the common mistakes and confusions?
- Trusting the steps blindly. A fluent chain can still contain an arithmetic slip, so verify important numbers.
- Using it everywhere. Extra reasoning text adds length and cost on tasks that do not need it.
- Confusing it with few-shot prompting. Few-shot is about giving examples. Chain of thought is about showing steps. They combine in the few-shot chain of thought form.
Which terms are related?
Read few-shot prompting for the example-driven side. For wider context, see what prompt engineering is, how to write effective AI prompts and the complete prompt engineering guide. To choose between techniques, see prompt engineering vs RAG vs fine-tuning.
Next step
Take one multi-step question you care about, write two worked examples, and compare the answers with and without the steps. Keep the version that is easier to check. More prompts to try are in AI prompt examples.
Frequently asked questions
What is chain of thought prompting?
It is a prompting method in which a large language model writes out intermediate reasoning steps before the final answer. The steps can be shown through worked examples or requested with a phrase such as Let's think step by step.
Who introduced chain of thought prompting?
Jason Wei and co-authors, in a paper first posted to arXiv on 28 January 2022 and presented at NeurIPS 2022. It describes a chain of thought as a series of intermediate reasoning steps.
What is zero-shot chain of thought?
Zero-shot chain of thought adds a phrase such as Let's think step by step before the answer, with no worked examples. Kojima and colleagues reported that it significantly outperforms plain zero-shot prompting on diverse reasoning benchmarks.
When should I use chain of thought prompting?
Use it for multi-step tasks such as arithmetic word problems, rule-based decisions and planning. Skip it for simple lookups or formatting, where the extra text only adds length.
Does chain of thought work with every model?
Not equally. The original paper says reasoning abilities emerge in sufficiently large language models, and the abstract gives no size threshold. Test it on your own model and tasks.