langchain-ai/langchain · error · ValueError
`default` should not be passed to dumps
Error message
`default` should not be passed to dumps
What it means
Raised by langchain_core.load.dumps when the caller passes json.dumps' `default` kwarg. LangChain installs its own serializer (_serialize_value) as the default handler, and a user-supplied `default` would silently bypass LangChain's escaping of user data (including 'lc'-keyed dicts and secret handling), so it is explicitly rejected.
Source
Thrown at libs/core/langchain_core/load/dump.py:94
deserialization.
Args:
obj: The object to dump.
pretty: Whether to pretty print the json.
If `True`, the json will be indented by either 2 spaces or the amount
provided in the `indent` kwarg.
**kwargs: Additional arguments to pass to `json.dumps`
Returns:
A JSON string representation of the object.
Raises:
ValueError: If `default` is passed as a kwarg.
"""
if "default" in kwargs:
msg = "`default` should not be passed to dumps"
raise ValueError(msg)
obj = _dump_pydantic_models(obj)
serialized = _serialize_value(obj)
if pretty:
indent = kwargs.pop("indent", 2)
return json.dumps(serialized, indent=indent, **kwargs)
return json.dumps(serialized, **kwargs)
def dumpd(obj: Any) -> Any:
"""Return a dict representation of an object.
Note:
Plain dicts containing an `'lc'` key are automatically escaped to prevent
confusion with LC serialization format. The escape marker is removed during
deserialization.
View on GitHub (pinned to e32fa9a52e)
Solutions
- Remove the default kwarg and rely on LangChain's built-in serialization
- Pre-convert custom types to dicts/primitives before calling dumps
- Wrap custom classes as Serializable subclasses so dumps handles them natively
Example fix
# before dumps(obj, default=lambda o: o.__dict__) # after dumps(obj) # pre-convert custom types to plain dicts yourself
Defensive patterns
Strategy: validation
Validate before calling
kwargs.pop('default', None) # never forward `default` to langchain's dumps
from langchain_core.load import dumps
dumps(obj, **kwargs) Try / catch
try:
dumps(obj, **json_kwargs)
except ValueError as e:
if 'default' in str(e):
json_kwargs.pop('default', None)
dumps(obj, **json_kwargs)
else:
raise Prevention
- Do not reuse json.dumps kwargs with langchain_core.load.dumps
- Pre-convert custom types to plain data instead of relying on a default hook
When it happens
Trigger: dumps(obj, default=my_encoder); forwarding **json_kwargs collected from elsewhere that happen to include 'default'. Any kwargs are otherwise passed through to json.dumps, but 'default' is reserved.
Common situations: Reusing a json.dumps(...) call's kwargs verbatim when switching to langchain dumps; attempting to support custom types via a default hook instead of Serializable.
Related errors
- Failed to hash metadata: {e}. Please use a dict that can be
- Expected Serializable, got {type(obj)}
- {f.__name__}() got multiple values for argument {new!r}
- invalid IP address
- private IP range
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/f5e81a1256b42fb9.
Report an issue: GitHub.