LangChain is an open-source framework for building applications on large language models, providing standard interfaces for chat models, prompts, retrievers and tools so that developers can compose them into chains and agents. Among AI frameworks & tools it sits at the application orchestration layer: it does not train or serve models, but connects hosted or local models to data sources, external APIs and application logic.
The project was released in late 2022 in Python and was soon followed by a JavaScript and TypeScript version. Its main value is provider independence: the same application code can call models from different vendors, swap a vector store or add a tool without rewriting the surrounding logic.
How LangChain composes model calls
LangChain works by wrapping every component in a common Runnable interface, so that models, prompt templates, parsers and retrievers can be connected in sequence. Each Runnable exposes the same methods, including invoke, batch, stream and their asynchronous variants, which means a whole pipeline can be streamed or batched as easily as a single call.
The LangChain Expression Language (LCEL) expresses these pipelines declaratively. A typical chain is written as prompt | model | parser: the prompt template formats user input, the chat model generates a message, and the output parser converts that message into a string or a structured object. Because the pipe operator builds a graph of Runnables, the framework can parallelize independent branches, apply retries and fallbacks, and emit traces for every step.
The following table lists the core building blocks and the role each plays in an application.
| Component | Role | Typical example |
|---|---|---|
| Chat model | Sends messages to a language model and returns a reply | A hosted or locally served LLM |
| Prompt template | Formats variables into system and user messages | A support assistant prompt with placeholders |
| Output parser | Turns raw model text into strings or typed objects | JSON parsed into a Pydantic model |
| Document loader | Reads content from files, databases or web sources | PDF, HTML or CSV ingestion |
| Text splitter | Cuts documents into chunks sized for embedding | Recursive splitting at 500-1,500 characters |
| Retriever | Returns relevant chunks for a query | Similarity search over a vector store |
| Tool | Exposes a function the model may call | A weather API or SQL query function |
Package structure and versions
LangChain is distributed as several separate packages rather than one monolithic library, a split introduced to keep dependencies light and to stabilize the core interfaces. Knowing which package holds which code prevents many import and version conflicts.
| Package | Contents | When it is needed |
|---|---|---|
| langchain-core | Base abstractions, Runnable interface and LCEL | Always, as the foundation |
| langchain | Agent construction and higher-level helpers | For agents and common application patterns |
| Partner packages | Integrations maintained per provider, such as langchain-openai | When a specific model or database is used |
| langchain-community | Community-maintained third-party integrations | For integrations without a partner package |
| langchain-text-splitters | Chunking utilities for documents | In retrieval and ingestion pipelines |
The 1.0 release in 2025 narrowed the main package around agent creation built on LangGraph and moved older chain classes into a legacy package. Earlier constructs such as LLMChain and many prebuilt chains are deprecated, so tutorials written for versions before 0.2 often no longer run without changes. Teams should pin package versions and read migration notes before upgrading.
LangChain compared with related frameworks
LangChain is a general-purpose orchestration framework, while several neighboring tools specialize in one part of the same problem. The comparison below shows where each fits.
| Tool | Primary focus | Relationship to LangChain |
|---|---|---|
| LangChain | Model integrations, chains and agent creation | Reference point |
| LangGraph | Stateful, cyclic agent workflows as graphs | Same maintainers; runtime beneath LangChain agents |
| LangSmith | Tracing, evaluation and monitoring | Commercial platform that observes LangChain runs |
| LlamaIndex | Data ingestion, indexing and retrieval | Alternative with a stronger retrieval emphasis |
| Haystack | Search and retrieval pipelines | Alternative with explicit pipeline components |
| DSPy | Programmatic prompt optimization | Different paradigm that compiles prompts from metrics |
The most common confusion is between LangChain and LangGraph. LangChain answers the question of which components to connect, whereas LangGraph answers how state and control flow move through loops, branches and human approval steps. In current versions a LangChain agent is itself executed by the LangGraph runtime.
Typical use cases and design choices
LangChain is most often used for retrieval-augmented generation (RAG), tool-calling agents and structured data extraction. In a RAG application the framework loads documents, splits them, stores embeddings in a vector database and then injects retrieved passages into the prompt at query time.
The decision table below summarizes when LangChain is a good fit and when a simpler or more specialized option is preferable.
| Situation | Recommended choice | Reason |
|---|---|---|
| Several model providers must be interchangeable | Use LangChain | Uniform chat model interface reduces vendor lock-in |
| Agent needs tools, memory and approval steps | LangChain agent on LangGraph | Durable state and controllable loops |
| Single call to one model API | Direct provider SDK | Less abstraction and fewer dependencies |
| Retrieval quality is the main concern | Evaluate LlamaIndex or Haystack too | Richer indexing and retrieval options |
| Prompts must be tuned against a metric | Consider DSPy | Automatic prompt optimization |
Good practice is to keep chains short and observable, request structured output wherever downstream code depends on the format, and log every run with a tracing tool so that failures can be reproduced.
Limitations and common criticisms
The main criticism of LangChain is abstraction overhead: for simple tasks, its wrappers can hide what is actually sent to the model and make debugging harder than a direct API call. Experienced teams therefore adopt it selectively rather than for every model interaction.
- Rapid API churn in early versions broke code frequently, and outdated examples remain widespread.
- Deep class hierarchies can obscure the exact prompt, so inspecting traces is essential.
- Integration quality varies: community integrations are not all maintained to the same standard.
- Agent loops can run up costs when iteration limits and timeouts are not set.
- Security depends on tool design: a tool that executes code or SQL needs strict permissions and input validation, because prompt injection can steer the model.
None of these issues is unique to LangChain, but its breadth makes them visible. The decisive mitigation is disciplined engineering: pinned versions, explicit prompts, bounded agent iterations and automated evaluation.
A non-technical view
A language model on its own can only read text and write text. It cannot look up a company manual, check a database or send an email. LangChain is a toolkit of connectors that lets programmers link a model to those other things in a clear order.
Think of it as a set of standard plugs and adapters. Instead of building a custom cable for every model and every data source, developers use pieces that already fit together, and they can swap one piece for another without rebuilding the whole system.
A concrete example
A mid-sized insurance company wants an internal assistant that answers adjusters’ questions about policy wording. The development team uses LangChain to load about 4,000 policy PDFs, split them into chunks of roughly 1,000 characters, and store their embeddings in a vector database. At query time a retriever returns the five most relevant passages, a prompt template places them in the context, and an output parser returns an answer together with the cited clause numbers.
Because the chat model sits behind the common interface, the team later switches to a cheaper model for routine questions by changing one configuration line. Tracing reveals that some answers relied on outdated documents, so the team adds a metadata filter for the current policy year. The result is an assistant that adjusters use daily, with answers grounded in the actual policy text rather than in the model’s general knowledge.