liveBook · Manning

Chain-of-thought prompting

As explained in Transformers in Action

Chain-of-thought prompting guides a language model by providing or eliciting a sequence of intermediate reasoning steps before the final answer.

Chain-of-thought prompting guides a language model through a sequence of natural reasoning steps before it produces a final answer. It decomposes complex problems into intermediate steps, helping the model connect a question’s semantics to its conclusion rather than mapping the input directly to one answer. section 4.2.3

Use the technique when:

  • Provide a few worked reasoning demonstrations for multistep tasks such as text-based arithmetic and commonsense reasoning. section 4.2.3
  • Prefer intermediate reasoning over showing only a correct answer when the model must translate several semantic relationships into an equation or conclusion. section 4.2.3
  • Separate reasoning from the conclusion when downstream systems need controlled, machine-readable output for verification, grading, or refinement. section 4.2.4
  • Improve robustness by sampling multiple reasoning paths and selecting the most frequent final result through self-consistency. section 4.2.4

Arithmetic commonsense reasoning

For a question about Roger starting with 5 balls and receiving two cans of 3 tennis balls, a direct answer says “The answer is 11.” A CoT demonstration instead states: “Roger started with 5 balls, 2 cans of 3 tennis balls each is 6 tennis balls. 5 + 6 = 11.” The intermediate calculation links the wording to the result. section 4.2.3

Structured chain of thought

Define a Pydantic schema with separate `chain_of_thought` and `final_answer` fields, then use Instructor with an OpenAI client to request a response matching that schema. Printing the two fields keeps reasoning and conclusion distinct and auditable. section 4.2.4

Figure 4.7 How CoT prompting enables LLMs to tackle complex tasks such as arithmetic commonsense reasoning. The processes for CoT are highlighted. Image is taken from [1].
figure

Compare standard prompting with CoT prompting as the reasoning path transforms a complex arithmetic or commonsense task into intermediate steps and a final answer. section 4.2.3

How Transformers in Action covers it

How deep it goes
Explains decomposition, demonstrations, structured outputs, and self-consistency, but does not detail model internals.
Examples
Uses arithmetic commonsense reasoning, the Roger tennis-ball problem, and a cube-root request with a structured response schema.
What it assumes
Assumes familiarity with prompts and language-model generation while teaching intermediate-step decomposition from basic examples.
What you can do after
Apply it via few-shot demonstrations, structured schemas, and repeated sampling for more inspectable reasoning outputs.
How it connects
Connects few-shot prompting, structured output, Pydantic, Instructor, self-consistency, and tree-of-thought prompting.

Also explained in

Compare how 18 books explain chain-of-thought prompting →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Transformers in Action. The section links point to the parts of the book it draws on.