Skip to main content
Practice

Prompt Chaining

Prompt Chaining is a technique where the output from one prompt is used as the input for the next. This allows AI to solve complex problems by linking multiple stages of questioning.

While similar to Chain of Thought (CoT) which analyses problems step-by-step, prompt chaining differs in that multiple prompts are connected sequentially.

In prompt chaining, each stage’s result serves as the next stage’s question, helping to achieve more refined and detailed outcomes.


How is Prompt Chaining Used?

Prompt chaining solves complex problems by using the result of the previous stage as the input for the next.


Simple Prompt Chaining Example

First, let’s consider a simple example of investigating the most populous cities and regions in the world.

First Question
What is the most populous city in the world?
First Answer
The most populous city in the world is Tokyo, Japan.
As of 2024, the Tokyo metropolitan area has a population of approximately 37 million.

Based on the information about Tokyo's population in the first answer, you can then pose a second question as follows.

Second Question
What is the most populous ward within Tokyo?
Second Answer
The most populous ward within Tokyo is Setagaya Ward.

Setagaya has approximately 920,000 residents as of 2024, making it the most populous ward among Tokyo's 23 special wards.

Continuing with sequential questions about Setagaya's population distribution by age, gender ratio, etc., can provide more detailed and in-depth information during research.


In practice, prompt chaining can also be used to solve complex problems. Below is an example of using prompt chaining in the development of a marketing plan for a book launch.


Developing a Marketing Plan for a Book Launch

First Question
What are some marketing strategies to promote a new book release?
First Answer
1. Digital Marketing:
Leverage social media ads, email marketing, and SEO to reach the target audience.

2. Content Marketing:
Create various content such as blog posts, YouTube videos, and podcasts to generate interest in the book.

3. Promotion Events:
Increase direct interactions with readers through book signings, webinars, and other events.

To gain more detailed information about digital marketing, you can then ask the following second question.

Second Question
How can we monitor the effectiveness of digital marketing? Please provide specific tools.
Second Answer
1. Google Analytics:

- Website Traffic Analysis: Track visitor count, page views, average session duration, and the behavior of website visitors.

- Goal Setting and Conversion Tracking: Set specific actions (e.g., book purchases, newsletter sign-ups) as goals and monitor the achievement rate.

- Source/Medium Analysis: Analyze the traffic sources (e.g., social media, search engines, direct visits) to identify the most effective channels.


2. HubSpot:

- Marketing Automation: Automate and analyze various marketing activities such as email marketing, blog posting, and social media management.

- CRM Integration: Integrate customer relationship management with marketing activities for comprehensive performance monitoring.


3. Email Marketing Tools (e.g., Mailchimp):
Answer continues...

Prompt chaining is also useful when performing data analysis tasks sequentially.

  1. First, organize the data in the desired format (data preprocessing).

  2. Then, draw insights from and visualize the data (data analysis).

  3. Finally, summarize the data analysis results (result synthesis).

Each of these tasks can be handled with separate prompts.


Key Takeaways

Prompt chaining handles complex tasks by breaking them into multiple prompts and using each stage’s result as the input for the next, systematically solving the problem.

Prompt chaining is particularly useful when

  • Narrowing down broad research topics to derive insights or

  • Sequentially handling interrelated tasks such as data preprocessing → visualization → result summarization.


Exercise

Send a prompt example and compare the AI's responses.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.