Home / Class/ Serializable Class — langchain Architecture

Serializable Class — langchain Architecture

Architecture documentation for the Serializable class in serializable.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  f3658565_d05c_7f49_b7f8_622b7ef34f33["Serializable"]
  b5d5ce95_4e41_41ed_7fe6_1a936c2c18f4["serializable.py"]
  f3658565_d05c_7f49_b7f8_622b7ef34f33 -->|defined in| b5d5ce95_4e41_41ed_7fe6_1a936c2c18f4
  1ca75786_23ae_d559_1153_cbd5239705d5["__init__()"]
  f3658565_d05c_7f49_b7f8_622b7ef34f33 -->|method| 1ca75786_23ae_d559_1153_cbd5239705d5
  3773f2e4_1571_e10d_6e96_821cf09d5abd["is_lc_serializable()"]
  f3658565_d05c_7f49_b7f8_622b7ef34f33 -->|method| 3773f2e4_1571_e10d_6e96_821cf09d5abd
  98d341b3_2d98_5955_2089_df9784d6e203["get_lc_namespace()"]
  f3658565_d05c_7f49_b7f8_622b7ef34f33 -->|method| 98d341b3_2d98_5955_2089_df9784d6e203
  d5bdc41f_3baa_8268_2bc7_9fdcb07d842f["lc_secrets()"]
  f3658565_d05c_7f49_b7f8_622b7ef34f33 -->|method| d5bdc41f_3baa_8268_2bc7_9fdcb07d842f
  27094093_94b3_135b_5cc8_38e7bfbb2821["lc_attributes()"]
  f3658565_d05c_7f49_b7f8_622b7ef34f33 -->|method| 27094093_94b3_135b_5cc8_38e7bfbb2821
  47dda569_0afc_9a11_4184_278a31d1c32e["lc_id()"]
  f3658565_d05c_7f49_b7f8_622b7ef34f33 -->|method| 47dda569_0afc_9a11_4184_278a31d1c32e
  ae8dd777_ab0a_6050_e766_fdbeec2727a6["__repr_args__()"]
  f3658565_d05c_7f49_b7f8_622b7ef34f33 -->|method| ae8dd777_ab0a_6050_e766_fdbeec2727a6
  1d0f0a19_7194_6a37_5750_0e64e020c9c4["to_json()"]
  f3658565_d05c_7f49_b7f8_622b7ef34f33 -->|method| 1d0f0a19_7194_6a37_5750_0e64e020c9c4
  2303e3f8_c7b8_2493_e3a3_ddb8cd0f10ca["to_json_not_implemented()"]
  f3658565_d05c_7f49_b7f8_622b7ef34f33 -->|method| 2303e3f8_c7b8_2493_e3a3_ddb8cd0f10ca

Relationship Graph

Source Code

libs/core/langchain_core/load/serializable.py lines 88–280

class Serializable(BaseModel, ABC):
    """Serializable base class.

    This class is used to serialize objects to JSON.

    It relies on the following methods and properties:

    - [`is_lc_serializable`][langchain_core.load.serializable.Serializable.is_lc_serializable]: Is this class serializable?

        By design, even if a class inherits from `Serializable`, it is not serializable
        by default. This is to prevent accidental serialization of objects that should
        not be serialized.
    - [`get_lc_namespace`][langchain_core.load.serializable.Serializable.get_lc_namespace]: Get the namespace of the LangChain object.

        During deserialization, this namespace is used to identify
        the correct class to instantiate.

        Please see the `Reviver` class in `langchain_core.load.load` for more details.

        During deserialization an additional mapping is handle classes that have moved
        or been renamed across package versions.

    - [`lc_secrets`][langchain_core.load.serializable.Serializable.lc_secrets]: A map of constructor argument names to secret ids.
    - [`lc_attributes`][langchain_core.load.serializable.Serializable.lc_attributes]: List of additional attribute names that should be included
        as part of the serialized representation.
    """  # noqa: E501

    # Remove default BaseModel init docstring.
    def __init__(self, *args: Any, **kwargs: Any) -> None:
        """"""  # noqa: D419  # Intentional blank docstring
        super().__init__(*args, **kwargs)

    @classmethod
    def is_lc_serializable(cls) -> bool:
        """Is this class serializable?

        By design, even if a class inherits from `Serializable`, it is not serializable
        by default. This is to prevent accidental serialization of objects that should
        not be serialized.

        Returns:
            Whether the class is serializable. Default is `False`.
        """
        return False

    @classmethod
    def get_lc_namespace(cls) -> list[str]:
        """Get the namespace of the LangChain object.

        For example, if the class is
        [`langchain.llms.openai.OpenAI`][langchain_openai.OpenAI], then the namespace is
        `["langchain", "llms", "openai"]`

        Returns:
            The namespace.
        """
        return cls.__module__.split(".")

    @property
    def lc_secrets(self) -> dict[str, str]:
        """A map of constructor argument names to secret ids.

        For example, `{"openai_api_key": "OPENAI_API_KEY"}`
        """
        return {}

    @property
    def lc_attributes(self) -> dict:
        """List of attribute names that should be included in the serialized kwargs.

        These attributes must be accepted by the constructor.

        Default is an empty dictionary.
        """
        return {}

    @classmethod
    def lc_id(cls) -> list[str]:
        """Return a unique identifier for this class for serialization purposes.

        The unique identifier is a list of strings that describes the path

Frequently Asked Questions

What is the Serializable class?
Serializable is a class in the langchain codebase, defined in libs/core/langchain_core/load/serializable.py.
Where is Serializable defined?
Serializable is defined in libs/core/langchain_core/load/serializable.py at line 88.

Analyze Your Own Codebase

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

Try Supermodel Free