Lesson 4 / 31
A Mental Model: Everything Is a Pipeline of Typed Steps
See an LLM app as data flowing through composable steps.
Input, transform, output
Both frameworks reward the same way of thinking: an LLM app is a pipeline where each step takes a value and returns a value. A prompt template turns a dict into messages; a model turns messages into a message; a parser turns a message into a Python object; a retriever turns a query into documents; a tool turns arguments into a result. When you know each step's input and output type, you can swap parts, test them separately (with fakes) and see exactly where a bug appears. Keep side effects (sending email, writing to a database) in clearly marked steps that can be approved or disabled.
The pipeline view
Types in brackets show what flows between steps.
{question: str} -> [prompt] -> messages -> [model] -> AIMessage -> [parser] -> str / object
retrieval: str -> [retriever] -> list[Document] -> [format] -> str -> (into the prompt)
tools: AIMessage(tool_call) -> [tool] -> ToolMessage -> back to the modelQuick check: Why think about each step's input and output types?
- It makes the model smaller
- It lets you swap, test and debug steps independently
- It removes the need for prompts
- It speeds up the GPU
Answer
It lets you swap, test and debug steps independently — Clear interfaces make pipelines modular and testable.