{"record":{"id":"26e33085e952b62e","repo":"langchain-ai/langchain","slug":"invalid-namespace-value","errorCode":null,"errorMessage":"Invalid namespace: {value}","messagePattern":"Invalid namespace: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"libs/core/langchain_core/load/load.py","lineNumber":526,"sourceCode":"                and mapping_key not in self.allowed_class_paths\n            ):\n                msg = (\n                    f\"Deserialization of {mapping_key!r} is not allowed. \"\n                    \"The default (allowed_objects='core') only permits core \"\n                    \"langchain-core classes. To allow trusted partner integrations, \"\n                    \"use allowed_objects='all'. Alternatively, pass an explicit list \"\n                    \"of allowed classes via allowed_objects=[...]. \"\n                    \"See langchain_core.load.mapping for the full allowlist.\"\n                )\n                raise ValueError(msg)\n\n            if (\n                namespace[0] not in self.valid_namespaces\n                # The root namespace [\"langchain\"] is not a valid identifier.\n                or namespace == [\"langchain\"]\n            ):\n                msg = f\"Invalid namespace: {value}\"\n                raise ValueError(msg)\n            # Determine explicit import path\n            if mapping_key in self.import_mappings:\n                import_path = self.import_mappings[mapping_key]\n                # Split into module and name\n                import_dir, name = import_path[:-1], import_path[-1]\n            elif namespace[0] in DISALLOW_LOAD_FROM_PATH:\n                msg = (\n                    \"Trying to deserialize something that cannot \"\n                    \"be deserialized in current version of langchain-core: \"\n                    f\"{mapping_key}.\"\n                )\n                raise ValueError(msg)\n            else:\n                # Otherwise, treat namespace as path.\n                import_dir = namespace\n\n            # Validate import path is in trusted namespaces before importing\n            if import_dir[0] not in self.valid_namespaces:","sourceCodeStart":508,"sourceCodeEnd":544,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/load/load.py#L508-L544","documentation":"Namespace validation error from the Reviver: the first element of the serialized object's id (its namespace, e.g. ['langchain_core', 'prompts', ...]) is not in valid_namespaces, or the namespace is exactly ['langchain'] (the legacy root, which is not importable). This guards against importing modules from unapproved top-level namespaces.","triggerScenarios":"loads of a payload whose id starts with an unexpected root, e.g. ['mycompany', 'tools', 'CustomTool'], when valid_namespaces defaults to {'langchain_core', ...}; legacy payloads with id ['langchain', 'chain', 'LLMChain']. Distinct from error 117, which fires later on the resolved import path.","commonSituations":"Loading serialized objects produced by custom subclasses that use a private namespace; very old serialized chains from the pre-langchain-core 'langchain' namespace era; interop with payloads from forks that renamed top-level packages.","solutions":["If you trust the payload's namespace, pass it through: loads(text, valid_namespaces=['mycompany', 'langchain_core'])","Re-serialize the object in the current version so its lc_id matches an importable namespace","For custom classes, override lc_id()/lc_namespace to align with an approved import path"],"exampleFix":"# before\nobj = loads(payload)  # id starts with 'mycompany'\n# after\nobj = loads(payload, valid_namespaces=['langchain_core', 'langchain', 'mycompany'])","handlingStrategy":"validation","validationCode":"import json\npayload = json.loads(text)\nroots = {node['id'][0] for node in iter_constructor_nodes(payload)}\nallowed_roots = {'langchain_core'}\nif not roots <= allowed_roots:\n    # pass valid_namespaces=roots | allowed_roots, or reject\n    ...","typeGuard":null,"tryCatchPattern":"try:\n    obj = loads(text)\nexcept ValueError as e:\n    if 'Invalid namespace' in str(e) and payload_is_trusted:\n        obj = loads(text, valid_namespaces=['langchain_core', *extra_roots])\n    else:\n        raise","preventionTips":["Give custom Serializable subclasses an lc_id()/lc_namespace under a root you control and whitelist","Re-serialize objects with the current library version before archiving them","Never widen valid_namespaces for payloads from untrusted sources"],"tags":["security","deserialization","namespace","load"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}