Working with LLMs

Prompt Chaining


Learning Objectives

  • You understand what prompt chaining is and when it’s useful.
  • You can break complex tasks into sequences of simpler prompts.
  • You know how to connect prompts together effectively.

Beyond single prompts

So far, we’ve focused on crafting individual prompts — writing clear instructions, providing appropriate context, using examples effectively, and encouraging step-by-step reasoning. These techniques work well for many tasks, but some problems are simply too complex for a single prompt to handle effectively.

Consider asking a model to simultaneously analyze a customer review, extract complaints, categorize them by type, rate their severity, and generate specific actionable recommendations. Even with careful prompting, combining all these steps into one instruction often produces inconsistent results, omits important details, or generates generic responses that don’t address the specific issues identified.

Prompt chaining offers a solution: break complex tasks into a sequence of simpler prompts, where each step focuses on one clear objective and the output from one step becomes input to the next.


The basic idea

Prompt chaining works like an assembly line. Instead of asking one worker to manufacture an entire complex product alone, you have specialists at each station, each focusing on their specific task with clear inputs and outputs. Similarly, instead of one prompt trying to handle everything, you create multiple prompts, each handling a specific subtask.

A chain consists of:

  • Multiple prompts, each addressing one piece of the overall task with clear, focused instructions.

  • Data flow between prompts, where outputs from one step become inputs to the next, creating a pipeline of processing.

  • A defined sequence determining which prompt runs when, and under what conditions.

The model never sees the full complexity at once. Instead, it tackles each step individually, which generally leads to more reliable and consistent results than attempting everything simultaneously.

Prompt chaining

0 / 5 points

Why is prompt chaining often more effective than trying to solve a complex task with a single prompt? (Select all that apply)


A concrete example

Let’s see how this works with customer review analysis. Suppose we have this review:

“The package arrived 3 days late, which was frustrating. When I opened it, the box was crushed and the product inside had visible scratches. I tried contacting customer service but didn’t hear back for 48 hours. The product itself works fine once I set it up, but the whole experience was disappointing.”

Attempting a single prompt

We could try asking the model to do everything at once:

Analyze this review, extract all complaints, categorize them, rate their
severity, and provide recommendations: [review text]

This often produces inconsistent results. The model might miss some complaints, mix up categories, apply inconsistent severity ratings, or generate generic recommendations that don’t address the specific issues identified.

Using a chain instead

Let’s break this into four focused steps:

Step 1: Extract complaints

Read this customer review and list all specific complaints mentioned.
Focus on concrete issues, not general sentiment.
Review: [review text]
List one complaint per line.

The model responds:

- Delivery was 3 days late
- Package box was crushed
- Product had visible scratches
- Customer service didn't respond for 48 hours

Step 2: Categorize complaints

Now we take these extracted complaints and categorize them:

Categorize each complaint into one category: Delivery, Product Quality,
Customer Service, Pricing, or Other.
Complaints:
- Delivery was 3 days late
- Package box was crushed
- Product had visible scratches
- Customer service didn't respond for 48 hours
Format: [Complaint] | [Category]

The model responds:

- Delivery was 3 days late | Delivery
- Package box was crushed | Delivery
- Product had visible scratches | Product Quality
- Customer service didn't respond for 48 hours | Customer Service

Categorizing events from a news article

0 / 10 points

You are working on a news aggregation system that processes articles to extract and categorize key events. You are using prompt chaining for the task. You already have a step that extracts events from the articles. Now, you need to categorize these events.

The input to your prompt will be a list of events extracted from a news article. The input format is as follows:

Events:
- [Event 1]
- [Event 2]
- [Event 3]

Create a prompt that takes a list of extracted events in the above format and categorizes each event into one of the following categories:

  • Politics
  • Economy
  • Environment
  • Technology
  • Other

Choose the single most direct category for each event based on its literal content. Do not add explanations.

The output must follow this format:

Categorized Events:
- [Event 1] | [Category]
- [Event 2] | [Category]
- [Event 3] | [Category]

Step 3: Rate severity

Take the categorized complaints and assess their likely impact:

Rate each complaint's severity as Low, Medium, or High based on likely
impact on customer satisfaction.
Complaints:
- Delivery was 3 days late | Delivery
- Package box was crushed | Delivery
- Product had visible scratches | Product Quality
- Customer service didn't respond for 48 hours | Customer Service
Format: [Complaint] | [Category] | [Severity]

The model responds:

- Delivery was 3 days late | Delivery | Medium
- Package box was crushed | Delivery | Medium
- Product had visible scratches | Product Quality | High
- Customer service didn't respond for 48 hours | Customer Service | High

Identifying actors in news events

0 / 10 points

Continuing from the previous task related to categorizing news events, you now need to identify the main actors involved in each event. These actors can be people, organizations, or countries mentioned in the events. The input to your prompt will be a list of categorized news events in the following format:

Categorized Events:
- Finland announced new border rules | Politics
- Apple reported record quarterly profits | Economy
- Greenpeace organized a beach cleanup | Environment

Create a prompt that takes a list of categorized news events and identifies the main actors (people, organizations, or countries) mentioned in each.

Copy the actor names exactly as they appear in each event. If multiple actors are explicitly named, list them in the same order as they appear in the event, separated by commas.

The output must follow this format:

Identified Actors:
- [Event] | [Category] | [Actor1, Actor2, ...]

As an example, for the above data, the output should be:

Identified Actors:
- Finland announced new border rules | Politics | Finland
- Apple reported record quarterly profits | Economy | Apple
- Greenpeace organized a beach cleanup | Environment | Greenpeace

The model that is used to generate the output is the same that the AI chat uses. The categorized events that the model should analyze are appended after your prompt.

Step 4: Generate recommendations

Finally, use the analyzed data to create specific, actionable recommendations:

Based on these analyzed complaints, provide 2-3 specific recommendations
for improvement. Prioritize high-severity issues.
Analyzed complaints:
- Delivery was 3 days late | Delivery | Medium
- Package box was crushed | Delivery | Medium
- Product had visible scratches | Product Quality | High
- Customer service didn't respond for 48 hours | Customer Service | High

The model responds:

1. Implement protective packaging standards to prevent product damage,
including corner reinforcements and interior padding
2. Establish a 24-hour response time standard for customer service, with
automatic escalation for missed deadlines
3. Review shipping partner performance and establish backup carriers for
critical deliveries

Each step is simpler and more focused than trying to do everything simultaneously. The chain produces more reliable results because the model can concentrate on one clear objective at each stage.

Research synthesis

0 / 5 points

The following contains steps that could be done in prompt chaining for research synthesis (with plenty of omitted details). Sort the steps in an order that most likely leads to sensible outcomes, starting from the first step at the top.