Skip to main content
AI Development Toolkit

LangChain: A Framework for LLM Applications

Know which pieces of an LLM application are genuinely worth a framework, what the retrieval path actually does, and when the abstraction costs more than the plumbing it replaces.

Intermediate16 minBy ToolDix Editorial

Learning objectives

  • Identify which parts of an LLM application a framework genuinely helps with
  • Trace a retrieval pipeline end to end and know which stage to tune
  • Decide between a framework and a direct API call on concrete criteria
  • Keep an application debuggable once several abstraction layers are involved

ToolDix original visual

AI Development practice loop
1

Frame

Name the outcome and constraints.

2

Build

Try one bounded workflow.

3

Review

Keep evidence, revise, and share.

A direct model API call gets you one request and one response. Real applications need more: fetching relevant documents first, calling tools, carrying conversation state, chaining several model calls, streaming output, retrying failures, and swapping providers. LangChain supplies standard components for those pieces so you are not rebuilding the same plumbing each time.

The framework has a reputation for over-abstraction, some of it earned by earlier versions. The current composition model is thinner than it was, but the underlying judgement call has not changed: a framework pays for itself in proportion to how many of its pieces you actually use.

What it composes

The building blocks are small and fit together in one direction. A prompt template turns variables into messages. A model takes messages and returns a response. An output parser turns that response into a typed structure. A retriever takes a query and returns documents. Tools are functions the model may call. Memory carries state across turns.

Composition chains them:

chain = prompt | model | parser
answer = chain.invoke({"question": "What changed in the refund policy?"})

Building on that interface gives you streaming, batching, and async for free across every step, which is genuinely useful — those three are tedious to implement consistently by hand, and they are where a lot of the framework's real value sits.

The retrieval path, stage by stage

ToolDix original diagram
Six stages -- and the one that decides answer quality
1. Load
Pull documents from their source. Boring, and where encoding and boilerplate problems enter.
2. Split
The stage that most determines quality. Chunking by character count cuts tables, code blocks and numbered procedures in half. Split on structure first, then size, with overlap.
3. Embed
Each chunk becomes a vector. Query and documents must use the same model.
4. Store
Index the vectors, keep the source text and metadata alongside for filtering and citation.
5. Retrieve
Nearest chunks for the query. Pure vector search misses exact identifiers -- hybrid keyword plus vector usually beats either.
6. Generate
Answer grounded in what came back. If the fact was not retrieved, no prompt can recover it.
Debug from stage five backwards. Print the retrieved chunks before touching the prompt; that is where the fault nearly always is.

Retrieval-augmented generation is the most common reason teams adopt a framework, and it is worth seeing as six distinct stages, because when the answers are bad the cause is almost never the model.

Load documents from their source. Split them into chunks — this is the stage that most determines quality, and the common failure is chunking by character count so that a table, a code block, or a numbered procedure is cut in half. Split on structure first, then size, and overlap so context spanning a boundary survives. Embed each chunk into a vector. Store those vectors in an index. Retrieve the nearest chunks for a query. Generate an answer grounded in what came back.

Debug in that order and from the retrieval end. Print the chunks the retriever returned before blaming the prompt: if the answer is not in them, no amount of prompt engineering will produce it, and the fix is in splitting, embedding, or the number of results requested. Pure vector search also misses exact identifiers — error codes, SKUs, names — so hybrid search combining keyword and vector matching is usually a meaningful improvement over either alone.

Tool calling and where agents come in

The second reason teams adopt a framework is tool calling: letting the model decide to invoke a function, then feeding the result back. The framework handles the mechanics — turning a Python function's signature and docstring into the schema the model sees, parsing the call it returns, executing it, and appending the result to the conversation.

That plumbing is genuinely repetitive, and getting it right by hand for several providers is tedious. What the framework cannot do is make tool calling reliable, and it is worth being clear about where the difficulty actually sits. Models pick the wrong tool, invent arguments, call the same tool repeatedly, or stop early. The fixes are all on your side: fewer tools rather than more, descriptions written for the model rather than for a developer, arguments validated before execution, and a hard cap on loop iterations so a confused agent cannot run indefinitely.

The same caution applies to the agent abstractions built on top. A loop that plans, calls tools, observes, and repeats is easy to start and hard to make dependable, and the failure modes — a wrong step early that everything after inherits, cost that scales with iterations rather than requests — are properties of the architecture rather than of the framework. Start with a fixed sequence of steps you control, and move to a model-directed loop only when the task genuinely cannot be expressed as one.

Framework or direct call

ToolDix original diagram
What the framework buys, and what it charges
Worth it when
  • Retrieval plus tools plus multi-step flow together
  • Streaming, batching and async across every step
  • Genuine provider portability matters
  • Conversation state and retries to manage
  • The plumbing is the hard part of the problem
Costs more than it saves when
  • The feature is one prompt and one response
  • You need exact control of the request payload
  • Debugging crosses layers nobody on the team wrote
  • Version churn outpaces your release cycle
  • The wrapper hides the API's own documentation
If you adopt it: turn on tracing, pin versions, keep business logic out of prompt templates, and drop to a direct call for the one step that needs precision.

Reach for the framework when you need several pieces together: retrieval plus tools plus multi-step flow, streaming and async across all of them, or genuine provider portability. The plumbing is the hard part, and it is already written.

Call the API directly when the application is a prompt and a response, when you need exact control of the request payload, or when the team will spend more time reading framework source to understand behaviour than the plumbing would have taken to write. For a single-purpose feature, twenty lines of direct HTTP is often the more maintainable choice, and it stays that way.

The cost is real and worth naming. Debugging crosses layers you did not write. Version churn has been significant. The exact prompt sent to the model is one indirection away from your code. And a thin wrapper around a well-documented API can make it harder to consult that API's own documentation.

Mitigations if you do adopt it: turn on tracing so you can see the actual prompts and intermediate steps, pin versions, keep your business logic outside the chain rather than inside prompt templates, and be willing to drop to a direct call for the one step where you need precise control.

Common mistakes

Adopting the framework before a multi-step use case exists. Complexity without the matching benefit.

Debugging RAG from the prompt end. Inspect the retrieved chunks first; that is where the fault usually is.

Splitting on character count alone. Cutting tables and procedures in half is the leading cause of poor retrieval.

Running without tracing. You cannot fix what you cannot see, and the framework hides the request by design.

Sources and license context

These references informed the lesson. ToolDix adds its own explanation, workflow, and practice rather than reproducing source material. Every link below leaves ToolDix and opens the publisher's own site in a new tab.

Keep going

Read these next on ToolDix.

Original lessons that build on what you just read.