langchain-ai/deepagents · error · ExtrasIntrospectionError

Could not parse optional-dependency metadata; cannot preserv

Error message

Could not parse optional-dependency metadata; cannot preserve already-installed extras safely: {raw}

What it means

When parsing the distribution's `Requires-Dist` metadata entries, an entry that fails `packaging.requirements.Requirement` parsing raises `ExtrasIntrospectionError` in strict mode. The strict message stresses that extras already installed on the system cannot be preserved safely without parseable metadata, since the loader cannot tell which extras the distribution declares.

Source

Thrown at libs/code/deepagents_code/extras_info.py:1279

        logger.warning(
            "Distribution %s not found; optional-dependency status will be empty",
            distribution_name,
        )
        return ()

    own_name = distribution_name.lower()
    installed: dict[str, list[tuple[str, str]]] = {}
    missing: dict[str, list[str]] = {}
    for raw in dist.requires or []:
        try:
            req = Requirement(raw)
        except InvalidRequirement:
            if strict:
                msg = (
                    "Could not parse optional-dependency metadata; cannot "
                    f"preserve already-installed extras safely: {raw}"
                )
                raise ExtrasIntrospectionError(msg) from None
            logger.warning("Could not parse Requires-Dist entry: %s", raw)
            continue
        if not req.marker:
            continue
        extra = _extract_extra_name(str(req.marker))
        if not extra:
            continue
        if extra in _COMPOSITE_EXTRAS:
            continue
        if req.name.lower() == own_name:
            continue
        try:
            version = pkg_version(req.name)
        except PackageNotFoundError:
            missing.setdefault(extra, []).append(req.name)
        else:
            installed.setdefault(extra, []).append((req.name, version))

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Reinstall the affected distribution so clean metadata is regenerated (`pip install --force-reinstall <dist>`)
  2. Fix or remove the malformed `Requires-Dist` entry if the metadata was hand-edited or produced by your own build
  3. Use `strict=False` to skip unparseable entries with a warning when safe preservation is not required

Example fix

// before
# dist-info/METADATA (hand-edited)
Requires-Dist: requests[security]>=2 ; extra === 'sec'

// after
# valid PEP 508 requirement
Requires-Dist: requests[security]>=2.0 ; extra == "sec"
Defensive patterns

Strategy: fallback

Validate before calling

from packaging.requirements import Requirement, InvalidRequirement
for line in raw_requires_dist:
    try:
        Requirement(line)
    except InvalidRequirement:
        print(f"unparseable Requires-Dist: {line}")

Try / catch

try:
    status = get_optional_dependency_status(dist, strict=True)
except ExtrasIntrospectionError as exc:
    logger.warning("bad metadata: %s", exc)
    status = get_optional_dependency_status(dist, strict=False)

Prevention

When it happens

Trigger: A distribution's METADATA contains a malformed `Requires-Dist` line (unparseable requirement syntax) and `get_optional_dependency_status` runs with `strict=True` on that distribution.

Common situations: Hand-edited or truncated `dist-info/METADATA` files; packages built with buggy/misused setup tooling emitting invalid requirement strings; partially failed installs leaving corrupt metadata.

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/16139011b69dd9b3. Report an issue: GitHub.