{"record":{"id":"10415b9f8689f8c9","repo":"keras-team/keras","slug":"invalid-value-for-attribute-constraint-expected","errorCode":null,"errorMessage":"Invalid value for attribute `constraint`. Expected a callable (such as a `keras.constraints.Constraint` instance) or `None`. Received: constraint={value}","messagePattern":"Invalid value for attribute `constraint`\\. Expected a callable \\(such as a `keras\\.constraints\\.Constraint` instance\\) or `None`\\. Received: constraint=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/common/variables.py","lineNumber":392,"sourceCode":"\n    @regularizer.setter\n    def regularizer(self, value):\n        if value is not None and not callable(value):\n            raise ValueError(\n                \"Invalid value for attribute `regularizer`. Expected a \"\n                \"callable (such as a `keras.regularizers.Regularizer` \"\n                f\"instance) or `None`. Received: regularizer={value}\"\n            )\n        self._regularizer = value\n\n    @property\n    def constraint(self):\n        return self._constraint\n\n    @constraint.setter\n    def constraint(self, value):\n        if value is not None and not callable(value):\n            raise ValueError(\n                \"Invalid value for attribute `constraint`. Expected a \"\n                \"callable (such as a `keras.constraints.Constraint` instance) \"\n                f\"or `None`. Received: constraint={value}\"\n            )\n        self._constraint = value\n\n    def __repr__(self):\n        value = None\n        if hasattr(self, \"_value\") and self._value is not None:\n            try:\n                value = backend.core.convert_to_numpy(self._value)\n            except:\n                # In some cases the conversion to numpy can fail.\n                pass\n        value_str = f\", value={value}\" if value is not None else \"\"\n        return (\n            f\"<Variable path={self.path}, shape={self.shape}, \"\n            f\"dtype={self.dtype}{value_str}>\"","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/common/variables.py#L374-L410","documentation":"Raised by the constraint property setter when the assigned value is neither None nor callable. Keras expects a keras.constraints.Constraint instance (callable) or None; raw strings or config dicts are not accepted by this guard.","triggerScenarios":"Thrown at keras/src/backend/common/variables.py:392 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a Constraint instance such as variable.constraint = keras.constraints.MaxNorm(3), or None to disable.","Resolve identifiers first: keras.constraints.get('max_norm') before assignment."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}