langchain-ai/langchain · critical · ValueError
Deserialization of {mapping_key!r} is not allowed. The defau
Error message
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. What it means
Allowlist enforcement error from the Reviver: the serialized object's class path (mapping_key) is not in the set of permitted class paths. Default loads() behavior (allowed_objects='core') only permits langchain-core classes; partner classes like langchain_openai must be opted in. This exists because deserialization imports and instantiates arbitrary code paths, so it is a security boundary.
Source
Thrown at libs/core/langchain_core/load/load.py:518
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}."View on GitHub (pinned to e32fa9a52e)
Solutions
- If the payload is trusted, load with allowed_objects='all'
- Or extend the explicit allowlist: allowed_objects=[ChatOpenAI, PromptTemplate, ...] covering every class in the payload
- Check langchain_core.load.mapping (e.g. SERIALIZABLE_MAPPING / import_mappings) for the exact class paths in your payload and add each one
Example fix
# before chain = loads(serialized) # default allowed_objects='core' # after chain = loads(serialized, allowed_objects='all') # trusted payloads only
Defensive patterns
Strategy: validation
Validate before calling
from langchain_core.load.mapping import SERIALIZABLE_MAPPING
import json
payload = json.loads(text)
used_paths = {tuple(n['id']) for n in iter_constructor_nodes(payload)}
missing = used_paths - SERIALIZABLE_MAPPING.keys()
if missing:
# widen allowlist accordingly
... Try / catch
try:
obj = loads(text)
except ValueError as e:
if 'not allowed' in str(e) and source_is_trusted:
obj = loads(text, allowed_objects='all')
else:
raise Prevention
- Treat serialized chains like code: only load from trusted sources
- Standardize on allowed_objects='all' (trusted) or an explicit complete class list in your loader
- After adding a new component to a chain, re-run the loads smoke test — nested classes need allowlisting too
When it happens
Trigger: loads(dumps(chat_openai_chain)) using default settings — the payload contains ['langchain_openai', ...] which is outside core; also fires when an explicit allowed_objects=[...] list omits a nested class used inside the payload.
Common situations: Serializing a chain in one service and loading it in another with default flags; upgrading to a LangChain version where the restricted allowlist became the default; explicit allowlists that forget a nested component (e.g. allows the prompt but not the message class).
Related errors
- Invalid namespace: {value}
- Jinja2 templates are not allowed during deserialization for
- allowed_objects must contain Serializable subclasses.
- invalid IP address
- private IP range
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/0b1ef58d094c4246.
Report an issue: GitHub.