keras-team/keras · error · ValueError
`inputs` argument cannot be empty. Received: inputs=
Error message
`inputs` argument cannot be empty. Received:
inputs={inputs}
outputs={outputs} What it means
Raised by Functional.__init__ (keras.ops.function) when the `inputs` argument is empty/None while creating a Function via keras.ops.Function(inputs, outputs). Both inputs and outputs must be non-empty tensor structures.
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
- Function was called with an invalid input structure…
- Output with path ` ` is not connected to `inputs
- `outputs` argument cannot be empty. Received: inputs=
- Array inputs to associative_scan must have the same first…
- Cannot infer argument `num` from shape
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/652b1a1cbad0ac93.
Report an issue: GitHub.
Appendix: 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)