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

  1. Pin the package below the ceiling in the message: e.g. `pip install "pydantic<2"` (or add the constraint to requirements/uv.lock).
  2. Prefer upgrading the LangChain integration to a release that supports the new major version — usually better than downgrading.
  3. 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

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


AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14). Data as JSON: /api/errors/7c6b7f6dae3eb2e2. Report an issue: GitHub.