{"record":{"id":"068cccc06ef92eb8","repo":"keras-team/keras","slug":"axis-is-greater-than-the-maximum-allowed-value","errorCode":null,"errorMessage":"Axis {} is greater than the maximum allowed value: {}","messagePattern":"Axis (.+?) is greater than the maximum allowed value: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/input_spec.py","lineNumber":90,"sourceCode":"        self.max_ndim = max_ndim\n        self.min_ndim = min_ndim\n        self.name = name\n        self.optional = optional\n        self.allow_last_axis_squeeze = allow_last_axis_squeeze\n        try:\n            axes = axes or {}\n            self.axes = {int(k): axes[k] for k in axes}\n        except (ValueError, TypeError):\n            raise TypeError(\n                \"Argument `axes` must be a dict with integer keys. \"\n                f\"Received: axes={axes}\"\n            )\n\n        if self.axes and (self.ndim is not None or self.max_ndim is not None):\n            max_dim = (self.ndim if self.ndim else self.max_ndim) - 1\n            max_axis = max(self.axes)\n            if max_axis > max_dim:\n                raise ValueError(\n                    \"Axis {} is greater than the maximum \"\n                    \"allowed value: {}\".format(max_axis, max_dim)\n                )\n\n    def __repr__(self):\n        spec = [\n            (f\"dtype={str(self.dtype)}\") if self.dtype else \"\",\n            (f\"shape={str(self.shape)}\") if self.shape else \"\",\n            (f\"ndim={str(self.ndim)}\") if self.ndim else \"\",\n            (f\"max_ndim={str(self.max_ndim)}\") if self.max_ndim else \"\",\n            (f\"min_ndim={str(self.min_ndim)}\") if self.min_ndim else \"\",\n            (f\"axes={str(self.axes)}\") if self.axes else \"\",\n        ]\n        return f\"InputSpec({', '.join(x for x in spec if x)})\"\n\n    def get_config(self):\n        return {\n            \"dtype\": self.dtype,","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/input_spec.py#L72-L108","documentation":"Consistency check in InputSpec.__init__ after the axes dict is parsed: with axes defined and ndim or max_ndim also given, every axis key must fit within the allowed rank; a key exceeding the computed max_dim indexes a dimension the input cannot have, so the spec is rejected.","triggerScenarios":"Thrown at keras/src/layers/input_spec.py:90 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use negative indexing (e.g. -1 for the last axis) instead of a large positive index","Raise ndim/max_ndim to accommodate the axis, or drop the axis entry from `axes`"],"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"}