keras-team/keras · error · ValueError

A merge layer should be called on a list of inputs. Received

Error message

A merge layer should be called on a list of inputs. Received: input_shape={input_shape} (not a list of shapes)

What it means

Merge layers expect build(input_shape) to receive a list of shapes, one per input tensor. This check fails when input_shape[0] is not itself a tuple/list — i.e. the layer was effectively called with a single tensor (or something that is not a nest of shapes), so Keras cannot treat the call as a multi-input merge.

Source

Thrown at keras/src/layers/merging/base_merge.py:103

            if i is None or j is None:
                output_shape.append(None)
            elif i == 1:
                output_shape.append(j)
            elif j == 1:
                output_shape.append(i)
            else:
                if i != j:
                    raise ValueError(
                        "Inputs have incompatible shapes. "
                        f"Received shapes {shape1} and {shape2}"
                    )
                output_shape.append(i)
        return tuple(output_shape)

    def build(self, input_shape):
        # Used purely for shape validation.
        if not isinstance(input_shape[0], (tuple, list)):
            raise ValueError(
                "A merge layer should be called on a list of inputs. "
                f"Received: input_shape={input_shape} (not a list of shapes)"
            )
        if len(input_shape) < 1:
            raise ValueError(
                "A merge layer should be called "
                "on a list of at least 1 input. "
                f"Received {len(input_shape)} inputs. "
                f"Full input_shape received: {input_shape}"
            )

        batch_sizes = {s[0] for s in input_shape if s} - {None}
        if len(batch_sizes) > 1:
            raise ValueError(
                "Cannot merge tensors with different batch sizes. "
                f"Received tensors with shapes {input_shape}"
            )

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Pass a list of at least two tensors: Add()([x, y])
  2. In Functional models, ensure the merge layer receives a list input: layers.Add()([branch_a, branch_b])
  3. Wrap a lone tensor in a list only if you truly mean single-input merge behavior

Example fix

# before
out = layers.Add()(x)

# after
out = layers.Add()([x, y])
Defensive patterns

Strategy: type-guard

Validate before calling

assert isinstance(inputs, (list, tuple)) and len(inputs) >= 2 and all(hasattr(t, 'shape') for t in inputs)

Type guard

def is_merge_input_list(inputs) -> bool:
    return isinstance(inputs, (list, tuple)) and len(inputs) >= 2

Prevention

When it happens

Trigger: Calling Add()(x) with a single tensor instead of a list; passing a dict or scalar where a list of shapes is expected; a custom layer delegating to a merge layer with the wrong input structure.

Common situations: Forgetting brackets: Add()(x) instead of Add()([x, y]); a Functional model where a single previous tensor node feeds the merge layer; wrapping merge layers in custom code.

Related errors


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/91fc800a99ea94f9. Report an issue: GitHub.