docs(core): expanded get_lc_namespace docstring (#35229)

This commit is contained in:
Mason Daugherty
2026-02-15 02:39:39 -05:00
committed by GitHub
parent f9fd7be695
commit 1573757b3b

View File

@@ -134,9 +134,22 @@ class Serializable(BaseModel, ABC):
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"]`
The default implementation splits `cls.__module__` on `'.'`, e.g.
`langchain_openai.chat_models` becomes
`["langchain_openai", "chat_models"]`. This value is used by `lc_id` to
build the serialization identifier.
New partner packages should **not** override this method. The default
behavior is correct for any class whose module path already reflects
its package name. Some older packages (e.g. `langchain-openai`,
`langchain-anthropic`) override it to return a legacy-style namespace
like `["langchain", "chat_models", "openai"]`, matching the module
paths that existed before those integrations were split out of the
main `langchain` package. Those overrides are kept for
backwards-compatible deserialization; new packages should not copy them.
Deserialization mapping is handled separately by
`SERIALIZABLE_MAPPING` in `langchain_core.load.mapping`.
Returns:
The namespace.