Break complex tasks into sequential prompts where each output feeds the next — more reliable than one mega-prompt.
# Document analysis chain
import anthropic
client = anthropic.Anthropic()
def call_llm(prompt: str) -> str:
return client.messages.create(
model='claude-opus-4-5', max_tokens=1000,
messages=[{'role':'user','content':prompt}]
).content[0].text
# Step 1: Extract key facts
facts = call_llm('Extract the 5 most important facts from:
' + document)
# Step 2: Identify themes from facts
themes = call_llm('Given these facts:
' + facts + '
Identify 3 main themes.')
# Step 3: Write executive summary from themes
summary = call_llm('Given themes:
' + themes + '
Write a 100-word executive summary.')
# Benefits of chaining:
# - Each step is focused and reliable
# - Easier to debug intermediate outputs
# - Can validate between steps
# - Use different models per step