langchain-ai/langchain · error · ValueError
Expected {package} version to be < {lt_version}. Received {i
Error message
Expected {package} version to be < {lt_version}. Received {imported_version}. What it means
Raised by `check_package_version` in `langchain_core.utils.utils` when a version ceiling is enforced: the installed `package` version is greater than or equal to `lt_version` and the caller required strictly less than that. Integrations use this guard to refuse running against a dependency major version whose API they no longer match. The message shows expected ceiling vs. actually imported version.
Source
Thrown at libs/core/langchain_core/utils/utils.py:172
Args:
package: The name of the package.
lt_version: The version must be less than this.
lte_version: The version must be less than or equal to this.
gt_version: The version must be greater than this.
gte_version: The version must be greater than or equal to this.
Raises:
ValueError: If the package version does not meet the requirements.
"""
imported_version = parse(version(package))
if lt_version is not None and imported_version >= parse(lt_version):
msg = (
f"Expected {package} version to be < {lt_version}. Received "
f"{imported_version}."
)
raise ValueError(msg)
if lte_version is not None and imported_version > parse(lte_version):
msg = (
f"Expected {package} version to be <= {lte_version}. Received "
f"{imported_version}."
)
raise ValueError(msg)
if gt_version is not None and imported_version <= parse(gt_version):
msg = (
f"Expected {package} version to be > {gt_version}. Received "
f"{imported_version}."
)
raise ValueError(msg)
if gte_version is not None and imported_version < parse(gte_version):
msg = (
f"Expected {package} version to be >= {gte_version}. Received "
f"{imported_version}."
)
raise ValueError(msg)View on GitHub (pinned to e32fa9a52e)
Solutions
- Pin the package below the ceiling in the message: e.g. `pip install "pydantic<2"` (or add the constraint to requirements/uv.lock).
- Prefer upgrading the LangChain integration to a release that supports the new major version — usually better than downgrading.
- Use a lockfile (uv.lock / requirements.txt with `==`) so transitive upgrades cannot break the ceiling silently.
Example fix
# before # ValueError: Expected pydantic version to be < 2.0.0. Received 2.7.1. # after (terminal) # pip install "pydantic<2" # or upgrade the integration that enforces the ceiling: # pip install -U langchain-openai
Defensive patterns
Strategy: validation
Validate before calling
from packaging.version import Version, InvalidVersion
def version_lt(pkg: str, ceiling: str) -> bool:
try:
return Version(importlib.metadata.version(pkg)) < Version(ceiling)
except (importlib.metadata.PackageNotFoundError, InvalidVersion):
return False
if not version_lt("pydantic", "2"):
raise RuntimeError("pin pydantic<2 or upgrade this integration") Try / catch
try:
check_package_version(pkg, lt_version=ceiling)
except ValueError as e:
# environment drift — pin or upgrade, do not silence
raise RuntimeError(f"dependency ceiling violated: {e}") from e Prevention
- Install from a lockfile (uv sync / pip install -r requirements.lock) in prod.
- When upgrading a shared dependency major, upgrade the LangChain integration in the same change.
- Add a startup version assertion so drift is caught at boot, mid-request.
When it happens
Trigger: A LangChain integration (or your own call to `check_package_version(pkg, lt_version="1.0")`) executes after the environment was upgraded — e.g. `pydantic` 2.x installed where the code path requires `<2`, or a provider SDK bumped to a breaking major. Triggered at import/first use of the guarded integration.
Common situations: `pip install` of another package silently upgrading a shared dependency past a ceiling; stale LangChain integration against a newly released major SDK; environment drift between dev (pinned) and prod (loose) requirements; CI installing latest instead of locked versions.
Related errors
- Expected {package} version to be <= {lte_version}. Received
- Expected {package} version to be > {gt_version}. Received {i
- Expected {package} version to be >= {gte_version}. Received
- Could not import {module_name} python package. Please instal
- Tracing using LangChainTracerV1 is no longer supported. Plea
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/7c6b7f6dae3eb2e2.
Report an issue: GitHub.