keras-team/keras · error · ValueError
`inputs` argument cannot be empty. Received: inputs={inputs}
Error message
`inputs` argument cannot be empty. Received:
inputs={inputs}
outputs={outputs} What it means
A Keras ops Function must be constructed from at least one input KerasTensor; an empty flattened input structure (empty list/tuple) cannot define a callable graph and is rejected.
Source
Thrown at keras/src/ops/function.py:63
def __init__(self, inputs, outputs, name=None):
super().__init__(name=name)
if backend() == "tensorflow":
# Temporary work around for
# https://github.com/keras-team/keras/issues/931
# This stop tensorflow from wrapping tf.function output in a
# _DictWrapper object.
_self_setattr_tracking = getattr(
self, "_self_setattr_tracking", True
)
self._self_setattr_tracking = False
self._inputs_struct = tree.map_structure(lambda x: x, inputs)
self._outputs_struct = tree.map_structure(lambda x: x, outputs)
self._inputs = tree.flatten(inputs)
self._outputs = tree.flatten(outputs)
if not self._inputs:
raise ValueError(
"`inputs` argument cannot be empty. Received:\n"
f"inputs={inputs}\n"
f"outputs={outputs}"
)
if not self._outputs:
raise ValueError(
"`outputs` argument cannot be empty. Received:\n"
f"inputs={inputs}\n"
f"outputs={outputs}"
)
if backend() == "tensorflow":
self._self_setattr_tracking = _self_setattr_tracking
(nodes, nodes_by_depth, operations, operations_by_depth) = map_graph(
self._inputs, self._outputs
)
self._nodes = nodesView on GitHub (pinned to 7a34a03db6)
Solutions
- Pass at least one real KerasTensor as inputs
- Check that tree.flatten(inputs) is non-empty before constructing
Example fix
# before fn = keras.ops.Function([], out) # after fn = keras.ops.Function([x], out)
Defensive patterns
Strategy: validation
Validate before calling
assert tree.flatten(inputs), 'inputs must be non-empty'
Prevention
- Pass at least one KerasTensor as inputs when constructing a keras.ops.Function
When it happens
Trigger: keras.ops.Function(inputs=[], outputs=t) or inputs=()
Common situations: Building keras.ops.Function programmatically where the input list ends up empty (e.g. a disconnected trace)
Related errors
- `outputs` argument cannot be empty. Received: inputs={inputs
- Output with path `{path}` is not connected to `inputs`
- Function was called with an invalid input structure. Expecte
- Sequential model '{self.name}' has no defined inputs yet.
- Array inputs to associative_scan must have the same first di
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/652b1a1cbad0ac93.
Report an issue: GitHub.