Find helpful tutorials or share inspiring use cases on AI technology for higher education.

Shared content may not reflect the policies of Tilburg University on the use of AI. 

Become a Prompt Engineer: Understand and Apply Multi-step & Chain-of-Thought Prompting

Thanks for tuning in to the sixth part of the prompt engineering series. We will take one major step forward in this article towards becoming prompt engineers. But, to become proficient, we have to progress step by step, much like AI models. Yes, we are getting close to the point. Let’s explore multi-step and chain-of-thought prompting, which breaks down multiple or complex tasks into smaller pieces to reach the final output.

By the end of this part you will be able to:

  • Understand and implement multi-step prompting to break down complex tasks into minto simpler, manageable steps for the model.
    • Implement multi-step prompting in scenarios that require logical consistency and multiple stages of transformation.
  • Use chain-of-thought prompting to lead the model through intermediate reasoning steps, improving clarity and reducing errors.

Multi-Step Prompting

Multi-step prompting is a method that directs the behavior of the model to generate effective outputs by breaking down an end goal into a series of smaller, manageable steps. The model goes through each prompt step before giving the final output. These steps make it easier for the model and increase the chance of success. Therefore, this style of prompting is useful for the following type of taks:

  • Sequential tasks, such as generating a coherent text based on a given outline, benefit from multi-step prompts because they often need to complete a series of steps in a specific order. This is what we also saw in the second article with the Inner Monologue, where we gave step-by-step instructions to create a proof exam assistant.
  • Cognitive tasks, such as assessing the correctness of a solution, can also benefit from using multi-step prompts because they involve cognitive processing, problem-solving, and decision-making.

In short, a multi-step prompt breaks down a complex task into smaller, manageable steps the model must take to achieve the desired result.

Let’s look at the difference between multi-step and few-shot prompts. Although both steps and shots play an important role in controlling the model’s behavior, steps are instructions that explicitly tell the model what to do. They act as a roadmap for the model by providing specific guidance. Shots are example questions and answers from which the model learns. They demonstrate how the model should respond to certain inputs. The model observes these examples and learns to generalize from them.

Example Multiple Transformations:

The use of multi-step prompting is particularly useful when the AI model needs to perform multiple transformations simultaneously, as demonstrated in the previous article on model chaining. It is also beneficial when the task at hand requires logical coherence

In this context, we instruct the model to create a summary. Typically, this is done with a simple command like “Summarize this article.” However, for a high-quality summary, it is often necessary to incorporate information from earlier sections to make sense of the later sections. This is where a multi-step prompt becomes valuable. By employing a running summary, the model continuously summarizes the text, while checking any given point in the file, to make sure that the content is coherent, contains the necessary information to understand later information and is logically structured throughout.


Prompt: Transform the uploaded pdf with the following steps:
- Step 1: Divide the document into manageable sections.
- Step 2: Summarize each section individually.
- Step 3: Concatenate the summaries of each section.
- Step 4: Summarize the concatenated section summaries to produce a higher-level summary.

Here we tested the prompt using the literature review of a thesis.

Classroom Example Case: Combining Multi-step prompting and Conditional Prompts

With the techniques of Multi-step prompting and Conditional Prompts, it is possible to create scenario analyses through an AI model. These methods enable both students and teachers to develop hypothetical class case studies on any given subject and let you interact and engage with the study material.

Prompt: Create a hypothetical case study for an economics class focusing on supply and demand. I will provide you with the market sector in <> below.

  • Step 1: Outline a real-world scenario involving a specific product or service and include key factors such as price, consumer behavior, and market conditions.

  • Step 2: Check whether the conditions of a functioning market are met (e.g. availability of substitutes, competition, rational consumer behavior)
    • If the conditions are not met, stop short of providing a full case study and instead highlight the specific conditions that are not satisfied.If the conditions are met, provide a set of analysis questions to test students’ knowledge of supply and demand.
Market sector: <Car Industry>

Chain of Thought Prompting

A chain-of-thought prompt breaks complex concepts into manageable steps. It makes the explanation more digestible and provides a more comprehensive explanation of each step. Each step logically follows the previous one, resulting in a coherent and thorough explanation that guides you through the entire process. In short, chain-of-thought prompting is a technique where the model presents a series of reasoning steps, also called thoughts, before giving a final answer. In other words, models must explain how it arrived at a conclusion. Moreover, it helps reduce the model’s errors because the reasoning takes place step by step. Just like we have seen with multi-step prompting.

Let’s examine the difference between multi-step and chain-of-thought prompts. In multi-step prompts, the different steps of the task are directly included in the prompt itself, which directs the model’s behavior. Chain-of-thought prompts take a different approach by instructing the model to generate intermediate steps or thoughts in its output while solving the problem. This helps to gain insight into the model’s decision-making. A limitation of chain-of-thought prompting is that a step with flawed reasoning will lead to an unsuccessful result.

Example Case

This method is especially useful for explaining code snippets. When you use a chain-of-thought prompt to explain code, the benefits of step-by-step reasoning are utilized to make each step of the code understandable. This assures that the explanation not only describes the outcome of the code but also reveals the process and logic behind each step and how they work together.

API Prompt

Python
code = """
income_split <- initial_split(income_frac, prop = 0.80, strata = income)
income_train <- training(income_split)
income_test <- testing(income_split)
"""

# Use a chain-of-thought prompt that asks the model to explain what the code does
prompt = f"""Explain what the code delimited by triple backticks does. Let's think step by step.```{code}```"""

Desktop

Conclusion

In conclusion, learning multi-step and chain-of-thought prompting is vital for advancing your skills as a prompt engineer. These techniques allow you to break down complex tasks into smaller, manageable steps. Which improves the AI’s logical coherence and reduces errors. By understanding the differences and applications of each method, you can steer AI models to produce accurate and high-quality outputs.

Thank you for joining us in this sixth part of the prompt engineering series. Stay tuned for the next article, where we will explore a new topic: Model Prepping. Where you will create a personalized AI Tutor!