keras-team/keras · error · ValueError
`inputs` should be a list. Received: inputs={inputs}
Error message
`inputs` should be a list. Received: inputs={inputs} What it means
compute_mask() of merge layers validates that inputs is a list or tuple. If a single tensor (or other non-sequence) is passed alongside a mask, this error is raised before mask combination logic runs.
Source
Thrown at keras/src/layers/merging/base_merge.py:261
output_shape = (list(batch_sizes)[0],) + output_shape
else:
output_shape = (None,) + output_shape
return output_shape
def compute_output_spec(self, inputs):
output_shape = self.compute_output_shape([x.shape for x in inputs])
output_sparse = all(x.sparse for x in inputs)
return KerasTensor(
output_shape, dtype=self.compute_dtype, sparse=output_sparse
)
def compute_mask(self, inputs, mask=None):
if mask is None:
return None
if not isinstance(mask, (tuple, list)):
raise ValueError(f"`mask` should be a list. Received: mask={mask}")
if not isinstance(inputs, (tuple, list)):
raise ValueError(
f"`inputs` should be a list. Received: inputs={inputs}"
)
if len(mask) != len(inputs):
raise ValueError(
"The lists `inputs` and `mask` should have the same length. "
f"Received: inputs={inputs} of length {len(inputs)}, and "
f"mask={mask} of length {len(mask)}"
)
# Default implementation does an OR between the masks, which works
# for `Add`, `Subtract`, `Average`, `Maximum`, `Minimum`, `Multiply`.
if any(m is None for m in mask):
return None
output_mask = mask[0]
for m in mask[1:]:
output_mask = ops.logical_or(output_mask, m)
return output_mask
def get_config(self):View on GitHub (pinned to 7a34a03db6)
Solutions
- Pass inputs as a list matching the layer's input structure
- Keep compute_mask call sites consistent with how __call__/build see inputs
- Add input-structure assertions in custom merge subclasses
Example fix
# before mask_out = merge_layer.compute_mask(x, mask=[m1, m2]) # after mask_out = merge_layer.compute_mask([x1, x2], mask=[m1, m2])
Defensive patterns
Strategy: validation
Validate before calling
assert isinstance(inputs, (list, tuple)), 'inputs must be a list when a mask is provided'
Type guard
def is_input_list(x) -> bool:
return isinstance(x, (list, tuple)) Prevention
- Mirror __call__ input structure when calling compute_mask directly
- Wrap inputs in lists in custom subclasses
When it happens
Trigger: Calling compute_mask(x, mask=[m1, m2]) with a bare tensor x; custom subclasses invoking super().compute_mask with unwrapped inputs.
Common situations: Custom merge subclasses that forward masks; test code calling compute_mask directly; model surgery that changes input arity.
Related errors
- A merge layer should be called on a list of inputs. Received
- A merge layer should be called on a list of inputs. Received
- `mask` should be a list. Received: mask={mask}
- The lists `inputs` and `mask` should have the same length. R
- `inputs` should be a list. Received: inputs={inputs}
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/0843c7790366509a.
Report an issue: GitHub.