keras-team/keras · error · ValueError
The input ' ' is not optional, but None was passed. Please…
Error message
The input '{input_tensor.name}' is not optional, but None was passed. Please provide a valid tensor. What it means
Compatibility guard in Functional._assert_input_compatibility: None was passed for an input tensor whose corresponding InputLayer is not marked optional (optional=True). Optional inputs are the only ones allowed to receive None at call time; required inputs receiving None would silently corrupt the forward pass, so the call is rejected.
Solutions
- Provide a real tensor for every required (non-optional) input
- Create the input with keras.Input(..., optional=True) if the model should accept None for that input
Defensive patterns
Strategy: validation
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.
Appendix: 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)