keras-team/keras · error · ValueError

A merge layer should be called on a list of at least 1 input

Error message

A merge layer should be called on a list of at least 1 input. Received {len(input_shape)} inputs. Full input_shape received: {input_shape}

What it means

Merge layers validate that build() received at least one input shape. This error is raised when the input_shape list is empty (len < 1), meaning the layer was called with an empty list of inputs and there is nothing to merge.

Source

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

                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}"
            )

        if input_shape[0] is None:
            output_shape = None
        else:
            output_shape = input_shape[0][1:]

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Ensure at least one (usually two or more) tensors are passed to the merge layer
  2. Guard dynamic pipelines: if not tensors: skip or raise your own descriptive error
  3. Check upstream filtering/conditionals that assemble the input list

Example fix

# before
out = merge_layer([])

# after
out = merge_layer(tensors)  # tensors has >= 1 element
Defensive patterns

Strategy: validation

Validate before calling

assert isinstance(inputs, (list, tuple)) and len(inputs) >= 1, 'merge needs at least one input'

Type guard

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

Prevention

When it happens

Trigger: Calling a merge layer with an empty list: Add()([]); programmatically building a model whose input list is empty due to filtering bugs.

Common situations: Dynamic input collection code that can produce an empty list (e.g. filtering layers that match nothing); model surgery scripts that rebuild merge nodes with no inputs.

Related errors


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