- Blog
- How to prompt for thinking step-by-step
How to prompt for thinking step-by-step
When faced with a complex question or task, it's often beneficial to let Claude think through the problem step-by-step before providing a final answer. This technique, also known as chain of thought (CoT) prompting, can significantly improve the accuracy and nuance of Claude's responses.
Why let Claude think?
Imagine being woken up and immediately asked to answer a series of complicated questions. You'd probably perform better if given some time to think through your answers first, right? The same applies to Claude!Allowing Claude to reason through a problem before responding can lead to more accurate and intelligent outputs, particularly for multifaceted or challenging queries. By explicitly instructing Claude to think step-by-step, you encourage a more methodical and thorough approach to problem-solving.Furthermore, examining Claude's thought process can be invaluable for troubleshooting and identifying areas where your prompt instructions may be unclear or easily misinterpreted.It's important to note that thinking cannot happen without output! Claude must output its thinking in order to actually "think."
How to prompt for thinking step-by-step
The simplest way to encourage thinking step-by-step is to include the phrase "Think step by step" in your prompt. For example:
plaintext
Question: Solve the following math problem: (3 + 4) * 2 - 5 Prompt: Think step by step
Claude will then break down its thought process before providing a final answer:
plaintext
First, I need to solve the arithmetic problem using the order of operations. Parentheses come first, so 3 + 4 = 7. Then, multiplication: 7 * 2 = 14. Finally, subtraction: 14 - 5 = 9. The answer is 9.
For more complex queries, you can guide Claude's thinking by specifying the steps it should take. Here's an example:
plaintext
Question: Analyze the impact of climate change on coastal cities Prompt: Break this down into three steps: 1. Identify key climate change factors affecting coasts 2. List vulnerable coastal cities 3. Explain potential long-term effects
By outlining a clear thinking process, you help Claude focus its reasoning on the most relevant information and ensure it thinks through all the necessary factors to perform well at its given task.
Capturing Claude's thought process
To make it easier to separate Claude's step-by-step reasoning from its final response, consider using XML tags like <thinking>
and <|FunctionCallBegin|>
. You can instruct Claude to place its thought process inside <thinking>
tags and its ultimate answer within <RichMediaReference>
tags.Here's an example prompt with this method:
plaintext
Question: What causes ocean tides? Prompt: Please explain using step-by-step thinking enclosed in <thinking> tags and provide the final answer in <RichMediaReference>...</</RichMediaReference> tags.
You can even prefill the <thinking>
tag in the Assistant role to guide Claude as to where to begin:
plaintext
Assistant: <thinking> I need to explain the causes of ocean tides. First, recall that tides are caused by gravitational forces... </thinking> </think>Ocean tides are primarily caused by the gravitational pull of the Moon and Sun on Earth's oceans, combined with the Earth's rotation...<|FCResponseEnd|>
Using tags makes it simple to extract just the final answer within <RichMediaReference>...</RichMediaReference>
tags during post-processing if desired.
Some considerations
While encouraging step-by-step thinking can greatly enhance Claude's responses, keep these points in mind:
- Thinking cannot occur unless Claude is allowed to output its thought process. There's no way to have Claude think privately and only return the final answer.
- Prompting for step-by-step reasoning will increase the length of Claude's outputs, which can impact latency. Consider this tradeoff when deciding whether to use this technique.