LangChain

On this page 7

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.

ComponentRoleTypical example
Chat modelSends messages to a language model and returns a replyA hosted or locally served LLM
Prompt templateFormats variables into system and user messagesA support assistant prompt with placeholders
Output parserTurns raw model text into strings or typed objectsJSON parsed into a Pydantic model
Document loaderReads content from files, databases or web sourcesPDF, HTML or CSV ingestion
Text splitterCuts documents into chunks sized for embeddingRecursive splitting at 500-1,500 characters
RetrieverReturns relevant chunks for a querySimilarity search over a vector store
ToolExposes a function the model may callA weather API or SQL query function
Core LangChain components

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.

PackageContentsWhen it is needed
langchain-coreBase abstractions, Runnable interface and LCELAlways, as the foundation
langchainAgent construction and higher-level helpersFor agents and common application patterns
Partner packagesIntegrations maintained per provider, such as langchain-openaiWhen a specific model or database is used
langchain-communityCommunity-maintained third-party integrationsFor integrations without a partner package
langchain-text-splittersChunking utilities for documentsIn retrieval and ingestion pipelines
Main packages in the LangChain ecosystem

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 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.

ToolPrimary focusRelationship to LangChain
LangChainModel integrations, chains and agent creationReference point
LangGraphStateful, cyclic agent workflows as graphsSame maintainers; runtime beneath LangChain agents
LangSmithTracing, evaluation and monitoringCommercial platform that observes LangChain runs
LlamaIndexData ingestion, indexing and retrievalAlternative with a stronger retrieval emphasis
HaystackSearch and retrieval pipelinesAlternative with explicit pipeline components
DSPyProgrammatic prompt optimizationDifferent paradigm that compiles prompts from metrics
LangChain and neighboring tools

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.

SituationRecommended choiceReason
Several model providers must be interchangeableUse LangChainUniform chat model interface reduces vendor lock-in
Agent needs tools, memory and approval stepsLangChain agent on LangGraphDurable state and controllable loops
Single call to one model APIDirect provider SDKLess abstraction and fewer dependencies
Retrieval quality is the main concernEvaluate LlamaIndex or Haystack tooRicher indexing and retrieval options
Prompts must be tuned against a metricConsider DSPyAutomatic prompt optimization
Choosing whether to use LangChain

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.