__call__() — langchain Function Reference
Architecture documentation for the __call__() function in load.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 7bf2809f_6b72_455d_041e_15ac52a675c5["__call__()"] 717df861_44bf_d747_e788_3195caa42d87["Reviver"] 7bf2809f_6b72_455d_041e_15ac52a675c5 -->|defined in| 717df861_44bf_d747_e788_3195caa42d87 style 7bf2809f_6b72_455d_041e_15ac52a675c5 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/load/load.py lines 361–470
def __call__(self, value: dict[str, Any]) -> Any:
"""Revive the value.
Args:
value: The value to revive.
Returns:
The revived value.
Raises:
ValueError: If the namespace is invalid.
ValueError: If trying to deserialize something that cannot
be deserialized in the current version of langchain-core.
NotImplementedError: If the object is not implemented and
`ignore_unserializable_fields` is False.
"""
if (
value.get("lc") == 1
and value.get("type") == "secret"
and value.get("id") is not None
):
[key] = value["id"]
if key in self.secrets_map:
return self.secrets_map[key]
if self.secrets_from_env and key in os.environ and os.environ[key]:
return os.environ[key]
return None
if (
value.get("lc") == 1
and value.get("type") == "not_implemented"
and value.get("id") is not None
):
if self.ignore_unserializable_fields:
return None
msg = (
"Trying to load an object that doesn't implement "
f"serialization: {value}"
)
raise NotImplementedError(msg)
if (
value.get("lc") == 1
and value.get("type") == "constructor"
and value.get("id") is not None
):
[*namespace, name] = value["id"]
mapping_key = tuple(value["id"])
if (
self.allowed_class_paths is not None
and mapping_key not in self.allowed_class_paths
):
msg = (
f"Deserialization of {mapping_key!r} is not allowed. "
"The default (allowed_objects='core') only permits core "
"langchain-core classes. To allow trusted partner integrations, "
"use allowed_objects='all'. Alternatively, pass an explicit list "
"of allowed classes via allowed_objects=[...]. "
"See langchain_core.load.mapping for the full allowlist."
)
raise ValueError(msg)
if (
namespace[0] not in self.valid_namespaces
# The root namespace ["langchain"] is not a valid identifier.
or namespace == ["langchain"]
):
msg = f"Invalid namespace: {value}"
raise ValueError(msg)
# Determine explicit import path
if mapping_key in self.import_mappings:
import_path = self.import_mappings[mapping_key]
# Split into module and name
import_dir, name = import_path[:-1], import_path[-1]
elif namespace[0] in DISALLOW_LOAD_FROM_PATH:
msg = (
"Trying to deserialize something that cannot "
"be deserialized in current version of langchain-core: "
f"{mapping_key}."
)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does __call__() do?
__call__() is a function in the langchain codebase, defined in libs/core/langchain_core/load/load.py.
Where is __call__() defined?
__call__() is defined in libs/core/langchain_core/load/load.py at line 361.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free