keras-team/keras · error · ValueError
Layer "{layer_name}" expects {len(input_spec)} named input(s
Error message
Layer "{layer_name}" expects {len(input_spec)} named input(s) with keys {spec_names}, but it received {len(inputs)} input tensors. Pass inputs as a dict, e.g. `layer({'{n}': ...})`. What it means
Error "Layer "{layer_name}" expects {len(input_spec)} named input(s) with keys {spec_names}, but it received {len(inputs)} input tensors. Pass inputs as a dict, e.g. `layer({'{n}': ...})`." thrown in keras-team/keras.
Source
Thrown at keras/src/layers/input_spec.py:164
if all(names):
list_inputs = []
for name in names:
if name not in inputs:
raise ValueError(
f'Missing data for input "{name}". '
"You passed a data dictionary with keys "
f"{list(inputs.keys())}. "
f"Expected the following keys: {names}"
)
list_inputs.append(inputs[name])
inputs = list_inputs
inputs = tree.flatten(inputs)
if len(inputs) != len(input_spec):
# Provide appropriate error message for dict inputs.
spec_names = [spec.name for spec in input_spec if spec is not None]
if len(spec_names) == len(input_spec) and all(spec_names):
raise ValueError(
f'Layer "{layer_name}" expects {len(input_spec)} named '
f"input(s) with keys {spec_names}, but it received "
f"{len(inputs)} input tensors. Pass inputs as a dict, e.g. "
"`layer({"
+ ", ".join(f"'{n}': ..." for n in spec_names)
+ "})`."
)
raise ValueError(
f'Layer "{layer_name}" expects {len(input_spec)} input(s),'
f" but it received {len(inputs)} input tensors. "
f"Inputs received: {inputs}"
)
for input_index, (x, spec) in enumerate(zip(inputs, input_spec)):
if spec is None:
continue
if x is None and spec.optional:
continue
View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/layers/input_spec.py:164 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/824bfd18890a0366.
Report an issue: GitHub.