keras-team/keras · error · ValueError
`outputs` argument cannot be empty. Received: inputs={inputs
Error message
`outputs` argument cannot be empty. Received:
inputs={inputs}
outputs={outputs} What it means
Symmetric to the inputs check, outputs must flatten to a non-empty structure; a Function with no outputs is meaningless and rejected at construction.
Source
Thrown at keras/src/ops/function.py:69
# 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 = nodes
self._nodes_by_depth = nodes_by_depth
self._operations = operations
self._operations_by_depth = operations_by_depth
# Run through graph to check all outputs are connected to the inputs.
def empty_op_outputs(op, *args, **kwargs):View on GitHub (pinned to 7a34a03db6)
Solutions
- Ensure the op graph produces at least one output tensor
- Pass a concrete output tensor instead of an empty container
Example fix
# before fn = keras.ops.Function([x], []) # after fn = keras.ops.Function([x], y)
Defensive patterns
Strategy: validation
Validate before calling
assert tree.flatten(outputs), 'outputs must be non-empty'
Prevention
- Make sure the op graph actually consumes the input tensors
- Return at least one tensor derived from inputs
When it happens
Trigger: keras.ops.Function(inputs=[x], outputs=[]) or outputs=()
Common situations: Programmatic graph construction with bugs that drop the computed tensors
Related errors
- `inputs` 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 outputs 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/6d356c75a29f61fd.
Report an issue: GitHub.