pypa/pip · error · InstallationError

[dependency-groups] data was invalid in

Error message

[dependency-groups] data was invalid in {path}: {'; '.join(messages)}

What it means

The [dependency-groups] table exists and is a dict, but constructing a DependencyGroupResolver from it failed with an ExceptionGroup. This means individual entries within groups are malformed — not valid requirement strings and not valid include-group table objects. All sub-error messages are collected and reported.

Solutions

  1. Read each sub-message in the error to find which specific entry is invalid
  2. Ensure every list entry is either a valid PEP 508 requirement string or a table like { include-group = "other-group" }
  3. Validate entries programmatically before relying on pip

Example fix

# before — pyproject.toml
[dependency-groups]
test = [123]

# after
[dependency-groups]
test = ["pytest"]
Defensive patterns

Strategy: validation

Validate before calling

from pip._vendor.packaging.dependency_groups import DependencyGroupResolver
from pip._vendor.packaging.errors import ExceptionGroup

def validate_dependency_groups_data(path: str) -> list[str]:
    """Returns list of error messages; empty if valid."""
    from pip._internal.utils.compat import tomllib
    with open(path, "rb") as fp:
        data = tomllib.load(fp)
    raw = data.get("dependency-groups", {})
    try:
        DependencyGroupResolver(raw)
        return []
    except ExceptionGroup as eg:
        return [str(e) for e in eg.exceptions]

Type guard

from pip._vendor.packaging.dependency_groups import DependencyGroupResolver

def is_valid_dependency_groups_data(raw: dict) -> bool:
    """Type guard: True if DependencyGroupResolver accepts the data."""
    try:
        DependencyGroupResolver(raw)
        return True
    except Exception:
        return False

Try / catch

from pip._internal.exceptions import InstallationError
from pip._internal.req.req_dependency_group import parse_dependency_groups

try:
    reqs = parse_dependency_groups([("pyproject.toml", "dev")])
except InstallationError as e:
    if "data was invalid" in str(e):
        print("Fix malformed entries in [dependency-groups]")
    else:
        raise

Prevention

When it happens

Trigger: A group contains a non-string, non-table entry such as 'mygroup = [123]' or 'mygroup = [{ include-group = 123 }]' (include-group value must be a string). The resolver rejects these during initialization.

Common situations: Numeric or boolean values where strings are expected. include-group pointing to a number instead of a string name. Mismatched schema after a TOML editing mistake.

Related errors


AI-assisted analysis of pypa/pip@f399c37189 (2026-08-08). Data as JSON: /api/errors/54f26ecc9fa18988. Report an issue: GitHub.

Appendix: source

Thrown at src/pip/_internal/req/req_dependency_group.py:65

        pyproject = _load_pyproject(path)
        if "dependency-groups" not in pyproject:
            raise InstallationError(
                f"[dependency-groups] table was missing from '{path}'. "
                "Cannot resolve '--group' option."
            )
        raw_dependency_groups = pyproject["dependency-groups"]
        if not isinstance(raw_dependency_groups, dict):
            raise InstallationError(
                f"[dependency-groups] table was malformed in {path}. "
                "Cannot resolve '--group' option."
            )

        try:
            resolvers[path] = DependencyGroupResolver(raw_dependency_groups)
        except ExceptionGroup as eg:
            # Handle ExceptionGroup from resolver initialization
            messages = [str(e) for e in eg.exceptions]
            raise InstallationError(
                f"[dependency-groups] data was invalid in {path}: {'; '.join(messages)}"
            ) from eg

    return resolvers


def _load_pyproject(path: str) -> dict[str, Any]:
    """
    This helper loads a pyproject.toml as TOML.

    It raises an InstallationError if the operation fails.
    """
    try:
        with open(path, "rb") as fp:
            return tomllib.load(fp)
    except FileNotFoundError:
        raise InstallationError(f"{path} not found. Cannot resolve '--group' option.")
    except tomllib.TOMLDecodeError as e:

View on GitHub (pinned to f399c37189)