Home / Function/ RootModel() — anthropic-sdk-python Function Reference

RootModel() — anthropic-sdk-python Function Reference

Architecture documentation for the RootModel() function in _models.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  a4bf9be6_9a75_77f9_5ad6_bb079f612643["RootModel()"]
  3912cc3f_b0e8_a732_b8e2_613b018b830d["_models.py"]
  a4bf9be6_9a75_77f9_5ad6_bb079f612643 -->|defined in| 3912cc3f_b0e8_a732_b8e2_613b018b830d
  style a4bf9be6_9a75_77f9_5ad6_bb079f612643 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/_models.py lines 804–837

    class RootModel(GenericModel, Generic[_T]):
        """Used as a placeholder to easily convert runtime types to a Pydantic format
        to provide validation.

        For example:
        ```py
        validated = RootModel[int](__root__="5").__root__
        # validated: 5
        ```
        """

        __root__: _T

    def _validate_non_model_type(*, type_: type[_T], value: object) -> _T:
        model = _create_pydantic_model(type_).validate(value)
        return cast(_T, model.__root__)

    def _create_pydantic_model(type_: _T) -> Type[RootModel[_T]]:
        return RootModel[type_]  # type: ignore

    def TypeAdapter(*_args: Any, **_kwargs: Any) -> Any:
        raise RuntimeError("attempted to use TypeAdapter in pydantic v1")

    def computed_field(func: Any | None = None, /, **__: Any) -> Any:
        def _exc_func(*_: Any, **__: Any) -> Any:
            raise RuntimeError("attempted to use computed_field in pydantic v1")

        def _dec(*_: Any, **__: Any) -> Any:
            return _exc_func

        if func is not None:
            return _dec(func)
        else:
            return _dec

Subdomains

Frequently Asked Questions

What does RootModel() do?
RootModel() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/_models.py.
Where is RootModel() defined?
RootModel() is defined in src/anthropic/_models.py at line 804.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free