keras-team/keras · error · ValueError
A Sequential model configuration must be a dictionary…
Error message
A Sequential model configuration must be a dictionary containing the 'name' and 'layers' keys. Received: config={config} What it means
Raised when from_config() receives a configuration object that is not a dict containing the required 'name' and 'layers' keys. This usually happens when passing a malformed dict, a JSON string instead of a parsed dict, or a config produced by a different class to Sequential.from_config().
Solutions
- Use the dict from model.get_config() unmodified
- Add the missing 'name' (and keep 'layers') keys before calling from_config
- For bare layer lists, pass the list form that from_config also accepts
Example fix
# before
model = keras.Sequential.from_config({'layers': [...]})
# after
cfg = {'name': 'sequential_1', 'layers': [...]}
model = keras.Sequential.from_config(cfg) Defensive patterns
Strategy: validation
Validate before calling
def is_sequential_config(cfg):
return (isinstance(cfg, dict) and 'name' in cfg
and isinstance(cfg.get('layers'), list)) Try / catch
try:
model = keras.Sequential.from_config(cfg)
except ValueError:
if 'name' not in cfg or 'layers' not in cfg:
raise
cfg.setdefault('name', 'sequential')
model = keras.Sequential.from_config(cfg) Prevention
- Load round-trip artifacts produced by the same to_json/get_config API
- Validate the config dict before calling from_config
When it happens
Trigger: keras.Sequential.from_config({'layers': [...]}) or from_config with an unexpected structure
Common situations: Loading hand-edited JSON, YAML-derived dicts, or configs from a different serialization format or Keras version
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Argument `input_tensors` must contain a single tensor.
- `call_function` argument is not supported with Sequential…
- Data not JSON Serializable
- Expected `model` argument to be a `Sequential` model…
- Layer ' ' was never built and thus it doesn't have any…
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/3cb47082d7d1bbbe.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/models/sequential.py:369
for layer in super().layers:
# `super().layers` include the InputLayer if available (it is
# filtered out of `self.layers`).
layer_configs.append(serialize_fn(layer))
config = Model.get_config(self)
config["name"] = self.name
config["layers"] = copy.deepcopy(layer_configs)
if self._functional is not None:
config["build_input_shape"] = self._layers[0].batch_shape
return config
@classmethod
def from_config(cls, config, custom_objects=None):
if "name" in config:
name = config["name"]
build_input_shape = config.get("build_input_shape")
layer_configs = config["layers"]
else:
raise ValueError(
"A Sequential model configuration must be "
"a dictionary containing the 'name' and "
f"'layers' keys. Received: config={config}"
)
model = cls(name=name)
for layer_config in layer_configs:
if "module" not in layer_config:
# Legacy format deserialization (no "module" key)
# used for H5 and SavedModel formats
layer = saving_utils.model_from_config(
layer_config,
custom_objects=custom_objects,
)
else:
layer = serialization_lib.deserialize_keras_object(
layer_config,
custom_objects=custom_objects,
)View on GitHub (pinned to 7a34a03db6)