{"record":{"id":"24543a274dbdf3b1","repo":"keras-team/keras","slug":"a-merge-layer-should-be-called-on-a-list-of-at-lea","errorCode":null,"errorMessage":"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}","messagePattern":"A merge layer should be called on a list of at least 1 input\\. Received (.+?) inputs\\. Full input_shape received: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/merging/base_merge.py","lineNumber":108,"sourceCode":"                output_shape.append(i)\n            else:\n                if i != j:\n                    raise ValueError(\n                        \"Inputs have incompatible shapes. \"\n                        f\"Received shapes {shape1} and {shape2}\"\n                    )\n                output_shape.append(i)\n        return tuple(output_shape)\n\n    def build(self, input_shape):\n        # Used purely for shape validation.\n        if not isinstance(input_shape[0], (tuple, list)):\n            raise ValueError(\n                \"A merge layer should be called on a list of inputs. \"\n                f\"Received: input_shape={input_shape} (not a list of shapes)\"\n            )\n        if len(input_shape) < 1:\n            raise ValueError(\n                \"A merge layer should be called \"\n                \"on a list of at least 1 input. \"\n                f\"Received {len(input_shape)} inputs. \"\n                f\"Full input_shape received: {input_shape}\"\n            )\n\n        batch_sizes = {s[0] for s in input_shape if s} - {None}\n        if len(batch_sizes) > 1:\n            raise ValueError(\n                \"Cannot merge tensors with different batch sizes. \"\n                f\"Received tensors with shapes {input_shape}\"\n            )\n\n        if input_shape[0] is None:\n            output_shape = None\n        else:\n            output_shape = input_shape[0][1:]\n","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/merging/base_merge.py#L90-L126","documentation":"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.","triggerScenarios":"Calling a merge layer with an empty list: Add()([]); programmatically building a model whose input list is empty due to filtering bugs.","commonSituations":"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.","solutions":["Ensure at least one (usually two or more) tensors are passed to the merge layer","Guard dynamic pipelines: if not tensors: skip or raise your own descriptive error","Check upstream filtering/conditionals that assemble the input list"],"exampleFix":"# before\nout = merge_layer([])\n\n# after\nout = merge_layer(tensors)  # tensors has >= 1 element","handlingStrategy":"validation","validationCode":"assert isinstance(inputs, (list, tuple)) and len(inputs) >= 1, 'merge needs at least one input'","typeGuard":"def has_merge_inputs(inputs) -> bool:\n    return isinstance(inputs, (list, tuple)) and len(inputs) >= 1","tryCatchPattern":null,"preventionTips":["Guard dynamic input collection against empty lists","Log input list length before merge layers in pipelines"],"tags":["keras","merge","empty-input"],"backgroundTag":"empty-input-list","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}