{"record":{"id":"272807a19586c358","repo":"keras-team/keras","slug":"invalid-input-type-for-serialization-received-f","errorCode":null,"errorMessage":"Invalid input type for serialization. Received: {fn} of type {type(fn)}.","messagePattern":"Invalid input type for serialization\\. Received: (.+?) of type (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/core/lambda_layer.py","lineNumber":164,"sourceCode":"            self.arguments\n        )\n        base_config = super().get_config()\n        return {**base_config, **config}\n\n    def _serialize_function_to_config(self, fn):\n        if isinstance(fn, types.LambdaType) and fn.__name__ == \"<lambda>\":\n            code, defaults, closure = python_utils.func_dump(fn)\n            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","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/core/lambda_layer.py#L146-L182","documentation":"Sentinel error from Lambda._serialize_function_to_config: the function to serialize is neither a Python lambda (dumpable via func_dump) nor a registered callable that serialize_keras_object can handle, so no serialization path exists for it. The offending object is echoed with its type.","triggerScenarios":"Thrown at keras/src/layers/core/lambda_layer.py:164 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Wrap the logic in a plain Python lambda so it can be dumped as code","Use a named, registered function or @keras.saving.register_keras_serializable class that serialize_keras_object supports","If the function need not round-trip, avoid calling get_config/saving on this Lambda layer"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}