{"record":{"id":"478a71a8cc924253","repo":"keras-team/keras","slug":"requested-the-deserialization-of-a-lambda-layer","errorCode":null,"errorMessage":"Requested the deserialization of a `Lambda` layer whose `function` is a Python lambda. This carries a potential risk of arbitrary code execution and thus it is disallowed by default. If you trust the source of the artifact, you can override this error by passing `safe_mode=False` to the loading function, or calling `keras.config.enable_unsafe_deserialization().","messagePattern":"Requested the deserialization of a `Lambda` layer whose `function` is a Python lambda\\. This carries a potential risk of arbitrary code execution and thus it is disallowed by default\\. If you trust the source of the artifact, you can override this error by passing `safe_mode=False` to the loading function, or calling `keras\\.config\\.enable_unsafe_deserialization\\(\\)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/core/lambda_layer.py","lineNumber":172,"sourceCode":"            return {\n                \"class_name\": \"__lambda__\",\n                \"config\": {\n                    \"code\": code,\n                    \"defaults\": defaults,\n                    \"closure\": closure,\n                },\n            }\n        elif callable(fn):\n            return serialization_lib.serialize_keras_object(fn)\n        raise ValueError(\n            \"Invalid input type for serialization. \"\n            f\"Received: {fn} of type {type(fn)}.\"\n        )\n\n    @staticmethod\n    def _raise_for_lambda_deserialization(safe_mode):\n        if safe_mode:\n            raise ValueError(\n                \"Requested the deserialization of a `Lambda` layer whose \"\n                \"`function` is a Python lambda. This carries a potential risk \"\n                \"of arbitrary code execution and thus it is disallowed by \"\n                \"default. If you trust the source of the artifact, you can \"\n                \"override this error by passing `safe_mode=False` to the \"\n                \"loading function, or calling \"\n                \"`keras.config.enable_unsafe_deserialization().\"\n            )\n\n    @classmethod\n    def from_config(cls, config, custom_objects=None, safe_mode=None):\n        # When `safe_mode` is unset, fall back to the ambient deserialization\n        # scope, treating an unset scope as safe. This fails closed so that\n        # deserializing a `Lambda` outside of a `SafeModeScope` (e.g. a direct\n        # `from_config` call) does not silently allow arbitrary code execution.\n        effective_safe_mode = (\n            safe_mode\n            if safe_mode is not None","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/core/lambda_layer.py#L154-L190","documentation":"Error \"Requested the deserialization of a `Lambda` layer whose `function` is a Python lambda. This carries a potential risk of arbitrary code execution and thus it is disallowed by default. If you trust the source of the artifact, you can override this error by passing `safe_mode=False` to the loading function, or calling `keras.config.enable_unsafe_deserialization().\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/layers/core/lambda_layer.py:172 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}