# Chain-of-Thought

> The Chain-of-Thought is a prompting technique that asks a model to reason step by step before answering.

## What is chain-of-thought prompting?

The technique of asking a model to work through intermediate reasoning steps before giving the final answer. Improves results on logic, math and multi-step problems and makes the reasoning easier to verify.

- Topic: Prompting
- Type: technique

## Example

Wrong:

```js
const res = await llm.generate({ prompt: `${question}\nThink step by step.` });
const answer = Number(res.text);
```

Right:

```js
const res = await llm.generate({
  prompt: `${question}\nThink step by step, then give the result in <answer></answer>.`,
});
const match = res.text.match(/<answer>(.*?)<\/answer>/s);
const answer = match ? Number(match[1]) : null;
```

Tags separate the reasoning from the result, so code parses only the final answer.

## Common mistakes

- Parsing the reasoning text as if it were the answer.
- Asking a reasoning model to think step by step and only adding cost and latency.

## Key points

- The final answer is placed in a separate, parsable part, apart from the reasoning.
- Code parses only the final answer, not the whole reasoning text.
- Step-by-step reasoning is not shown to end users when it may contain internal data.

## Interview questions

### Does chain-of-thought help reasoning models?

Usually not much. Reasoning models already think before answering, so explicit step-by-step prompts mostly add tokens.

### Is chain-of-thought reasoning always faithful?

No. The written steps may not match how the model reached the answer, so check the result, not only the reasoning.

### When should I use chain-of-thought prompting?

For multi-step tasks like math, logic or planning, with models that do not reason by default.

## Related cards

- [Reasoning Model](https://wonderium.dev/ai/reasoning-model.md)
- [Reasoning Effort](https://wonderium.dev/ai/reasoning-effort.md)
- [Prompt Engineering](https://wonderium.dev/ai/prompt-engineering.md)
- [ReAct Pattern](https://wonderium.dev/ai/react-pattern.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/chain-of-thought
- Last updated: 2026-11-25
