Reviver Class — langchain Architecture
Architecture documentation for the Reviver class in load.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 2c2a5c9e_1140_2918_51be_8d67c3da2c60["Reviver"] f3658565_d05c_7f49_b7f8_622b7ef34f33["Serializable"] 2c2a5c9e_1140_2918_51be_8d67c3da2c60 -->|extends| f3658565_d05c_7f49_b7f8_622b7ef34f33 05e0e20a_4425_e962_37a4_c6c6f08a700d["load.py"] 2c2a5c9e_1140_2918_51be_8d67c3da2c60 -->|defined in| 05e0e20a_4425_e962_37a4_c6c6f08a700d b3f6aa7f_cc79_a63c_c7f8_32c14bbf6343["__init__()"] 2c2a5c9e_1140_2918_51be_8d67c3da2c60 -->|method| b3f6aa7f_cc79_a63c_c7f8_32c14bbf6343 720dfc0b_1ea4_5ae6_b341_ab46fbd26c54["__call__()"] 2c2a5c9e_1140_2918_51be_8d67c3da2c60 -->|method| 720dfc0b_1ea4_5ae6_b341_ab46fbd26c54
Relationship Graph
Source Code
libs/core/langchain_core/load/load.py lines 268–470
class Reviver:
"""Reviver for JSON objects.
Used as the `object_hook` for `json.loads` to reconstruct LangChain objects from
their serialized JSON representation.
Only classes in the allowlist can be instantiated.
"""
def __init__(
self,
allowed_objects: Iterable[AllowedObject] | Literal["all", "core"] = "core",
secrets_map: dict[str, str] | None = None,
valid_namespaces: list[str] | None = None,
secrets_from_env: bool = False, # noqa: FBT001,FBT002
additional_import_mappings: dict[tuple[str, ...], tuple[str, ...]]
| None = None,
*,
ignore_unserializable_fields: bool = False,
init_validator: InitValidator | None = default_init_validator,
) -> None:
"""Initialize the reviver.
Args:
allowed_objects: Allowlist of classes that can be deserialized.
- `'core'` (default): Allow classes defined in the serialization
mappings for `langchain_core`.
- `'all'`: Allow classes defined in the serialization mappings.
This includes core LangChain types (messages, prompts, documents,
etc.) and trusted partner integrations. See
`langchain_core.load.mapping` for the full list.
- Explicit list of classes: Only those specific classes are allowed.
secrets_map: A map of secrets to load.
If a secret is not found in the map, it will be loaded from the
environment if `secrets_from_env` is `True`.
valid_namespaces: Additional namespaces (modules) to allow during
deserialization, beyond the default trusted namespaces.
secrets_from_env: Whether to load secrets from the environment.
additional_import_mappings: A dictionary of additional namespace mappings.
You can use this to override default mappings or add new mappings.
When `allowed_objects` is `None` (using defaults), paths from these
mappings are also added to the allowed class paths.
ignore_unserializable_fields: Whether to ignore unserializable fields.
init_validator: Optional callable to validate kwargs before instantiation.
If provided, this function is called with `(class_path, kwargs)` where
`class_path` is the class path tuple and `kwargs` is the kwargs dict.
The validator should raise an exception if the object should not be
deserialized, otherwise return `None`.
Defaults to `default_init_validator` which blocks jinja2 templates.
"""
self.secrets_from_env = secrets_from_env
self.secrets_map = secrets_map or {}
# By default, only support langchain, but user can pass in additional namespaces
self.valid_namespaces = (
[*DEFAULT_NAMESPACES, *valid_namespaces]
if valid_namespaces
else DEFAULT_NAMESPACES
)
self.additional_import_mappings = additional_import_mappings or {}
self.import_mappings = (
{
**ALL_SERIALIZABLE_MAPPINGS,
**self.additional_import_mappings,
}
if self.additional_import_mappings
else ALL_SERIALIZABLE_MAPPINGS
)
# Compute allowed class paths:
# - "all" -> use default paths from mappings (+ additional_import_mappings)
# - Explicit list -> compute from those classes
if allowed_objects in ("all", "core"):
self.allowed_class_paths: set[tuple[str, ...]] | None = (
_get_default_allowed_class_paths(
cast("Literal['all', 'core']", allowed_objects)
).copy()
)
Defined In
Extends
Source
Frequently Asked Questions
What is the Reviver class?
Reviver is a class in the langchain codebase, defined in libs/core/langchain_core/load/load.py.
Where is Reviver defined?
Reviver is defined in libs/core/langchain_core/load/load.py at line 268.
What does Reviver extend?
Reviver extends Serializable.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free