{"record":{"id":"f5e81a1256b42fb9","repo":"langchain-ai/langchain","slug":"default-should-not-be-passed-to-dumps","errorCode":null,"errorMessage":"`default` should not be passed to dumps","messagePattern":"`default` should not be passed to dumps","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/load/dump.py","lineNumber":94,"sourceCode":"        deserialization.\n\n    Args:\n        obj: The object to dump.\n        pretty: Whether to pretty print the json.\n\n            If `True`, the json will be indented by either 2 spaces or the amount\n            provided in the `indent` kwarg.\n        **kwargs: Additional arguments to pass to `json.dumps`\n\n    Returns:\n        A JSON string representation of the object.\n\n    Raises:\n        ValueError: If `default` is passed as a kwarg.\n    \"\"\"\n    if \"default\" in kwargs:\n        msg = \"`default` should not be passed to dumps\"\n        raise ValueError(msg)\n\n    obj = _dump_pydantic_models(obj)\n    serialized = _serialize_value(obj)\n\n    if pretty:\n        indent = kwargs.pop(\"indent\", 2)\n        return json.dumps(serialized, indent=indent, **kwargs)\n    return json.dumps(serialized, **kwargs)\n\n\ndef dumpd(obj: Any) -> Any:\n    \"\"\"Return a dict representation of an object.\n\n    Note:\n        Plain dicts containing an `'lc'` key are automatically escaped to prevent\n        confusion with LC serialization format. The escape marker is removed during\n        deserialization.\n","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/load/dump.py#L76-L112","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\ndumps(obj, default=lambda o: o.__dict__)\n# after\ndumps(obj)  # pre-convert custom types to plain dicts yourself","handlingStrategy":"validation","validationCode":"kwargs.pop('default', None)  # never forward `default` to langchain's dumps\nfrom langchain_core.load import dumps\ndumps(obj, **kwargs)","typeGuard":null,"tryCatchPattern":"try:\n    dumps(obj, **json_kwargs)\nexcept ValueError as e:\n    if 'default' in str(e):\n        json_kwargs.pop('default', None)\n        dumps(obj, **json_kwargs)\n    else:\n        raise","preventionTips":["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"],"tags":["serialization","dump","json","kwargs","security"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}