LangChain from the ground up
Chains, prompts, parsers and tools
- Intermediate
- 10 chapters
- 153 min read
What LangChain actually does, written out once in plain Python: chains as steps, prompts as templates, messages as the model’s only memory, parsers as the boundary where text becomes data, and tools as a validated dispatch table. Every chapter has a runnable example beside the framework’s own API.
What You'll Learn
- Explain what a chain is without referring to a framework
- Build and test a prompt template with named slots
- Send a message list to a chat model and read the reply object
- Parse model output into validated data, with a failure path
- Compose steps with pipes, including parallel branches
- Describe a tool to a model, validate its request, and execute it
- Keep conversation history within a token budget
- Assemble a small chain and a bounded agent loop from scratch
Prerequisites
- Comfortable with Python functions, dictionaries and classes
- No prior experience with LangChain or any LLM framework
- The runnable examples use nothing outside the standard library
Vocabulary
The terms the chapters assume, in plain words.
- callback
- A function the library calls at fixed points in a run, such as when a step starts or ends.
- chain
- A series of steps where each one passes its result to the next, ending in the answer.
- invoke
- The method that runs a step once with one input and returns its result.
- memory
- Stored history from earlier turns, added back to a request so the model can refer to what was said.
- message
- One labelled turn in a chat request, marked as coming from the system, the user or the model.
- model
- The trained program that reads a message list and returns the next turn.
- output parser
- The step that turns a model's raw text into a value your program can use, or raises an error.
- pipe
- The operator that joins two steps into one new step, running the left side first.
- prompt
- The text a model receives for one request, built from fixed wording and the values filled into it.
- prompt template
- A reusable prompt with named blanks that are filled in for each request.
- runnable
- Any step with a standard way to run it, so steps can be joined without knowing each other's code.
- streaming
- Sending a reply in pieces as it is produced, rather than waiting for the whole text.
- tool
- A function exposed to a model, with a name, described inputs and a result.
- tool call
- A model's request to run a named tool with specific arguments, which your code may accept or refuse.
Course Content
- 01What a chain actually isNot started
Strip the branding away and a chain is a list of steps where each one hands its output to the next. Build one from plain functions before any framework is involved.
- 02Prompts are templatesNot started
A prompt with blanks in it is a template: fixed instructions, variable slots, and a rule about what happens when a slot is empty.
- 03Messages, not stringsNot started
A chat model takes a list of role-tagged messages and returns one. Understanding that list — and that the model remembers nothing between calls — explains most surprising behaviour.
- 04Output parsersNot started
A model returns text; your program needs data. A parser is the boundary where that text becomes a value you can trust — or an error you can handle.
- 05Composing with pipesNot started
The pipe operator is one method: a step that knows how to call another step. Implement it once and the rest of the framework becomes obvious.
- 06Tools and function callingNot started
A model cannot run code. It can only ask for a function to be run, by name and with arguments — and your program decides whether to obey.
- 07Memory and historyNot started
The model forgets everything between calls, so memory is something you build: a list you keep, a rule for what to drop, and a summary for what cannot fit.
- 08Callbacks and tracingNot started
A chain that cannot be observed cannot be debugged. Callbacks announce each run, and a trace turns those announcements into a tree with timings, tokens and errors.
- 09Streaming and asyncNot started
Streaming moves the first token earlier; async lets one worker wait on several calls at once. Neither makes the model faster, and both change how a chain is written.
- 10Capstone: a mini LangChainNot started
Assemble the pieces the course has built — templates, a model step, parsing, a tool loop — into one small library, then compare it with what the real framework adds.
