Home / Function/ _schema() — langchain Function Reference

_schema() — langchain Function Reference

Architecture documentation for the _schema() function in pydantic_utils.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  231942ec_e6ee_db67_4aa9_62b78c60b2f1["_schema()"]
  b22df862_b52d_14dc_cb85_6573258dd27c["pydantic_utils.py"]
  231942ec_e6ee_db67_4aa9_62b78c60b2f1 -->|defined in| b22df862_b52d_14dc_cb85_6573258dd27c
  4b6cb995_0278_5df7_b4c7_82cb6b0b8320["replace_all_of_with_ref()"]
  231942ec_e6ee_db67_4aa9_62b78c60b2f1 -->|calls| 4b6cb995_0278_5df7_b4c7_82cb6b0b8320
  80bb1e8b_2eb4_f11f_8739_d03f6bd4a5c3["remove_all_none_default()"]
  231942ec_e6ee_db67_4aa9_62b78c60b2f1 -->|calls| 80bb1e8b_2eb4_f11f_8739_d03f6bd4a5c3
  ffb01e2b_2f23_d6e1_f1e0_57d9068238b3["_remove_additionalproperties()"]
  231942ec_e6ee_db67_4aa9_62b78c60b2f1 -->|calls| ffb01e2b_2f23_d6e1_f1e0_57d9068238b3
  308f0879_d0aa_7d08_b310_9c1f1b32e7b1["_remove_enum()"]
  231942ec_e6ee_db67_4aa9_62b78c60b2f1 -->|calls| 308f0879_d0aa_7d08_b310_9c1f1b32e7b1
  style 231942ec_e6ee_db67_4aa9_62b78c60b2f1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/pydantic_utils.py lines 76–99

def _schema(obj: Any) -> dict:
    """Return the schema of the object."""
    # Remap to old style schema
    if isclass(obj):
        if issubclass(obj, BaseModelV1):
            return obj.schema()
        if issubclass(obj, BaseModel):
            schema_ = obj.model_json_schema(ref_template="#/definitions/{model}")
            if "$defs" in schema_:
                schema_["definitions"] = schema_["$defs"]
                del schema_["$defs"]

            if "default" in schema_ and schema_["default"] is None:
                del schema_["default"]

            replace_all_of_with_ref(schema_)
            remove_all_none_default(schema_)
            _remove_additionalproperties(schema_)
            _remove_enum(schema_)

            return schema_

    msg = f"Object must be a Pydantic BaseModel subclass. Got {type(obj)}"
    raise TypeError(msg)

Subdomains

Frequently Asked Questions

What does _schema() do?
_schema() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/pydantic_utils.py.
Where is _schema() defined?
_schema() is defined in libs/core/tests/unit_tests/pydantic_utils.py at line 76.
What does _schema() call?
_schema() calls 4 function(s): _remove_additionalproperties, _remove_enum, remove_all_none_default, replace_all_of_with_ref.

Analyze Your Own Codebase

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

Try Supermodel Free