{"record":{"id":"409f9359a6386867","repo":"keras-team/keras","slug":"output-must-be-a-tuple-when-multiple-outputs-are-e","errorCode":null,"errorMessage":"output must be a tuple when multiple outputs are expected, got: {out}","messagePattern":"output must be a tuple when multiple outputs are expected, got: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/common/backend_utils.py","lineNumber":557,"sourceCode":"    func,\n    dim_sizes,\n    expected_output_core_dims,\n):\n    from keras.src import ops\n\n    def wrapped(*args):\n        out = func(*args)\n        if isinstance(out, (list, tuple)):\n            out_shapes = [ops.shape(x) for x in out]\n        else:\n            out_shapes = [out.shape]\n\n        if expected_output_core_dims is None:\n            output_core_dims = [()] * len(out_shapes)\n        else:\n            output_core_dims = expected_output_core_dims\n            if len(output_core_dims) > 1 and not isinstance(out, tuple):\n                raise TypeError(\n                    \"output must be a tuple when multiple outputs \"\n                    f\"are expected, got: {out}\"\n                )\n            if len(out_shapes) != len(output_core_dims):\n                raise TypeError(\n                    \"wrong number of output arguments: \"\n                    f\"expected {len(output_core_dims)}, got {len(out_shapes)}\"\n                )\n\n        sizes = dict(dim_sizes)\n        for shape, core_dims in zip(out_shapes, output_core_dims):\n            _vectorize_update_dim_sizes(sizes, shape, core_dims, is_input=False)\n\n        return out\n\n    return wrapped\n\n","sourceCodeStart":539,"sourceCodeEnd":575,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/common/backend_utils.py#L539-L575","documentation":"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.","triggerScenarios":"Thrown at keras/src/backend/common/backend_utils.py:557 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}