P

Prompt Chaining: Definition and Examples

Prompt chaining is a technique that involves chaining multiple sequential prompts, where the output of each step feeds the input of the next, to accomplish complex tasks in a structured manner.

Full definition

Prompt chaining is an advanced prompt engineering method that breaks down a complex task into a series of intermediate steps. Rather than asking an AI model to solve everything in a single query, you create a chain of prompts where each link produces a result that serves as context or input for the next prompt.

This approach is inspired by the "divide and conquer" principle. For example, to write a full article, you might first ask for a detailed outline, then develop each section individually, and finally ask for a review and final synthesis. Each step benefits from targeted instructions and precise context, significantly improving the quality of the result.

Prompt chaining is particularly useful when the task exceeds the capabilities of a single prompt, either due to its complexity or the amount of information to process. It allows granular control over each step of the process, validation of intermediate results, and adjustment of direction if needed. It is a fundamental technique in building AI agents and automated workflows.

In practice, prompt chaining can be implemented manually (by copy-pasting results from one prompt into the next) or programmatically via frameworks like LangChain, API pipelines, or dedicated orchestration tools. The key to success lies in the careful design of each link in the chain and the transitions between them.

Etymology

The term combines "prompt" (instruction given to an AI model) and "chaining" (from English "chain"), borrowed from the concept of chaining in programming and logic. The idea of chaining sequential operations is inherited from Unix pipelines and the Chain of Responsibility design pattern in software engineering.

Concrete examples

Writing a blog post in several steps

Step 1: "Generate a detailed outline for an article on the benefits of teleworking with 5 sections." → Step 2: "Here is the outline: [RESULT]. Now write section 1 in 300 words." → Step 3: "Review the full article and suggest improvements."

Chain data analysis for a report

Step 1: "Summarize the key points of this sales data: [DATA]." → Step 2: "From this summary, identify the top 3 trends." → Step 3: "Write a strategic recommendation based on these trends."

Creating an application with an AI agent

Step 1: "Analyze this user story and identify the necessary technical components." → Step 2: "Generate the database schema for these components." → Step 3: "Write the API code corresponding to this schema."

Practical usage

To apply prompt chaining, start by identifying the natural subtasks of your final goal and formulate a dedicated prompt for each. Test each link individually before assembling them, and plan validation points between steps to correct course if necessary. Frameworks like LangChain or APIs with context management facilitate the automation of these chains.

Related concepts

Chain of ThoughtTask decompositionAI agentsLLM workflows

FAQ

What is the difference between prompt chaining and Chain of Thought?
Chain of Thought asks the model to reason step by step within a single prompt, whereas prompt chaining uses multiple distinct prompts chained sequentially. Chain of Thought structures internal reasoning, while prompt chaining structures the external workflow into several successive calls to the model.
How many steps can be chained in a prompt chain?
There is no theoretical limit, but in practice, 3 to 7 steps are common. Beyond that, the risk of error accumulation increases and the chain becomes difficult to maintain. The key is that each step has a clear objective and produces a verifiable result before moving to the next.
Does prompt chaining cost more in tokens than a single prompt?
Yes, prompt chaining generally consumes more tokens since it involves multiple API calls. However, it often produces much better results for complex tasks. The extra token cost is offset by reducing the number of attempts needed and the ability to use cheaper models for simple steps in the chain.

See also

How to use this prompt

  1. Copy the prompt with the button above.
  2. Paste it into ChatGPT, Claude or your favorite AI assistant.
  3. Replace the bracketed variables with your details, then refine the result.

About Prompt Guide

Prompt Guide is a free library of 2500+ ready-to-use prompts for ChatGPT, Claude and other AIs, with guides to learn prompting and tools to build and optimize your own prompts.

More definitions

Get new prompts every week

Join our newsletter.