Course Content
LangChain Mastery
7 sections · 109 lessons
Write a function to handle version compatibility in LangChain.
What you need to know
The package map (as of 2026)
| Package | Contains |
|---|---|
langchain-core | Base interfaces: runnables, messages, prompts, tools, callbacks, vector-store interface |
langchain (1.x) | create_agent, middleware, init_chat_model, tools and messages re-exports |
langchain-classic | Legacy chains (LLMChain, RetrievalQA), retrievers like EnsembleRetriever, indexing API helpers, hub, CacheBackedEmbeddings |
langgraph | The runtime agents run on: graphs, checkpointers, streaming |
langchain-openai, langchain-anthropic, langchain-chroma, ... | One package per integration |
langchain-community | Community integrations (loaders, some stores and retrievers) |
In September 2026 the current lines are langchain 1.4, langchain-core 1.6 and langgraph 1.2 — check PyPI for exact numbers when you answer.
A startup check
1from importlib.metadata import version, PackageNotFoundError2from packaging.specifiers import SpecifierSet34REQUIRED = {5 "langchain": ">=1.0,<2",6 "langchain-core": ">=1.0,<2",7 "langchain-openai": ">=1.0,<2",8 "langgraph": ">=1.0,<2",9}1011def check_versions(required: dict[str, str] = REQUIRED) -> list[str]:12 problems = []13 for pkg, spec in required.items():14 try:15 found = version(pkg)16 except PackageNotFoundError:17 problems.append(f"{pkg} is not installed (need {spec})")18 continue19 if found not in SpecifierSet(spec):20 problems.append(f"{pkg} {found} does not satisfy {spec}")21 return problems2223if problems := check_versions():24 raise RuntimeError("Incompatible LangChain install: " + "; ".join(problems))packaging (already a dependency of langchain-core) compares versions correctly, including pre-releases, which naive string or tuple comparison gets wrong.
Upgrade practice
- Pin everything in a lockfile (
uv.lock,poetry.lock, orpip-compileoutput). - Read the migration guide for major versions; 1.0 has one.
- Turn warnings into errors in CI (
-W error::DeprecationWarningfor your own code paths) to find deprecated calls before they are removed. - Upgrade core and partners together, then run unit tests and the evaluation dataset.
- Roll out gradually and compare traces before and after.
The 1.0 changes to know
from langchain.chains import ...→from langchain_classic.chains import ...(or rewrite in LCEL).initialize_agent,AgentExecutor,create_react_agent→create_agentfromlangchain.agents, withsystem_prompt=and middleware.langchain.globals→langchain_core.globals.- Python 3.9 dropped.
A real-life example
An HR bot's Dockerfile had pip install langchain with no pin. A rebuild in November 2025 pulled 1.0, and the service failed at import: from langchain.chains import create_retrieval_chain no longer existed. The team hot-fixed by pinning langchain<1.0.
They then planned the migration: added langchain-classic to get running on 1.x the same day, replaced the retrieval chain with LCEL, rewrote the leave-filing AgentExecutor as create_agent with HumanInTheLoopMiddleware for approvals, added the startup check and a lockfile, and ran their 120-question evaluation set before and after. Scores matched within one point, and the upgrade shipped a week later.
Follow-up questions to expect
- "Why can't you upgrade just
langchain-openai?" — Partner packages require a matchinglangchain-corerange; mixing versions causes import errors or subtle behaviour changes. - "How do you handle a deprecated API you depend on?" — Wrap it behind your own function so there is one place to change, and schedule the migration before the removal version.
- "Is
langchain-classiclong-term?" — It exists for compatibility; treat it as a bridge and move to current APIs over time.