A LangChain guide has to start with the problem it solves: a large language model can answer questions, but it cannot easily read your documents, call your tools, or remember earlier in a conversation. LangChain is an open-source framework for building applications with large language models, giving developers the pieces to connect a model to data, tools and memory. The short answer is that LangChain is a toolkit for turning a language model into a working application, and it is most useful when your app needs more than a single prompt and a single reply.
LangChain was created by Harrison Chase and released in late 2022, in the months after chat-based language models became widely available. It grew quickly because developers all faced the same gap between an impressive demo and a reliable product. This guide explains what it is, how its main parts fit together, and when to use it instead of calling a model directly.
Key takeaways
- LangChain is an open-source framework for building applications with large language models, not a model itself.
- Its core ideas are chains, agents, tools, memory, retrieval and prompt templates.
- LCEL, the LangChain Expression Language, is the modern way to compose chains.
- LangGraph handles multi-step, stateful workflows and agents that need loops and human review.
- LangSmith is the companion platform for tracing, testing and monitoring LangChain applications.
- LangChain helps most when an app must use private data or tools; for a simple chatbot, a direct API call is enough.
What LangChain is
LangChain is a framework, which means it provides reusable building blocks and conventions rather than a finished product. It is available in Python and JavaScript, and it works with models from many providers, including OpenAI, Anthropic, Google and open-weight models you can run yourself. You are not locked to one model, and swapping it is usually a small change rather than a rewrite.
The framework sits between your application and the language model. Your code sends a request through LangChain, which formats the prompt, adds context from your documents or memory, calls the model, and parses or acts on the result. That middle layer is where most of the real work lives: deciding what context the model needs and handling its output safely.
It helps to understand what LangChain is not. It is not a language model, so it does not generate text on its own, and it is not a chatbot product. Alternatives include LlamaIndex, which focuses more narrowly on data retrieval, and the software development kits provided by the model companies themselves. LangChain’s strength is breadth: it covers the whole journey from prototype to production.
How LangChain works: the core building blocks
Everything in LangChain is built from a few ideas. The first is the model interface, which gives every language model the same shape in code, so your application talks to LangChain rather than to one provider’s API. On top of that sit prompt templates: reusable prompts with slots for the user’s question, the conversation history, or retrieved documents.
The second idea is the chain. A chain links steps together: take a question, fetch relevant documents, insert them into a prompt, call the model, and return the answer. The modern way to build chains is LCEL, the LangChain Expression Language, which uses a simple pipe syntax to join components. A chain written in LCEL can stream its output, run steps in parallel where possible, and be traced step by step when something goes wrong.
The third idea is retrieval. A language model only knows what it was trained on, so it cannot answer questions about your private documents. Retrieval-augmented generation, usually shortened to RAG, solves this by searching your documents for the passages most relevant to a question and adding them to the prompt. LangChain provides document loaders, text splitters that break documents into searchable chunks, and integrations with vector databases that store them for fast search. Our guide to language model API pricing is worth reading alongside this one, because every retrieval step adds tokens, and tokens are what you pay for.
| Component | What it does | Use it when |
|---|---|---|
| Prompt templates | Reusable prompts with slots for input | You repeat the same prompt shape |
| Chains and LCEL | Link steps into a sequence | Work flows through several stages |
| Retrieval and RAG | Search your documents for context | The model must use private data |
| Agents and tools | Let the model choose actions | The next step is not known in advance |
| Memory | Keep conversation context | Replies depend on earlier turns |
| LangGraph | Stateful, branching workflows | Agents need loops or human review |
| LangSmith | Tracing, testing, monitoring | You need to debug or evaluate |
Agents and tools
Chains follow a fixed sequence, but many tasks cannot be planned in advance. An agent lets the model decide what to do next. You give the agent a set of tools, such as a web search, a calculator, a database query or a call to your company’s own system, and the model reasons about which tool to use, in what order, until it has enough to answer. The agent keeps going until it reaches an answer or a step limit.
Tools are the key idea here. A tool is a function with a name and a description that the model can read, and the model chooses tools by reading those descriptions. That makes the quality of your tool descriptions surprisingly important: a vague description leads the model to choose the wrong tool or call it with the wrong inputs. Keep tools narrow and describe exactly what they return.
Agents are powerful, and they are also where things most often go wrong. An agent can call tools in a loop, spend tokens on unproductive steps, or take an action you did not intend. That is why production agents need step limits and cost limits, and why tools that change data, such as sending an email or moving money, deserve human approval before they run.
Memory: giving the model a past
A language model has no memory of its own: each request is independent unless you include the earlier conversation in the prompt. LangChain’s memory components handle that bookkeeping. Simple memory stores the recent conversation and adds it to each new prompt, while summary memory condenses long conversations into a short summary so the prompt stays within the context limit. More advanced setups store facts in a database and retrieve only the relevant ones.
Memory is a trade-off, because every word of history costs tokens and takes space in the context window. For a short chat, keeping the whole conversation is fine; for a long-running assistant, summarising or retrieving only the relevant parts works better. Passwords and personal data should stay out of conversation history.

LangGraph and LangSmith
LangGraph is LangChain’s framework for agents and workflows that need more structure than a straight-line chain. It models work as a graph of steps, where each step can decide what happens next, loop back, or pause for a human to review. That suits research agents that gather information, check their work and revise it, or support workflows where a person approves a draft before it is sent.
LangGraph also handles state properly: each step reads from and writes to a shared state, so the workflow always knows where it is and what remains. That state can be saved and resumed, which matters for long-running jobs that should survive a restart. If your application is a simple chain, LangGraph is more machinery than you need; if it is an agent with loops and decisions, it is the part of LangChain designed for it.
LangSmith is the companion platform for developing and operating LangChain applications. It records a trace of every call, showing the prompt, the retrieved documents, the tool calls and the model’s reply. When an answer is wrong, the trace shows exactly where it went wrong. LangSmith also supports datasets and evaluations, so you can test your application against set questions and measure whether a change made it better or worse.
When to use LangChain
LangChain is the right choice when your application needs several of its building blocks at once. A document question-answering system that loads files, stores them in a vector database, retrieves passages and generates cited answers is a natural fit, as is a support assistant that searches a knowledge base, remembers the conversation and escalates to a human when unsure. In both cases, LangChain saves you from writing the plumbing yourself.
It is the wrong choice when a direct API call will do. A single prompt that summarises a piece of text needs no framework, and a short script that calls the model once is easier to read, test and debug than a chain. There is also a learning cost: LangChain moves quickly, its interface has changed between versions, and code written against an older version may need updating. Check the version you are using against the current documentation before you follow a tutorial. Our comparison of AI coding assistants covers tools that can help you write framework code, and our guide to AI workflow automation tools looks at the no-code side of the same problem.
LangChain decision checklist
Work through this checklist before you commit to LangChain for a project.
- Your app needs more than one prompt: retrieval, tools, memory or several steps in sequence.
- You need to use private documents: retrieval is a core requirement, not an afterthought.
- You want model flexibility: the app should be able to switch providers without a rewrite.
- Your workflow has decisions or loops: consider LangGraph over a plain chain.
- You need tracing and evaluation: LangSmith covers debugging and testing in production.
- A direct API call is not enough: if one prompt and one reply solves the problem, skip the framework.
- You can track versions: pin the LangChain version and check the current documentation before following older tutorials.
- You have budgeted for tokens: retrieval, memory and agent loops all add cost, so estimate it early.
Frequently asked questions
Is LangChain a language model?
No. LangChain is a framework for building applications with language models. The model itself comes from a provider such as OpenAI, Anthropic or Google, or from an open-weight model you run yourself.
Do I need LangChain to build with a language model?
No. You can call a model’s API directly, and for simple tasks that is the better choice. LangChain earns its place when your application needs retrieval, tools, memory or multi-step work.
What is the difference between LangChain and LangGraph?
LangChain provides chains and components for language model applications. LangGraph is a framework inside the same ecosystem for stateful, branching workflows and agents, where steps can loop, branch or pause for human review.
What is LangSmith used for?
LangSmith traces, tests and monitors LangChain applications. It records each step of a run so you can debug bad answers, and runs evaluations against test datasets so you can measure improvements.
Does LangChain work with any model?
It works with many models through integrations, including the major commercial providers and open-weight models. Swapping providers is usually a small change, though behaviour still differs, so test after switching.
Is LangChain free?
The framework itself is open source and free to use. LangSmith has a free tier with paid plans for heavier use, and you still pay the model provider for every token your application uses.
The bottom line
LangChain is a toolkit for the gap between a language model and a working application. Chains and LCEL organise multi-step work, retrieval connects the model to your documents, agents and tools let it act, memory gives it a past, and LangGraph and LangSmith cover complex workflows.
Use it when your application genuinely needs those pieces, and skip it when a direct API call will do. For the right project it removes a large amount of plumbing and lets you focus on the application itself.







