{"record":{"id":"6b9fd8bfdb9f2f3f","repo":"keras-team/keras","slug":"the-lists-inputs-and-mask-should-have-the-same","errorCode":null,"errorMessage":"The lists `inputs` and `mask` should have the same length. Received: inputs={inputs} of length {len(inputs)}, and mask={mask} of length {len(mask)}","messagePattern":"The lists `inputs` and `mask` should have the same length\\. Received: inputs=(.+?) of length (.+?), and mask=(.+?) of length (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/merging/base_merge.py","lineNumber":265,"sourceCode":"\n    def compute_output_spec(self, inputs):\n        output_shape = self.compute_output_shape([x.shape for x in inputs])\n        output_sparse = all(x.sparse for x in inputs)\n        return KerasTensor(\n            output_shape, dtype=self.compute_dtype, sparse=output_sparse\n        )\n\n    def compute_mask(self, inputs, mask=None):\n        if mask is None:\n            return None\n        if not isinstance(mask, (tuple, list)):\n            raise ValueError(f\"`mask` should be a list. Received: mask={mask}\")\n        if not isinstance(inputs, (tuple, list)):\n            raise ValueError(\n                f\"`inputs` should be a list. Received: inputs={inputs}\"\n            )\n        if len(mask) != len(inputs):\n            raise ValueError(\n                \"The lists `inputs` and `mask` should have the same length. \"\n                f\"Received: inputs={inputs} of length {len(inputs)}, and \"\n                f\"mask={mask} of length {len(mask)}\"\n            )\n        # Default implementation does an OR between the masks, which works\n        # for `Add`, `Subtract`, `Average`, `Maximum`, `Minimum`, `Multiply`.\n        if any(m is None for m in mask):\n            return None\n        output_mask = mask[0]\n        for m in mask[1:]:\n            output_mask = ops.logical_or(output_mask, m)\n        return output_mask\n\n    def get_config(self):\n        return super().get_config()\n","sourceCodeStart":247,"sourceCodeEnd":281,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/merging/base_merge.py#L247-L281","documentation":"Merge layers combine masks element-wise, so compute_mask requires len(mask) == len(inputs). This error fires when the number of masks does not match the number of input tensors.","triggerScenarios":"Calling compute_mask([x1, x2], mask=[m1]) or __call__ paths where one input's mask is missing from the list (you must pass None placeholders).","commonSituations":"Mixing masked and unmasked inputs (forgetting a None entry); changing the number of inputs without updating the mask list.","solutions":["Supply exactly one mask entry per input, using None for unmasked inputs: mask=[m1, None]","Recompute mask lists whenever input arity changes","In Functional models, rely on automatic mask propagation instead of hand-built mask lists"],"exampleFix":"# before\nout = merge([x1, x2], mask=[m1])\n\n# after\nout = merge([x1, x2], mask=[m1, None])","handlingStrategy":"validation","validationCode":"assert isinstance(mask, (list, tuple)) and len(mask) == len(inputs), 'one mask per input (use None)'","typeGuard":"def masks_match_inputs(mask, inputs) -> bool:\n    return mask is None or (isinstance(mask, (list, tuple)) and len(mask) == len(inputs))","tryCatchPattern":null,"preventionTips":["Always emit one mask entry per input, None for unmasked","Recompute mask lists when input arity changes"],"tags":["keras","merge","masking","length-mismatch"],"backgroundTag":"mask-length-mismatch","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}