≈ Pipe and Filter Architecture / Chain of Responsibility Pattern
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.
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.
1def process_user_request(request):2 # One giant function trying to do everything3 # High complexity, hard to debug, prone to spaghetti code4 data = extract_entities(request)5 sentiment = analyze_sentiment(data)6 summary = summarize_text(data)7 response = formulate_response(summary, sentiment)8 return response1# Agentic Architecture using LangChain-style pseudocode2class PromptChain:3 def execute(self, user_query):4 # Step 1: Extraction Agent (The "Filter")5 # Objective: Clean and structure the raw input6 context = llm.invoke(7 prompt="Extract entities and intent...",8 input=user_query9 )1011 # Validation Gate (Traditional Code)12 if not self.validate_structure(context):13 raise ValueError("Step 1 failed extraction")1415 # Step 2: Analysis Agent (The "Processor")16 # Objective: Perform the core reasoning task17 analysis = llm.invoke(18 prompt="Analyze sentiment and key themes...",19 input=context20 )2122 # Step 3: Synthesis Agent (The "Formatter")23 # Objective: Draft the final human-readable response24 final_response = llm.invoke(25 prompt="Draft reply based on analysis...",26 input=analysis27 )28 return final_responseTraditional SWE
Pipe & Filter
Agentic Pattern
Prompt Chaining
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.
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.
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.
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.
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.
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.
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.