Lesson 12 / 29
Prompt Chaining and Decomposition
Split a big task into smaller prompts whose outputs feed each other.
One job per prompt
A single giant prompt that extracts, analyses, decides and writes is hard to debug. Prompt chaining splits it: step 1 extracts facts into JSON, step 2 checks them against rules, step 3 drafts the reply from the verified data. Benefits: each prompt is simpler and testable, you can use a cheaper model for easy steps, you can insert code checks between steps, and failures are easy to locate. Costs: more calls, more latency, and errors can propagate, so validate between steps. Routing (a first call that classifies the request, then sends it to the right specialised prompt) is a common chain.
A three-step chain
Each step has one job; code can validate between steps. Illustrative; not run here.
Step 1 EXTRACT prompt: "Extract order_id, issue, requested_action as JSON." -> validate JSON
Step 2 DECIDE code/prompt: apply refund policy to the extracted fields -> decision + reason
Step 3 WRITE prompt: "Write a 3-sentence reply using ONLY these facts: ..." -> final text
Routing first: a cheap classifier sends billing / technical / other to different prompts.Validate between steps
Check the JSON from step 1 before step 2 uses it, so one bad extraction does not poison every later step.
Quick check: What is a benefit of prompt chaining?
- It removes all errors
- Each step is simpler to test and debug
- It always costs less
- It removes the need for validation
Answer
Each step is simpler to test and debug — Smaller focused steps are easier to evaluate and fix.