keras-team/keras · error · ValueError
Output with path ` ` is not connected to `inputs
Error message
Output with path `{path}` is not connected to `inputs` What it means
When evaluating a Function graph, every declared output must be reachable by traversing from the declared inputs. An output that came from different tensors (constants, another graph) fails this reachability check.
Solutions
- Compute the output from the input tensors via ops/layers
- Add the missing source tensor to inputs
- Remove the stray output from the outputs structure
Example fix
# before y = some_other_input + 1 fn = keras.ops.Function([x], y) # after y = x + 1 fn = keras.ops.Function([x], y)
Defensive patterns
Strategy: validation
Validate before calling
out_flat = tree.flatten(outputs)
in_ids = {id(t) for t in tree.flatten(inputs)}
assert out_flat, 'outputs empty' Prevention
- Compute outputs from the inputs, not from captured constants
- Trace the op graph with keras.ops.Function to verify connectivity before saving
When it happens
Trigger: keras.ops.Function([x], [y]) where y was created independently of x (e.g. y = other_tensor + 1)
Common situations: Functional model construction where a return value comes from a layer applied outside the input graph, or accidental tensor reuse across models
Related errors
- Function was called with an invalid input structure…
- `inputs` argument cannot be empty. Received: 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/6a2733247d031f13.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/ops/function.py:221
# Use call_fn if provided (e.g., for symbolic execution)
op = operation_fn(node.operation)
outputs = call_fn(op, *args, **kwargs)
else:
# Use NNX operation mapping
operation = self._get_operation_for_node(node)
op = operation_fn(operation)
outputs = op(*args, **kwargs)
# Update tensor_dict.
for x, y in zip(node.outputs, tree.flatten(outputs)):
tensor_dict[id(x)] = y
output_tensors = []
for i, x in enumerate(self.outputs):
if id(x) not in tensor_dict:
path = tree.flatten_with_path(self._outputs_struct)[i][0]
path = ".".join(str(p) for p in path)
raise ValueError(
f"Output with path `{path}` is not connected to `inputs`"
)
output_tensors.append(tensor_dict[id(x)])
return tree.pack_sequence_as(self._outputs_struct, output_tensors)
def _assert_input_compatibility(self, inputs):
try:
tree.assert_same_structure(inputs, self._inputs_struct)
except ValueError:
raise ValueError(
"Function was called with an invalid input structure. "
f"Expected input structure: {self._inputs_struct}\n"
f"Received input structure: {inputs}"
)
for x, x_ref in zip(tree.flatten(inputs), self._inputs):
if len(x.shape) != len(x_ref.shape):
raise ValueError(View on GitHub (pinned to 7a34a03db6)