Prompt Chaining Patterns Cheat Sheet

Prompt chaining design patterns — sequential chains, parallel branching, conditional routing, loop chains, error recovery, and building reliable multi-step LLM pi.

Last Updated: May 1, 2025

Chain Pattern Taxonomy

PatternStructureBest ForFailure Mode
Sequential ChainA → B → C (linear pipeline)Data extraction → transformation → formattingGarbage in, garbage out — errors cascade
Parallel BranchingA → [B, C, D] → aggregateMulti-perspective analysis, voting ensemblesCost multiplies by branch count
Conditional RoutingA → if X then B else CClassification-based workflowsWrong routing = wrong output
Loop ChainRepeat B until condition metSelf-refinement, iterative improvementInfinite loops if condition never met
Map-ReduceMap over items → reduce resultsProcessing lists, batch operationsLarge inputs = many parallel calls
Graph WorkflowsDAG of prompts with dependenciesComplex multi-step reasoningHard to debug, race conditions
Human-in-LoopA → human review → BHigh-stakes decisionsBottleneck if human is slow
Fallback ChainTry A → if fails, try B → if fails, try CRobustness, error handlingHigher latency on failure paths

Sequential Chains

Step 1: Extract
Prompt: 'Extract all named entities (people, orgs, dates) from: {input}' — structured output only
Step 2: Enrich
Use extracted entities to query knowledge base — attach context to each entity
Step 3: Synthesize
Prompt: 'Given entities and context: {enriched}, write a summary connecting all parties'
Step 4: Validate
Prompt: 'Check if the summary mentions all {n} entities. Return PASS or FAIL with explanation'
Step 5: Format
If PASS → format into final output. If FAIL → return to Step 3 with error context
Error Propagation
Store intermediate outputs at each step for debugging — when chain fails, you know exactly where
Context Window
Each step adds tokens. Use summary compression between steps for long chains (>5 steps)

Parallel Branching & Voting

ItemDescription
Multi-Perspective AnalysisRun the same prompt with different system instructions simultaneously: 'Analyze as a security expert', 'Analyze as a UX designer', 'Analyze as a lawyer'
Ensemble VotingRun 3+ models on same task → majority vote on output. Reduces hallucination and increases factual accuracy
Fact-Checking BranchMain chain produces answer → parallel branch verifies each factual claim against sources → merge corrections
Cost-Aware RoutingRun cheap model (GPT-4o-mini) first. If confidence is low OR task is flagged as complex, escalate to expensive model (GPT-4o)
Pareto AggregationCollect outputs from parallel branches → use a 'judge' LLM to synthesize a single best response
Parallel Tool CallsExecute independent tool calls simultaneously: search_web + query_database + check_calendar → merge results
Asynchronous PatternFire all parallel chains, wait for ALL to complete (or timeout) before aggregating

Conditional Routing & Loop Chains

ItemDescription
Classifier GateStep 1: Classify intent (greeting/tech_support/complaint/purchase). Step 2: Route to specialized chain per intent.
Confidence ThresholdIf LLM outputs with low confidence score (<0.7), route to human review or retry with more context
Language DetectionDetect input language → route to language-specific prompt → translate output back if needed
Retry-on-ErrorValidate output → if invalid, append error to prompt and retry (max 3 retries) — self-correction pattern
Self-Refinement LoopGenerate → Self-critique → Refine based on critique → Repeat until quality threshold or max iterations
Tool-Use LoopLLM selects tool → execute → observe → decide next tool or finish → loop until Task Complete signal
Convergence DetectionTrack output changes between iterations. If delta < threshold (e.g., <5% token change), terminate loop
Max Iteration GuardALWAYS set max_iterations (default 10). Log warning at 80% of max — helps catch near-infinite loops early
Pro Tip: Every chain needs an exit condition. LLMs can loop forever on ambiguous or adversarial inputs. Set max_iterations, add timeout guards, and validate intermediate outputs at each step.