keras-team/keras · error · ValueError

Layer "{layer_name}" expects {len(input_spec)} input(s), but

Error message

Layer "{layer_name}" expects {len(input_spec)} input(s), but it received {len(inputs)} input tensors. Inputs received: {inputs}

What it means

Error "Layer "{layer_name}" expects {len(input_spec)} input(s), but it received {len(inputs)} input tensors. Inputs received: {inputs}" thrown in keras-team/keras.

Source

Thrown at keras/src/layers/input_spec.py:172

                        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

        # Having a shape/dtype is the only commonality of the various
        # tensor-like objects that may be passed. The most common kind of
        # invalid type we are guarding for is a Layer instance (Functional API),
        # which does not have a `shape` attribute.
        if not hasattr(x, "shape"):
            raise ValueError(
                f"Inputs to a layer should be tensors. Got '{x}' "
                f"(of type {type(x)}) as input for layer '{layer_name}'."

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/layers/input_spec.py:172 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/2afe93207acf183c. Report an issue: GitHub.