Understanding Reasoning Models: Guiding LLMs to Think Step by Step

Introduction: Why Reasoning Techniques Matter

In the previous lessons, you learned how large language models (LLMs) generate text by predicting one token at a time and how different model versions can affect the quality of responses. Let's build on that foundation by exploring how you can get even better answers from LLMs — especially for complex or multi-step problems — by guiding them to "think" before answering.

When you ask a model a simple question, it often gives you a direct answer. However, for more complicated tasks, such as solving a math problem or analyzing a scenario, the model can make mistakes if it tries to answer too quickly. This is where reasoning techniques come in. Encouraging the model to break down its thought process can help it arrive at more accurate and logical answers.

Chain of Thought (CoT): The Step-by-Step Approach

The Chain of Thought (CoT) technique is a way to prompt LLMs to solve problems step by step, just like you might do on paper. Instead of asking for a final answer right away, you guide the model to show its reasoning process.

Let's see how this works, starting with a simple math problem.

Suppose you ask:

Q: What is 197 * 971?

If you ask this, the model will try to predict the next token. It can't actually do the math; it just predicts something plausible. Sometimes, it gets it right, but often, it makes a mistake, especially with large numbers or multi-step problems.

To help the model, you can add a phrase like Think step by step to your prompt. This tells the model to break down the problem:

Q: What is 197 * 971? Think step by step.

But you can be even more helpful by showing the model exactly how to break down the steps. Let's build this up together.

First, you can show the model how to multiply using place value:

Step 1: Multiply the unit digit of 197 (which is 7) by 971.
Step 2: Multiply the tens digit of 197 (which is 9) by 971, and add a zero at the end.
Step 3: Multiply the hundreds digit of 197 (which is 1) by 971, and add two zeroes at the end.
Step 4: Add all the results together.

Chain of Thought (CoT): Full Example

Now, let's put this into a full prompt, step by step:

Q: What's 212 * 385?

A: Step 1: Multiply 2 (units place of 212) by 385
       2 * 385 = 770
Step 2: Multiply 1 (tens place of 212) by 385 and add a zero at the end
       1 * 385 = 385 => 3850
Step 3: Multiply 2 (hundreds place of 212) by 385 and add two zeroes at the end
       2 * 385 = 770 => 77000
Step 4: Add all the results from steps 1, 2, and 3
       770 + 3850 + 77000 = 81620

Therefore, 212 * 385 = 81620

Q: What's 197 * 971?

In this prompt, we provide the model with a solution example for a different problem and then ask for a solution to an actual problem. This way, we show the model how to "think" properly.

By guiding the model through each step, you help it avoid mistakes and clarify its reasoning. This is the core idea behind Chain of Thought prompting.

You can use this approach for many problems, not just math. For example, you can ask the model to explain its reasoning in logic puzzles, story analysis, or code debugging.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal