keras-team/keras · error · ValueError

The input '{input_name}' is not optional, but None was passe

Error message

The input '{input_name}' is not optional, but None was passed. Please provide a valid tensor.

What it means

Error "The input '{input_name}' is not optional, but None was passed. Please provide a valid tensor." thrown in keras-team/keras.

Source

Thrown at keras/src/models/functional.py:274

    def _convert_inputs_to_tensors(self, flat_inputs):
        converted = []
        for x, input_tensor in zip(flat_inputs, self._inputs):
            if x is None:
                # Only enforce optional semantics when the input tensor was
                # created by an `InputLayer`. For other kinds of tensors
                # (e.g. tensors produced dynamically) preserve previous
                # behavior and allow None to pass through.
                input_layer = None
                if (
                    hasattr(input_tensor, "_keras_history")
                    and input_tensor._keras_history
                ):
                    input_layer = input_tensor._keras_history.operation

                if isinstance(input_layer, InputLayer):
                    if not input_layer.optional:
                        input_name = input_tensor.name
                        raise ValueError(
                            (
                                f"The input '{input_name}' is not optional, "
                                "but None was passed. "
                                "Please provide a valid tensor."
                            )
                        )
                # If input_layer is not an InputLayer, fall back to previous
                # behavior and accept None.
                converted.append(x)
            else:
                converted.append(
                    ops.convert_to_tensor(
                        x,
                        dtype=input_tensor.dtype,
                        sparse=input_tensor.sparse,
                    )
                )
        return converted

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/models/functional.py:274 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/3688e92e35ff0936. Report an issue: GitHub.