Home / Function/ _create_root_model() — langchain Function Reference

_create_root_model() — langchain Function Reference

Architecture documentation for the _create_root_model() function in pydantic.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  2871abd3_cccd_0317_0db7_f334717b473b["_create_root_model()"]
  892b1d9f_bb87_0364_19af_71382204e430["pydantic.py"]
  2871abd3_cccd_0317_0db7_f334717b473b -->|defined in| 892b1d9f_bb87_0364_19af_71382204e430
  2871abd3_cccd_0317_0db7_f334717b473b["_create_root_model()"]
  2871abd3_cccd_0317_0db7_f334717b473b -->|calls| 2871abd3_cccd_0317_0db7_f334717b473b
  b9af98f3_3d27_bff1_7437_4fe45a239f0b["_create_root_model_cached()"]
  b9af98f3_3d27_bff1_7437_4fe45a239f0b -->|calls| 2871abd3_cccd_0317_0db7_f334717b473b
  b8865414_42c0_49d9_3e9c_7fa9ff60c3a7["create_model_v2()"]
  b8865414_42c0_49d9_3e9c_7fa9ff60c3a7 -->|calls| 2871abd3_cccd_0317_0db7_f334717b473b
  2871abd3_cccd_0317_0db7_f334717b473b["_create_root_model()"]
  2871abd3_cccd_0317_0db7_f334717b473b -->|calls| 2871abd3_cccd_0317_0db7_f334717b473b
  style 2871abd3_cccd_0317_0db7_f334717b473b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/utils/pydantic.py lines 350–408

def _create_root_model(
    name: str,
    type_: Any,
    module_name: str | None = None,
    default_: object = NO_DEFAULT,
) -> type[BaseModel]:
    """Create a base class."""

    def schema(
        cls: type[BaseModelV1],
        by_alias: bool = True,  # noqa: FBT001,FBT002
        ref_template: str = DEFAULT_REF_TEMPLATE,
    ) -> dict[str, Any]:
        super_cls = cast("type[BaseModelV1]", super(cls, cls))
        schema_ = super_cls.schema(by_alias=by_alias, ref_template=ref_template)
        schema_["title"] = name
        return schema_

    def model_json_schema(
        cls: type[BaseModel],
        by_alias: bool = True,  # noqa: FBT001,FBT002
        ref_template: str = DEFAULT_REF_TEMPLATE,
        schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema,
        mode: JsonSchemaMode = "validation",
    ) -> dict[str, Any]:
        super_cls = cast("type[BaseModel]", super(cls, cls))
        schema_ = super_cls.model_json_schema(
            by_alias=by_alias,
            ref_template=ref_template,
            schema_generator=schema_generator,
            mode=mode,
        )
        schema_["title"] = name
        return schema_

    base_class_attributes = {
        "__annotations__": {"root": type_},
        "model_config": ConfigDict(arbitrary_types_allowed=True),
        "schema": classmethod(schema),
        "model_json_schema": classmethod(model_json_schema),
        "__module__": module_name or "langchain_core.runnables.utils",
    }

    if default_ is not NO_DEFAULT:
        base_class_attributes["root"] = default_
    with warnings.catch_warnings():
        try:
            if (
                isinstance(type_, type)
                and not isinstance(type_, GenericAlias)
                and issubclass(type_, BaseModelV1)
            ):
                warnings.filterwarnings(
                    action="ignore", category=PydanticDeprecationWarning
                )
        except TypeError:
            pass
        custom_root_type = type(name, (RootModel,), base_class_attributes)
    return cast("type[BaseModel]", custom_root_type)

Domain

Subdomains

Frequently Asked Questions

What does _create_root_model() do?
_create_root_model() is a function in the langchain codebase, defined in libs/core/langchain_core/utils/pydantic.py.
Where is _create_root_model() defined?
_create_root_model() is defined in libs/core/langchain_core/utils/pydantic.py at line 350.
What does _create_root_model() call?
_create_root_model() calls 1 function(s): _create_root_model.
What calls _create_root_model()?
_create_root_model() is called by 3 function(s): _create_root_model, _create_root_model_cached, create_model_v2.

Analyze Your Own Codebase

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

Try Supermodel Free