keras-team/keras · error · ValueError

The provided configuration is not a valid Keras…

Error message

The provided configuration is not a valid Keras configuration. Expected a dictionary containing a 'config' key. Received: config={config}

What it means

Raised when deserializing a model from a config dict that lacks the nested 'config' key expected by the Keras serialization format (which uses {'class_name': ..., 'config': {...}}). The function tries to read config['config'] to reconstruct the model, so a malformed or foreign dictionary aborts with this guard before the lookup fails obscurely.

Solutions

  1. Use the full serialized form {'class_name': ..., 'config': model.get_config()} as produced by keras.models.model_to_json or serialize_keras_object
  2. If you only have get_config() output, pass it via the appropriate from_config classmethod instead of this function
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/legacy/saving/saving_utils.py:58 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/57b8fb1f85a7a67f. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/legacy/saving/saving_utils.py:58

            "`model_from_config` expects a dictionary, not a list. "
            f"Received: config={config}. Did you meant to use "
            "`Sequential.from_config(config)`?"
        )

    global MODULE_OBJECTS

    if not hasattr(MODULE_OBJECTS, "ALL_OBJECTS"):
        from keras.src import layers
        from keras.src import models

        MODULE_OBJECTS.ALL_OBJECTS = layers.__dict__
        MODULE_OBJECTS.ALL_OBJECTS["InputLayer"] = layers.InputLayer
        MODULE_OBJECTS.ALL_OBJECTS["Functional"] = models.Functional
        MODULE_OBJECTS.ALL_OBJECTS["Model"] = models.Model
        MODULE_OBJECTS.ALL_OBJECTS["Sequential"] = models.Sequential

    if not isinstance(config, dict) or "config" not in config:
        raise ValueError(
            "The provided configuration is not a valid Keras configuration. "
            "Expected a dictionary containing a 'config' key. "
            f"Received: config={config}"
        )
    batch_input_shape = config["config"].pop("batch_input_shape", None)
    if batch_input_shape is not None:
        if config["class_name"] == "InputLayer":
            config["config"]["batch_shape"] = batch_input_shape
        else:
            config["config"]["input_shape"] = batch_input_shape

    axis = config["config"].pop("axis", None)
    if axis is not None:
        if isinstance(axis, list) and len(axis) == 1:
            config["config"]["axis"] = int(axis[0])
        elif isinstance(axis, (int, float)):
            config["config"]["axis"] = int(axis)

View on GitHub (pinned to 7a34a03db6)