keras-team/keras · error · ValueError
The input '{input_tensor.name}' is not optional, but None wa
Error message
The input '{input_tensor.name}' is not optional, but None was passed. Please provide a valid tensor. What it means
Error "The input '{input_tensor.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:221
return input_shapes
@property
def output_shape(self):
output_shapes = tree.map_structure(lambda x: x.shape, self.outputs)
if isinstance(output_shapes, list) and len(output_shapes) == 1:
return output_shapes[0]
return output_shapes
def _assert_input_compatibility(self, *args):
flat_inputs = tree.flatten(args[0])
for x, input_tensor in zip(flat_inputs, self._inputs):
if x is None:
input_layer = input_tensor._keras_history.operation
if (
isinstance(input_layer, InputLayer)
and not input_layer.optional
):
raise ValueError(
(
f"The input '{input_tensor.name}' is not optional, "
"but None was passed. "
"Please provide a valid tensor."
)
)
return super(Model, self)._assert_input_compatibility(*args)
def _maybe_warn_inputs_struct_mismatch(self, inputs, raise_exception=False):
try:
# We first normalize to tuples before performing the check to
# suppress warnings when encountering mismatched tuples and lists.
tree.assert_same_structure(
tree.lists_to_tuples(inputs),
tree.lists_to_tuples(self._inputs_struct),
)
except:
model_inputs_struct = tree.map_structure(View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/models/functional.py:221 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/5c740b11582bd225.
Report an issue: GitHub.