keras-team/keras · error · TypeError
output must be a tuple when multiple outputs are expected…
Error message
output must be a tuple when multiple outputs are expected, got: {out} What it means
Guard in the wrapped function of ops.vectorize: the gufunc signature declares multiple outputs, so the wrapped pyfunc must return a tuple so each element's core dimensions can be validated; it returned a single (non-tuple) object such as a list or bare tensor.
Solutions
- Return a tuple from the wrapped function, e.g. return (a, b) instead of [a, b] or a.
- If only one output is produced, change the signature to declare a single output group.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/backend/common/backend_utils.py:557 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/409f9359a6386867.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/backend/common/backend_utils.py:557
func,
dim_sizes,
expected_output_core_dims,
):
from keras.src import ops
def wrapped(*args):
out = func(*args)
if isinstance(out, (list, tuple)):
out_shapes = [ops.shape(x) for x in out]
else:
out_shapes = [out.shape]
if expected_output_core_dims is None:
output_core_dims = [()] * len(out_shapes)
else:
output_core_dims = expected_output_core_dims
if len(output_core_dims) > 1 and not isinstance(out, tuple):
raise TypeError(
"output must be a tuple when multiple outputs "
f"are expected, got: {out}"
)
if len(out_shapes) != len(output_core_dims):
raise TypeError(
"wrong number of output arguments: "
f"expected {len(output_core_dims)}, got {len(out_shapes)}"
)
sizes = dict(dim_sizes)
for shape, core_dims in zip(out_shapes, output_core_dims):
_vectorize_update_dim_sizes(sizes, shape, core_dims, is_input=False)
return out
return wrapped
View on GitHub (pinned to 7a34a03db6)