Course Content
Prompt Chaining and Pipelines
Connect multiple prompts to build multi-step AI workflows
What is Prompt Chaining?
Prompt chaining breaks a complex task into smaller, sequential steps. Each step is a separate LLM call, and the output feeds into the next prompt.
Why not do everything in one prompt?
- Large tasks exceed context windows
- Intermediate validation catches errors early
- Each step can use a different model or temperature
- Easier to debug — you can inspect each step’s output
A Simple Chain: Research Report
import anthropic
client = anthropic.Anthropic()
# Step 1: Extract key claims from source material
step1_response = client.messages.create(
model="claude-opus-4-8",
max_tokens=1000,
messages=[{"role": "user", "content": f"Extract the 5 most important claims from this text. Return as a numbered list.\n\n{source_text}"}]
)
claims = step1_response.content[0].text
# Step 2: Evaluate each claim
step2_response = client.messages.create(
model="claude-opus-4-8",
max_tokens=2000,
messages=[{"role": "user", "content": f"For each claim below, assess: (1) is it well-supported? (2) what evidence would strengthen it?\n\n{claims}"}]
)
analysis = step2_response.content[0].text
# Step 3: Synthesize into a report
step3_response = client.messages.create(
model="claude-opus-4-8",
max_tokens=1500,
messages=[{"role": "user", "content": f"Write a 3-paragraph executive summary based on this analysis:\n\n{analysis}"}]
)
report = step3_response.content[0].textWhen to Chain vs. Single Prompt
| Use chaining when | Use single prompt when |
|---|---|
| Task has >3 distinct steps | Task is a single, clear operation |
| Steps can fail independently | The whole task fits comfortably in context |
| You need intermediate validation | Speed is more important than reliability |
| Different steps need different expertise |
