Intermediate level · Module 2 of 9 · 11 guided hours
Prompt Chaining and Task Decomposition
Implementing multi-step chains in Python: decomposition, passing intermediate outputs, gates between steps, routing and testing each step separately.
Learning objectives
- Implement prompt chains as tested Python functions
- Add gates and routing between steps
- Compare chains with single prompts on accuracy and cost
Topics
- decomposing research tasks
- chains as functions
- gates and checks between steps
- routing
- per-step tests
- cost and latency of chains
Lessons
-
Lesson 1 Implementing Prompt Chains
Learners implement a research chain (understand the question, plan searches, gather evidence, draft, check) as separate Python functions with typed inputs and outputs.
chain steptyped input and outputintermediate resultsingle responsibilitycomposition
-
Lesson 2 Gates and Routing in Code
Learners add programmatic gates (checks that decide whether to continue) and a router that chooses a path from a validated category.
gateearly exitrouterallowed categoriesdefault path
-
Lesson 3 Testing and Costing Chains
Learners test each step separately and the whole chain end to end, and measure the cost and latency of each step to find where to optimise.
unit tests per stepend-to-end testslatency per steptoken use per stepoptimisation
Practical activity
Implement the project's research chain with gates and routing, step and end-to-end tests, and a cost and latency profile with one optimisation.
Expected outcomes
- Reliable, testable prompt chains
- Cost-aware design
Assessment
Chain implementation and tests (70%) and cost profile (30%).
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.