No history yet

Reasoning Patterns

Beyond Simple Instructions

Getting a large language model to answer a direct question is one thing. Guiding it through a complex problem that requires multiple steps of reasoning is another entirely. For tasks involving logic, math, or planning, simply asking for the final answer often leads to mistakes. The model might guess or miss a crucial step in the logical sequence.

To solve this, we can move beyond simple 'ask-and-receive' interactions and into more structured reasoning frameworks. The foundational technique is called Chain-of-Thought prompting.

Chain-of-thought (CoT) prompting generates a sequence of short sentences to describe reasoning logics step by step, known as reasoning chains or rationales, to eventually lead to the final answer.

Instead of just asking for the answer, you prompt the model to 'show its work.' This externalizes the reasoning process, making it transparent and much more likely to be correct. It's like doing a math problem on paper instead of in your head. When the steps are visible, it's easier to catch errors.

Thinking Step by Step

The easiest way to activate this reasoning pattern is with prompting. It works by simply adding a phrase like "Let's think step by step" to the end of your question. This small nudge encourages the model to break down its thinking process before giving the final answer. It's a surprisingly effective technique for a wide range of problems, tapping into the model's emergent reasoning abilities without needing complex examples.

## Standard Prompt

Q: A juggler has 15 balls. He buys two more cans of balls, and each can has 3 balls. How many balls does he have now?
A:

## Zero-Shot CoT Prompt

Q: A juggler has 15 balls. He buys two more cans of balls, and each can has 3 balls. How many balls does he have now?
A: Let's think step by step.

The first prompt might just spit out a number, which could be wrong. The second prompt encourages a response that looks more like this:

First, calculate the total number of new balls. The juggler buys 2 cans, and each can has 3 balls, so 2 * 3 = 6 new balls. Next, add the new balls to the balls he already had. He started with 15 balls, so 15 + 6 = 21 balls. The juggler now has 21 balls.

For more control, you can use Manual CoT, also known as Few-Shot CoT. Here, you provide the model with one or more high-quality examples of the reasoning process you want it to follow. This gives it a clear template to imitate.

Q: The cafeteria had 23 apples. If they used 20 to make lunch and bought 6 more, how many apples do they have?
A: The cafeteria started with 23 apples. They used 20 for lunch, so they had 23 - 20 = 3 apples left. Then they bought 6 more, so now they have 3 + 6 = 9 apples. The answer is 9.

Q: Roger has 5 tennis balls. He buys 2 cans of tennis balls. Each can has 3 tennis balls. How many tennis balls does he have now?
A:

By providing a demonstration, you guide the model to adopt a specific reasoning structure, which is especially useful for niche or complex problem domains.

From One Path to Many

Even with Chain-of-Thought, an LLM can still make a logical error or a simple arithmetic mistake in its reasoning chain. If the task is critical, how can you increase your confidence in the result? One powerful technique is called decoding.

The idea is simple but effective. Instead of generating just one reasoning path, you prompt the model to generate several. You can do this by increasing the 'temperature' parameter in your API call, which makes the output more random. You then look at all the final answers and choose the one that appears most often. It’s a majority vote.

This method works because even if some reasoning chains have errors, the majority of paths are likely to converge on the correct answer. It significantly improves performance on arithmetic and commonsense reasoning tasks.

Exploring Branches of Thought

Some problems are too complex for a single, linear chain of thought. Planning a trip, for example, involves exploring many options and backtracking when a path doesn't work. For these kinds of problems, a more advanced technique called (ToT) is useful.

ToT generalizes CoT by allowing the model to explore multiple reasoning paths at each step. It treats the problem-solving process as a tree, where each node is a 'thought' that contributes to the final solution. The model can generate multiple thoughts at each step, evaluate their viability, and decide which path to pursue, backtrack from, or explore further.

Lesson image

This structure allows the model to perform deliberate search and planning. For example, you can prompt the model to:

  1. Decompose the problem into a few intermediate steps.
  2. For each step, generate several possible next thoughts.
  3. Evaluate the progress made by each thought.
  4. Prune the less promising branches and continue exploring the best ones.

This makes it possible to tackle complex tasks that require foresight and strategic exploration, moving beyond linear reasoning into a more dynamic and robust problem-solving process.

Quiz Questions 1/6

What is the primary purpose of Chain-of-Thought (CoT) prompting?

Quiz Questions 2/6

You want an LLM to solve a logic puzzle but don't have any pre-written examples of the reasoning process. Which technique is the most efficient way to get started?

By moving from simple questions to structured reasoning, you can unlock a much higher level of performance from LLMs for complex, multi-step tasks.