keras-team/keras · error · ValueError

Invalid input type for serialization. Received: {fn} of type

Error message

Invalid input type for serialization. Received: {fn} of type {type(fn)}.

What it means

Error "Invalid input type for serialization. Received: {fn} of type {type(fn)}." thrown in keras-team/keras.

Source

Thrown at keras/src/layers/core/lambda_layer.py:164

            self.arguments
        )
        base_config = super().get_config()
        return {**base_config, **config}

    def _serialize_function_to_config(self, fn):
        if isinstance(fn, types.LambdaType) and fn.__name__ == "<lambda>":
            code, defaults, closure = python_utils.func_dump(fn)
            return {
                "class_name": "__lambda__",
                "config": {
                    "code": code,
                    "defaults": defaults,
                    "closure": closure,
                },
            }
        elif callable(fn):
            return serialization_lib.serialize_keras_object(fn)
        raise ValueError(
            "Invalid input type for serialization. "
            f"Received: {fn} of type {type(fn)}."
        )

    @staticmethod
    def _raise_for_lambda_deserialization(safe_mode):
        if safe_mode:
            raise ValueError(
                "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()."
            )

    @classmethod

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/layers/core/lambda_layer.py:164 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/272807a19586c358. Report an issue: GitHub.