pypa/pip · error · InstallationError

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

Error message

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

What it means

Raised by _build_resolvers() when constructing the DependencyGroupResolver from the [dependency-groups] data raises an ExceptionGroup (req_dependency_group.py:62-67). Unlike error 136 (which fires during resolution of a specific group), this fires during RESOLVER INITIALIZATION — meaning the table structure is malformed in a way the resolver rejects up front (e.g. a group value that is not a list, or contains non-string elements).

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 d7d0d0a394)

Solutions

  1. Ensure each group's value is a TOML array of PEP 508 requirement strings (or `{other-group}` references).
  2. Read the joined messages to find the specific malformed group and fix its value type.
  3. Validate by loading the file and checking `isinstance(data['dependency-groups'][name], list)` for each group.
  4. Re-run pip after correcting the structure.

Example fix

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

Strategy: validation

Validate before calling

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

def validate_dependency_groups_init(path: str) -> None:
    with open(path, "rb") as f:
        data = tomllib.load(f)
    raw = data.get("dependency-groups", {})
    if not isinstance(raw, dict):
        raise TypeError("dependency-groups must be a dict of group -> list[str]")
    for name, val in raw.items():
        if not isinstance(val, list) or not all(isinstance(i, str) for i in val):
            raise TypeError(f"group {name!r} must be a list of strings")
    try:
        DependencyGroupResolver(raw)
    except ExceptionGroup as eg:
        raise ValueError("; ".join(str(e) for e in eg.exceptions)) from eg

Type guard

def is_group_value_list_of_str(val) -> bool:
    return isinstance(val, list) and all(isinstance(i, str) for i in val)

Try / catch

from pip._internal.exceptions import InstallationError

try:
    parse_dependency_groups([(path, group)])
except InstallationError as e:
    if "data was invalid" in str(e):
        # show sub-messages and fix the offending group value
        ...
    raise

Prevention

When it happens

Trigger: A [dependency-groups] table where a group's value is not a list, e.g. `dev = "pytest"` or `dev = {x=1}`, or a list containing non-string entries. DependencyGroupResolver(raw_dependency_groups) raises an ExceptionGroup during validation; pip joins the sub-exception messages.

Common situations: Hand-authoring groups with the wrong value type. Tooling that serializes a dict-of-dicts instead of dict-of-lists. Mixing TOML types accidentally.

Related errors


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