Passing Outputs Between Prompts
The core mechanic of prompt chaining is taking the output of one prompt and using it as input for the next. Getting this right is essential for reliable chains.
The Output-to-Input Pipeline
When one step completes, its output must be:
- Captured - Store the raw response
- Parsed - Extract structured data if needed
- Validated - Ensure it meets expectations
- Transformed - Convert to the format the next step needs
- Injected - Insert into the next prompt
Structured Output Formats
The most reliable chains use structured outputs that are easy to parse and validate.
JSON Outputs
JSON is the most common format for chain outputs:
Markdown with Markers
For semi-structured outputs, use clear section markers:
## ANALYSIS
[Analysis content here]
## RECOMMENDATIONS
1. First recommendation
2. Second recommendation
## CONFIDENCE
High (85%)
Delimiter-Based Formats
For simple outputs, delimiters work well:
SENTIMENT: positive
SCORE: 0.87
KEYWORDS: innovation, growth, opportunity
Injection Patterns
Direct Injection
The simplest pattern: insert the entire previous output:
Step 1 Output: "The company shows strong growth potential..."
Step 2 Prompt:
"Based on this analysis:
---
The company shows strong growth potential...
---
Generate three investment recommendations."
Field Injection
Extract and inject specific fields:
Step 1 Output: { "sentiment": "positive", "score": 0.87, "themes": ["growth", "innovation"] }
Step 2 Prompt:
"The sentiment analysis shows a {{sentiment}} sentiment with {{score}} confidence.
Key themes identified: {{themes | join(', ')}}
Based on these findings, draft a response strategy."
Selective Injection
Only pass what the next step needs:
// Step 1 produces detailed analysis
step1Output = {
fullAnalysis: "...", // 2000 words
summary: "...", // 100 words
score: 0.87,
categories: [...]
}
// Step 2 only needs summary and score
step2Input = {
summary: step1Output.summary,
score: step1Output.score
}
Handling Different Output Types
Text Outputs
When the output is free-form text:
List Outputs
When working with lists, specify the format clearly:
Step 1 Output:
1. Improve customer onboarding (HIGH priority)
2. Add dark mode (MEDIUM priority)
3. Fix payment bugs (HIGH priority)
4. Update documentation (LOW priority)
Step 2 Prompt:
"For each HIGH priority item in this list, create a detailed implementation plan:
[list from step 1]"
Nested Data
For complex nested structures, consider flattening or summarizing:
// Complex step 1 output
{
"analysis": {
"financial": {
"revenue": { "q1": 100, "q2": 120, "q3": 115 },
"costs": { "q1": 80, "q2": 85, "q3": 90 }
},
"market": {
"share": 0.23,
"growth": 0.05
}
}
}
// Flattened for step 2
"Financial Summary:
- Revenue trend: Q1=$100M → Q2=$120M → Q3=$115M
- Cost trend: Q1=$80M → Q2=$85M → Q3=$90M
- Current market share: 23%
- Market growth rate: 5%"
Context Window Considerations
Large outputs can consume valuable context space. Strategies to manage this:
Summarization
Step 1: Generate detailed analysis (2000 words)
Step 1.5: Summarize analysis to key points (200 words)
Step 2: Use summary for next steps
Chunking
Step 1: Process items 1-10
Step 2: Process items 11-20
Step 3: Combine results from steps 1 and 2
Reference Systems
Step 1 Output: { "id": "analysis_001", "summary": "...", "full_text": "..." }
Step 2 Input: Uses only summary, but can reference id for full text if needed
Exercise: Design Output Passing
Design the output format and passing mechanism for this chain:
Task: Analyze a customer complaint, categorize it, and generate a response
Example solution:
// Step 1 Output
{
"complaint_text": "original text",
"customer_emotion": "frustrated",
"issue_summary": "Package arrived damaged after 2-week delay",
"mentioned_products": ["Order #12345"],
"urgency": "high",
"key_phrases": ["damaged", "late delivery", "refund"]
}
// Step 2 Output
{
"primary_category": "shipping",
"secondary_category": "product_damage",
"resolution_type": "refund_and_reship",
"escalation_needed": false,
"similar_cases": 3
}
// Step 3 Input (combined)
{
"emotion": "frustrated",
"summary": "Package arrived damaged after 2-week delay",
"category": "shipping",
"resolution": "refund_and_reship",
"urgency": "high"
}
Common Pitfalls
1. Passing Too Much Context
Problem: Including the entire previous output when only a summary is needed Solution: Extract only the fields required for the next step
2. Losing Important Context
Problem: Over-summarizing and losing critical details Solution: Balance brevity with completeness; keep original available if needed
3. Format Mismatches
Problem: Step 2 expects JSON but Step 1 outputs markdown Solution: Define clear output contracts and add format conversion if needed
4. Fragile Parsing
Problem: Using regex to parse free-form text that might change format Solution: Use structured formats (JSON) or robust parsing with fallbacks
Key Takeaways
- Structured outputs (JSON, delimited text) are easier to parse and validate
- Only pass what the next step actually needs
- Consider context window limits when passing large outputs
- Use summarization or chunking for long content
- Define clear contracts for what each step produces and consumes
- Handle format mismatches gracefully with transformations
Next, we'll dive deeper into transforming outputs between steps.

