Revive a LangChain class from a JSON string.
Equivalent to load(json.loads(text)).
Only classes in the allowlist can be instantiated. The default allowlist includes
core LangChain types (messages, prompts, documents, etc.). See
langchain_core.load.mapping for the full list.
This function instantiates Python objects and can trigger side effects
during deserialization. Never call loads() on data from an untrusted
or unauthenticated source. See the module-level security model
documentation for details and best practices.
loads(
text: str,
*,
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,
additional_import_mappings: dict[tuple[str, ...], tuple[str, ...]] | None = None,
ignore_unserializable_fields: bool = False,
init_validator: InitValidator | None = default_init_validator
) -> Any| Name | Type | Description |
|---|---|---|
text* | str | The string to load. |
allowed_objects | Iterable[AllowedObject] | Literal['all', 'core'] | Default: 'core'Allowlist of classes that can be deserialized.
|
secrets_map | dict[str, str] | None | Default: NoneA map of secrets to load. Only include the specific secrets the serialized object requires. If
a secret is not found in the map, it will be loaded from the
environment if |
valid_namespaces | list[str] | None | Default: NoneAdditional namespaces (modules) to allow during deserialization, beyond the default trusted namespaces. |
secrets_from_env | bool | Default: FalseWhether to load secrets from the environment. A crafted payload can name arbitrary environment variables in its
|
additional_import_mappings | dict[tuple[str, ...], tuple[str, ...]] | None | Default: NoneA dictionary of additional namespace mappings. You can use this to override default mappings or add new mappings. When |
ignore_unserializable_fields | bool | Default: FalseWhether to ignore unserializable fields. |
init_validator | InitValidator | None | Default: default_init_validatorOptional callable to validate kwargs before instantiation. If provided, this function is called with Defaults to |