What Is LangChain? When to Use It (and When Not To)
LangChain is a framework for building LLM apps. Learn its core building blocks, a short sketch, and when plain code is the better choice.
Short answer: LangChain is an open-source framework, available for Python and JavaScript, that gives you ready-made building blocks for LLM applications: models, prompts, document loaders, retrievers, tools and chains. It saves time when you prototype something like RAG or want to swap model providers. For a simple app that makes one model call, plain code is usually clearer.
The Problem LangChain Solves
A real LLM app is rarely just one call to a model. You load documents, split them into chunks, turn them into embeddings, store them, retrieve the right pieces, build a prompt, call a model, and parse the answer. Every provider and every vector store has its own API.
LangChain wraps these steps in a common interface, so the pieces can be connected and replaced without rewriting everything.
The Core Building Blocks
Block | What it does |
|---|---|
Models | One interface for chat and embedding models from different providers |
Prompts | Reusable templates with placeholders such as |
Document loaders | Read PDFs, web pages and files into a common document format |
Text splitters | Cut long documents into chunks that fit a model |
Retrievers and vector stores | Find the chunks most relevant to a question |
Tools | Functions a model can ask your code to call |
Chains | Steps connected so the output of one feeds the next |
LangGraph, from the same team, is a related library for stateful, graph-based agent workflows: loops, branches and steps that remember state. You can learn LangChain first and add LangGraph when you need agents.
A Short Sketch
The idea is easy to see in code. This is an illustrative sketch, not a copy-and-run recipe. LangChain changes quickly, so check the current documentation for exact imports and model setup.
# SKETCH ONLY: names and import paths change between versions.
# Check the current LangChain docs before running anything like this.
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
prompt = ChatPromptTemplate.from_template(
"Summarise this text in two sentences:\n\n{text}"
)
model = ... # a chat model object from the provider package you choose
chain = prompt | model | StrOutputParser() # prompt -> model -> plain string
print(chain.invoke({"text": "LangChain is a framework for LLM apps..."}))The | operator connects the steps: the prompt fills in the text, the model answers, and the parser returns a plain string. Swapping the model changes one line.
When LangChain Helps
Prototyping RAG: loaders, splitters and retrievers are ready to use. If you are new to the idea, read what RAG is and how a vector database works first.
Swapping providers: you can compare models or vector stores with small code changes.
Many integrations: a large ecosystem means you rarely write a connector from scratch.
When Plain Code Is Better
Simple apps: if you make one model call, the provider's own library is shorter and easier to read.
Learning the fundamentals: build one RAG pipeline by hand first. Then you will know what each abstraction hides.
Debugging: extra layers can make errors harder to trace. If you cannot see the exact prompt being sent, you cannot fix it.
Stability: a framework that evolves quickly means more upgrade work.
Common Mistakes
Using a framework before understanding prompts, tokens and embeddings.
Copying old tutorials without checking that the code matches the current docs.
Hiding bugs behind chains instead of printing the prompt and the retrieved text.
Key Takeaway
LangChain is a toolbox for connecting models, data and tools. Learn the basics with plain code first, then use LangChain when it saves you real work.
Ready to start? Learn how LLM applications work from the ground up, so any framework makes sense. Begin with the free course AI Engineering with LLMs: Beginner.
Related articles
More in AI Engineering
How to Get an LLM API Key (OpenAI and Gemini) and Understand the Cost
Where to create an OpenAI or Gemini API key, how token-based billing works, how to estimate cost and how to keep your key safe.
4 min readNov 11, 2026What Is Function Calling in LLMs?
Function calling lets an LLM ask your code to run a tool and use the result. Learn the step-by-step flow, a runnable example and the safety rules.
3 min readNov 7, 2026How Do You Evaluate an AI or LLM System?
Building an AI system is not enough—you need to measure how accurately, reliably, and safely it performs. Learn the key metrics and methods used to evaluate modern AI and LLM applications.
2 min readSep 6, 2026What Is AI Automation? Real Examples
AI automation puts a language model inside a workflow to handle messy, text-heavy steps. See real examples, a small code pattern and the risks to watch.
4 min readNov 14, 20267 AI Project Ideas for Your Portfolio
Seven small, finishable AI project ideas for a beginner portfolio, with the skill each one teaches and how to present it so others trust your work.
4 min readNov 14, 2026What Is Prompt Injection?
Prompt injection tricks an AI app into following an attacker's instructions. Learn the types, why it is dangerous and the layers of defence that reduce the risk.
4 min readNov 12, 2026
Comments
Sign in to join the discussion.



