Learn Agentic Patterns
CoursesInterviewSchoolVideosAI agent videosAI now
Learn Agentic Patterns

Learn agentic AI, then get interviewed on it. A free course, four job paths, a daily broken agent, and the interview.

learnagenticpatterns.com

Navigation

HomeThe courseThe interviewPatterns (developer track)PM trackBlogCareer GuideAboutSign Up

Connect

Cheat sheet (free PDF)Reskilling guideLinkedIn (Mousa Jawaheri)

© 2026 learnagenticpatterns.com

Privacy PolicyTerms of Service

Based on “Agentic Design Patterns” by Antonio Gullí

> All Patterns

[01]Prompt Chaining[02]Routing[03]Parallelization[04]Reflection[05]Tool Use[06]Planning[07]Multi-Agent Collaboration[08]Memory Management[09]Learning & Adaptation[10]State Management (MCP)[11]Goal Setting & Monitoring[12]Exception Handling & Recovery[13]Human-in-the-Loop[14]Knowledge Retrieval (RAG)[15]Inter-Agent Communication (A2A)[16]Resource-Aware Optimization[17]Reasoning Techniques[18]Guardrails & Safety[19]Evaluation & Monitoring[20]Prioritization[21]Exploration & Discovery[22]Boundary Translation
HomeCurriculumPrompt Chaining
Pattern [01]

Prompt Chaining

≈ Pipe and Filter Architecture / Chain of Responsibility Pattern

[01]

TL;DR

The foundational design pattern where a complex task is decomposed into a linear sequence of smaller, discrete LLM calls. The output of one step becomes the input (context) for the next step.

SWE: Pipe & Filter
Architecture Flow
agentgate
Extraction AgentagentValidation GategateAnalysis AgentagentResponse Agentagent

> Agentic Definition

Prompt Chaining is the foundational design pattern where a complex task is decomposed into a linear sequence of smaller, discrete LLM calls. The output of one step becomes the input (context) for the next step. By breaking a monolithic prompt into a chain, the system reduces the cognitive load on the model for any single inference, significantly improving accuracy, adherence to instructions, and reliability. It allows for intermediate "gates" where deterministic code can validate outputs before passing them to the next link in the chain.

Before: Traditional Monolithic Logic

Traditional Monolithic Logic
1def process_user_request(request):
2 # One giant function trying to do everything
3 # High complexity, hard to debug, prone to spaghetti code
4 data = extract_entities(request)
5 sentiment = analyze_sentiment(data)
6 summary = summarize_text(data)
7 response = formulate_response(summary, sentiment)
8 return response

After: Agentic Prompt Chain Architecture

Agentic Prompt Chain Architecture
1# Agentic Architecture using LangChain-style pseudocode
2class PromptChain:
3 def execute(self, user_query):
4 # Step 1: Extraction Agent (The "Filter")
5 # Objective: Clean and structure the raw input
6 context = llm.invoke(
7 prompt="Extract entities and intent...",
8 input=user_query
9 )
10
11 # Validation Gate (Traditional Code)
12 if not self.validate_structure(context):
13 raise ValueError("Step 1 failed extraction")
14
15 # Step 2: Analysis Agent (The "Processor")
16 # Objective: Perform the core reasoning task
17 analysis = llm.invoke(
18 prompt="Analyze sentiment and key themes...",
19 input=context
20 )
21
22 # Step 3: Synthesis Agent (The "Formatter")
23 # Objective: Draft the final human-readable response
24 final_response = llm.invoke(
25 prompt="Draft reply based on analysis...",
26 input=analysis
27 )
28 return final_response

Traditional SWE

Pipe & Filter

≈maps to

Agentic Pattern

Prompt Chaining

Read the original pattern

  • Pipes and Filters pattern (Microsoft Azure Architecture Center)
  • Chain of Responsibility (Refactoring Guru)

≈How They're Similar

Both patterns rely on passing data sequentially through processing nodes. Each node acts independently, having a single responsibility (SRP). The system is composed of modular components that can be tested and optimized in isolation.

≠Key Divergence

In SWE, the transformation is deterministic (bytes in, bytes out) and the interface is rigid (data types). In Prompt Chaining, the transformation is probabilistic (text in, text out). The "interface" between nodes is natural language, which is "fuzzy" and unstructured. This necessitates a new type of "Type Safety" — often implemented via intermediate parsing or "Guardrail" agents — to ensure the next node receives intelligible input.

> Production Considerations

01

Latency is additive. Total Latency = Sum(Step_1...Step_N). Chains can become slow if they grow too long. Engineers must optimize prompt length (input tokens) and generation length (output tokens) at each step to maintain responsiveness.

02

Error propagation is a significant risk. If Step 1 hallucinates or fails to extract the correct context, Step 2 processes garbage ("Garbage In, Garbage Out"). Validation gates between steps are not optional; they are critical reliability engineering.

03

While multiple calls increase request count, breaking a task down can actually reduce total token usage compared to a massive, multi-turn conversation that requires re-reading a huge context window for every minor correction.

💡

Key Takeaway

Unlearn: The instinct to write a "Mega-Function" or a "Mega-Prompt" that handles all edge cases.

Adapt: Think in terms of "Semantic Micro-Transactions." Break reasoning down into atomic units of work. Architect your prompt chains like you architect a data pipeline: Step A → Validate → Step B → Transform → Step C.

BuildBuild a Customer Support Pipeline. Assemble an agent pipeline that extracts intent from a support ticket, validates the extraction, analyzes sentiment, and generates a response.

DebugDebug: Prompt Chaining. This pipeline sometimes produces hallucinated responses. The extraction seems fine but downstream agents act on bad data. What's missing?

OptimizeOptimize a Support Pipeline. Your 4-step customer support pipeline uses GPT-4o for every step. It's accurate but costs $14.20 per 1,000 runs and takes 3.2 seconds. Cut costs by 60% while keeping quality above 85% and latency under 4 seconds.

PromptWrite an Extraction Agent Prompt. You're building a customer support pipeline using Prompt Chaining. The first step is an Extraction Agent that receives raw support tickets and must extract structured data. Write the system prompt for this agent.

Frequently Asked Questions

When should I use the Prompt Chaining pattern?

Prompt Chaining is the foundational design pattern where a complex task is decomposed into a linear sequence of smaller, discrete LLM calls. The output of one step becomes the input (context) for the next step. By breaking a monolithic prompt into a chain, the system reduces the cognitive load on the model for any single inference, significantly improving accuracy, adherence to instructions, and reliability. It allows for intermediate "gates" where deterministic code can validate outputs before passing them to the next link in the chain.

How does Prompt Chaining relate to Pipe and Filter Architecture / Chain of Responsibility Pattern?

Both patterns rely on passing data sequentially through processing nodes. Each node acts independently, having a single responsibility (SRP). The system is composed of modular components that can be tested and optimized in isolation. However, there is a key divergence: In SWE, the transformation is deterministic (bytes in, bytes out) and the interface is rigid (data types). In Prompt Chaining, the transformation is probabilistic (text in, text out). The "interface" between nodes is natural language, which is "fuzzy" and unstructured. This necessitates a new type of "Type Safety" — often implemented via intermediate parsing or "Guardrail" agents — to ensure the next node receives intelligible input.

What are the production trade-offs of Prompt Chaining?

Latency is additive. Total Latency = Sum(Step_1...Step_N). Chains can become slow if they grow too long. Engineers must optimize prompt length (input tokens) and generation length (output tokens) at each step to maintain responsiveness. Error propagation is a significant risk. If Step 1 hallucinates or fails to extract the correct context, Step 2 processes garbage ("Garbage In, Garbage Out"). Validation gates between steps are not optional; they are critical reliability engineering. While multiple calls increase request count, breaking a task down can actually reduce total token usage compared to a massive, multi-turn conversation that requires re-reading a huge context window for every minor correction.

Further Reading

Blog · 3 min read

Prompt Chaining Example: A 3-Step Blog Writer in Python

A worked example of prompt chaining: 3 LLM calls (outline → draft → edit) to write a blog post. Python code, full walkthrough, and when to use it.

Next Pattern

[02] · Routing