langchain-ai/langchain · error · NotImplementedError

When specifying __root__ no other fields should be provided.

Error message

When specifying __root__ no other fields should be provided. Got {field_definitions}

What it means

Raised by `_create_model` in `langchain_core.utils.pydantic` when `root` is specified (pydantic v1-style `__root__` model) at the same time as additional field definitions. A root model has exactly one value, so mixing `root=` with `field_definitions` is ambiguous and rejected with `NotImplementedError`.

Source

Thrown at libs/core/langchain_core/utils/pydantic.py:589

        model_name: The name of the model.
        module_name: The name of the module where the model is defined.

            This is used by Pydantic to resolve any forward references.
        field_definitions: The field definitions for the model.
        root: Type for a root model (`RootModel`)

    Returns:
        The created model.
    """
    field_definitions = field_definitions or {}

    if root:
        if field_definitions:
            msg = (
                "When specifying __root__ no other "
                f"fields should be provided. Got {field_definitions}"
            )
            raise NotImplementedError(msg)

        if isinstance(root, tuple):
            kwargs = {"type_": root[0], "default_": root[1]}
        else:
            kwargs = {"type_": root}

        try:
            named_root_model = _create_root_model_cached(
                model_name, module_name=module_name, **kwargs
            )
        except TypeError:
            # something in the arguments into _create_root_model_cached is not hashable
            named_root_model = _create_root_model(
                model_name,
                module_name=module_name,
                **kwargs,
            )
        return named_root_model

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. Remove the extra field definitions — a root model may only define `root`.
  2. If you need both the root value and named fields, model it explicitly instead: define a `BaseModel` with a normal field (e.g. `items: list[T]`) rather than a root model.
  3. Audit helper code that injects defaults/metadata into `field_definitions` before calling `create_model`.

Example fix

# before
create_model("Tags", root=list[str], **{"sep": (str, ",")})  # NotImplementedError

# after
create_model("Tags", root=list[str])
# or, if named fields are required, drop root:
class Tags(BaseModel):
    items: list[str]
    sep: str = ","
Defensive patterns

Strategy: validation

Validate before calling

def build_model(name, root=None, **fields):
    if root is not None and fields:
        raise ValueError("a root model cannot have additional fields; pass either root= or fields, not both")
    return create_model(name, root=root, **fields)

Try / catch

try:
    create_model("M", root=root, field_definitions=fields)
except NotImplementedError:
    fields = None  # degrade to a pure root model
    model = create_model("M", root=root)

Prevention

When it happens

Trigger: Calling `create_model("Name", root=str, **{"extra": (int, 0)})` or `create_model("Name", root=(list[str], []), field1=(int, ...))` — any invocation that supplies both `root` and non-empty field definitions (including a leftover default like `field_definitions={"x": ...}`).

Common situations: Wrapping scalar/array types as models for structured output (root models for lists of objects) while also passing convenience fields; refactoring a normal model to a root model and forgetting to remove old field definitions; generic helper functions that always merge extra kwargs into field definitions.

Related errors


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