keras-team/keras · error · ValueError
Expected `trainable` to be a boolean. Received: trainable=
Error message
Expected `trainable` to be a boolean. Received: trainable={trainable} (of type {type(trainable)}) What it means
Guard in Layer.__init__ that requires the `trainable` constructor argument to be a strict Python bool; passing truthy values like 0/1, numpy bools, strings, or None triggers it because isinstance(trainable, bool) fails.
Solutions
- Pass an actual boolean: trainable=True or trainable=False
- Convert non-bool values before construction, e.g. trainable=bool(value) or trainable=bool(int_flag)
- Fix any config/hyperparameter pipeline that serializes trainable as 0/1 or a string and coerce it back to bool
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at keras/src/layers/layer.py:308 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/5795aada4c89c134.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/layer.py:308
"first layer in the model instead.",
stacklevel=2,
)
self._input_shape_arg = input_shape_arg
if kwargs:
raise ValueError(
"Unrecognized keyword arguments "
f"passed to {self.__class__.__name__}: {kwargs}"
)
self._path = None # Will be determined in `build_wrapper`
self.built = False
self.autocast = autocast
self._input_spec = None
self._called = False
self.supports_jit = True
if not isinstance(trainable, bool):
raise ValueError(
"Expected `trainable` to be a boolean. "
f"Received: trainable={trainable} (of type "
f"{type(trainable)})"
)
self._trainable = trainable
self._losses = []
self._loss_ids = set()
self._losses_override = []
self._call_signature = inspect.signature(self.call)
self.call_signature_parameters = [
p.name for p in self._call_signature.parameters.values()
]
self._call_has_training_arg = (
"training" in self.call_signature_parameters
)
self._call_has_mask_arg = "mask" in self.call_signature_parameters
View on GitHub (pinned to 7a34a03db6)