Anatomy of a Prompt Chain
A prompt chain is more than just running multiple prompts in sequence. Understanding the core components helps you design more effective workflows.
The Building Blocks
Every prompt chain consists of these fundamental components:
1. Steps (Nodes)
Each step in the chain is a discrete unit of work:
- Has a specific purpose
- Takes defined inputs
- Produces defined outputs
- Can succeed or fail
2. Connections (Edges)
Connections define how data flows between steps:
- Which output goes to which input
- How outputs are transformed for the next step
- Conditional paths based on results
3. State
State is the accumulated context that persists across steps:
- Original input data
- Intermediate results
- Metadata (timestamps, step counts, etc.)
- Error information
A Simple Chain Structure
┌─────────────────────────────────────────────────────────────┐
│ PROMPT CHAIN │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Step 1 │ ───► │ Step 2 │ ───► │ Step 3 │ │
│ │ Extract │ │ Analyze │ │ Generate │ │
│ └──────────┘ └──────────┘ └──────────┘ │
│ ▲ │ │
│ │ ▼ │
│ ┌──────────┐ ┌──────────┐ │
│ │ INPUT │ │ OUTPUT │ │
│ └──────────┘ └──────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
Anatomy of a Single Step
Each step has these properties:
┌────────────────────────────────────────┐
│ CHAIN STEP │
├────────────────────────────────────────┤
│ Name: "analyze_sentiment" │
│ │
│ Input: │
│ - text: string (from previous step) │
│ - context: object (from state) │
│ │
│ Prompt Template: │
│ "Analyze the sentiment of: {text}" │
│ │
│ Output Schema: │
│ - sentiment: "positive"|"negative" │
│ - confidence: number │
│ - reasoning: string │
│ │
│ Success Criteria: │
│ - confidence > 0.5 │
│ - sentiment is valid enum │
└────────────────────────────────────────┘
Input and Output Contracts
Each step should have clear contracts:
Input Contract
What the step expects to receive:
- Required fields
- Optional fields
- Data types
- Validation rules
Output Contract
What the step promises to produce:
- Guaranteed fields
- Possible fields
- Data types
- Format specifications
Notice how the explicit contracts make the step predictable and integrable.
Chain State Management
State flows through the chain and accumulates:
// Initial state
{
input: "Original user request",
steps_completed: [],
results: {}
}
// After Step 1
{
input: "Original user request",
steps_completed: ["extract"],
results: {
extract: { data: [...], confidence: 0.95 }
}
}
// After Step 2
{
input: "Original user request",
steps_completed: ["extract", "analyze"],
results: {
extract: { data: [...], confidence: 0.95 },
analyze: { insights: [...], sentiment: "positive" }
}
}
Template Variables and Injection
Prompts in a chain typically use templates:
Step 1 Prompt:
"Extract key information from: {{input.text}}"
Step 2 Prompt:
"Given these extracted facts: {{results.step1.facts}}
Analyze the sentiment and key themes."
Step 3 Prompt:
"Based on this analysis: {{results.step2.analysis}}
Generate a summary for: {{input.audience}}"
Each step can access:
- Original input:
{{input.*}} - Previous results:
{{results.stepName.*}} - Chain metadata:
{{meta.*}}
Error States
Steps can end in different states:
| State | Meaning | Action |
|---|---|---|
| Success | Step completed, output valid | Continue to next step |
| Soft Failure | Output invalid but retryable | Retry with modified prompt |
| Hard Failure | Unrecoverable error | Stop chain or skip to fallback |
| Timeout | Step took too long | Retry or use cached result |
Exercise: Map a Chain
Design a chain for this task: "Convert a job posting into a structured candidate screening rubric"
A well-designed chain might look like:
-
Extract Requirements
- Input: Raw job posting text
- Output: Structured list of requirements (technical, experience, soft skills)
-
Categorize and Weight
- Input: List of requirements
- Output: Requirements with importance weights (must-have vs nice-to-have)
-
Generate Evaluation Criteria
- Input: Weighted requirements
- Output: Specific questions/criteria for each requirement
-
Format Rubric
- Input: Evaluation criteria
- Output: Formatted screening rubric document
Key Takeaways
- Chains consist of steps, connections, and state
- Each step should have clear input/output contracts
- State accumulates through the chain, making previous results available
- Template variables inject dynamic content into prompts
- Steps can succeed, fail softly, fail hard, or timeout
- Good chain design starts with clear contracts for each step
Next, we'll look at the mechanics of actually passing outputs between prompts.

