{"record":{"id":"6dd6310d8fb4ee78","repo":"keras-team/keras","slug":"error-preamble-for-layer-class-name-receive","errorCode":null,"errorMessage":"{error_preamble} For layer '{class_name}', Received `{method_name}()` argument `{name}`, which does not end in `_shape`.","messagePattern":"(.+?) For layer '(.+?)', Received `(.+?)\\(\\)` argument `(.+?)`, which does not end in `_shape`\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/layer.py","lineNumber":2056,"sourceCode":"        key = expected_names[0]\n        values = tuple(shapes_dict.values())\n        if values:\n            input_shape = values[0]\n        else:\n            input_shape = None\n        return {key: input_shape}\n\n    # Multiple args: check that all names line up.\n    kwargs = {}\n    for name in expected_names:\n        method_name = target_fn.__name__\n        error_preamble = (\n            f\"For a `{method_name}()` method with more than one argument, all \"\n            \"arguments should have a `_shape` suffix and match an argument \"\n            f\"from `call()`. E.g. `{method_name}(self, foo_shape, bar_shape)` \"\n        )\n        if not name.endswith(\"_shape\"):\n            raise ValueError(\n                f\"{error_preamble} For layer '{class_name}', \"\n                f\"Received `{method_name}()` argument \"\n                f\"`{name}`, which does not end in `_shape`.\"\n            )\n        expected_call_arg = utils.removesuffix(name, \"_shape\")\n        if expected_call_arg not in call_spec.arguments_dict:\n            raise ValueError(\n                f\"{error_preamble} For layer '{class_name}', \"\n                f\"received `{method_name}()` argument \"\n                f\"`{name}`, but `call()` does not have argument \"\n                f\"`{expected_call_arg}`.\"\n            )\n        if name in shapes_dict:\n            kwargs[name] = shapes_dict[name]\n\n    return kwargs\n\n","sourceCodeStart":2038,"sourceCodeEnd":2074,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/layer.py#L2038-L2074","documentation":"For shape-computing methods with multiple arguments (compute_output_shape, build), Keras requires every parameter name to end in _shape and correspond to a call() argument. This error fires when a method like compute_output_shape(self, foo, bar_shape) declares a parameter without the _shape suffix, so Keras cannot map it back to a call() argument.","triggerScenarios":"Defining compute_output_shape(self, input_shape, training) or build(self, input_shape, mask) where the extra parameter lacks the _shape suffix on a layer with multiple such arguments.","commonSituations":"Porting old Keras 2 layers whose compute_output_shape took arbitrary parameter names; adding a mask or training parameter to compute_output_shape; subclassing layers that override build/compute_output_shape with positional names.","solutions":["Rename the parameter to <arg>_shape, e.g. compute_output_shape(self, input_shape, mask_shape)","Ensure the stripped name (mask) matches an actual argument of call()","If the extra parameter is a flag (like training), remove it from compute_output_shape — training is not a shape argument"],"exampleFix":"# before\nclass MyLayer(keras.layers.Layer):\n    def compute_output_shape(self, input_shape, training):\n        ...\n\n# after\nclass MyLayer(keras.layers.Layer):\n    def compute_output_shape(self, input_shape):\n        ...","handlingStrategy":"validation","validationCode":"import inspect\nparams = [n for n in inspect.signature(MyLayer.compute_output_shape).parameters if n != 'self']\nassert len(params) <= 1 or all(p.endswith('_shape') for p in params), params","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Name every multi-arg build/compute_output_shape parameter <arg>_shape","Keep parameter names mirrored with call() arguments","Run model.build() early in tests to catch signature errors"],"tags":["keras","shape-inference","api-contract","naming-convention"],"backgroundTag":"shape-inference-contract","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}