Skip to main content

Chain-of-Thought Prompting

Updated 3 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/chain-of-thought

In short

Chain-of-thought prompting is a technique that asks an LLM to reason through intermediate steps before its final answer, improving accuracy on complex tasks.

What is chain-of-thought prompting?

Chain-of-thought prompting means asking a language model to show its reasoning step by step instead of jumping straight to an answer. The idea was popularized by a 2022 research paper showing that models solved math word problems and logic puzzles far more accurately when their prompt included examples with worked-out reasoning. Even a simple instruction such as 'think through this step by step' can have a similar effect.

It works because an LLM generates text one token at a time, and every token it writes becomes part of the context for the next one. Writing out intermediate steps gives the model more computation and a place to keep partial results, much like scratch paper, so later steps can build on earlier ones. Many recent models, often called reasoning models, are trained to produce this kind of reasoning on their own before answering, which improves results on hard problems but uses more tokens and adds latency.

The everyday analogy is a teacher who asks students to show their work on a math exam: writing each step makes mistakes less likely and easier to spot. In applications, chain-of-thought is used for multi-step math, planning, debugging, and questions that combine several facts, and developers usually ask for the reasoning and the final answer in separate, clearly marked parts so the program can extract just the answer.

Chain-of-thought is often confused with few-shot prompting. Few-shot prompting shows the model example inputs and outputs, while chain-of-thought is about drawing out reasoning steps; the two are often combined by giving examples that include the reasoning. It is also worth knowing that a written chain of thought is not a guaranteed, faithful explanation of how the model reached its answer, and for simple lookups or classification it mostly adds cost without improving accuracy.

Key takeaways

  • Chain-of-thought prompting asks the model to reason step by step before answering.
  • Writing intermediate steps gives the model more room to compute and fewer chances to skip logic.
  • It helps most with math, logic, planning, and multi-step questions.
  • Reasoning models produce this kind of reasoning automatically, at the cost of more tokens.
  • The written reasoning is not guaranteed to reflect how the model actually decided.

Example

Asking for reasoning and a clearly marked answertypescript
// Ask for reasoning first, then a clearly marked final answer
const prompt = [
  "A store sells pens in packs of 12 for $3. How much do 60 pens cost?",
  "Think through the problem step by step.",
  "Then write the result on its own line as: ANSWER: <number>",
].join("\n");

// callModel is a placeholder for a real model client
const reply = await callModel(prompt);
// e.g. "60 / 12 = 5 packs. 5 * $3 = $15.\nANSWER: 15"

const answer = reply.match(/ANSWER:\s*(\d+)/)?.[1];
console.log(answer); // "15"

Readers ask

Does chain-of-thought prompting always improve results?

No. It helps most on problems that need several reasoning steps, such as math, logic, and planning. For simple lookups, short classifications, or formatting tasks it mostly adds tokens, cost, and latency.

What is a reasoning model?

A reasoning model is an LLM trained to produce its own chain of thought, often hidden or summarized, before giving a final answer. It usually performs better on complex problems but takes longer and uses more tokens per response.

Is the chain of thought a true explanation of the model's answer?

Not necessarily. The steps are generated text and can look convincing even when they don't match how the model actually arrived at its answer, so the reasoning should be checked rather than trusted as proof.

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings