# RootModel

RootModel class and type definitions.

## RootModel

**Bases:** [`BaseModel`](/guides/pydantic-base-model#basemodel), `Generic[RootModelRootType]`

:::callout{intent="note" title="Usage Documentation"}
[`RootModel` and Custom Root Types](/guides/concepts-models#rootmodel-and-custom-root-types)
:::

A Pydantic `BaseModel` for the root object of the model.

### Attributes

#### root

The root object of the model.

**Type:** `RootModelRootType`

#### \_\_pydantic\_root\_model\_\_

Whether the model is a RootModel.

#### \_\_pydantic\_private\_\_

Private fields in the model.

#### \_\_pydantic\_extra\_\_

Extra fields in the model.

### Methods

#### model\_construct

`@classmethod`

```python
def model_construct(
    cls,
    root: RootModelRootType,
    _fields_set: set[str] | None = None,
) -> Self
```

Create a new model using the provided root object and update fields set.

##### Returns

[`Self`](https://docs.python.org/3/library/typing.html#typing.Self) — The new model.

##### Parameters

**`root`** : `RootModelRootType`

The root object of the model.

**`_fields_set`** : [`set`](https://docs.python.org/3/reference/expressions.html#set)\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)] | [`None`](https://docs.python.org/3/builtins/constants.html#None) _Default:_ `None`

The set of fields to be updated.

##### Raises

- `NotImplemented` — If the model is not a subclass of `RootModel`.

#### model\_dump

```python
def model_dump(
    *,
    mode: Literal['json', 'python'] | str = 'python',
    include: Any = None,
    exclude: Any = None,
    context: dict[str, Any] | None = None,
    by_alias: bool | None = None,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False,
    exclude_computed_fields: bool = False,
    round_trip: bool = False,
    warnings: bool | Literal['none', 'warn', 'error'] = True,
    serialize_as_any: bool = False,
) -> Any
```

This method is included just to get a more accurate return type for type checkers. It is included in this `if TYPE_CHECKING:` block since no override is actually necessary.

See the documentation of `BaseModel.model_dump` for more details about the arguments.

Generally, this method will have a return type of `RootModelRootType`, assuming that `RootModelRootType` is not a `BaseModel` subclass. If `RootModelRootType` is a `BaseModel` subclass, then the return type will likely be `dict[str, Any]`, as `model_dump` calls are recursive. The return type could even be something different, in the case of a custom serializer. Thus, `Any` is used here to catch all of these cases.

##### Returns

[`Any`](https://docs.python.org/3/library/typing.html#typing.Any)

Was this page helpful?

## Related pages

- [API Documentation](./api-documentation-index.md)
- [Concepts](./concepts-index.md)
- [Dev Tools](./dev-tools-index.md)
- [Error Messages](./error-messages-index.md)
- [Examples](./examples-index.md)
- [Integrations](./integrations-index.md)
- [Internals](./internals-index.md)
- [Production Tools](./production-tools-index.md)
- [Pydantic](./pydantic-index.md)
- [Pydantic Core](./pydantic-core-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
