{"record":{"id":"718c5dedce1ece43","repo":"keras-team/keras","slug":"expected-padding-to-be-a-tuple-of-2-integers-re","errorCode":null,"errorMessage":"Expected `padding` to be a tuple of 2 integers. Received: padding={padding}","messagePattern":"Expected `padding` to be a tuple of 2 integers\\. Received: padding=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/legacy/backend.py","lineNumber":2181,"sourceCode":"            tile_shape = tf.where(\n                shape_diff > 0, expr_shape, tf.ones_like(expr_shape)\n            )\n            condition = tf.tile(condition, tile_shape)\n        x = tf.where(condition, then_expression, else_expression)\n    return x\n\n\n@keras_export(\"keras._legacy.backend.tanh\")\ndef tanh(x):\n    \"\"\"DEPRECATED.\"\"\"\n    return tf.tanh(x)\n\n\n@keras_export(\"keras._legacy.backend.temporal_padding\")\ndef temporal_padding(x, padding=(1, 1)):\n    \"\"\"DEPRECATED.\"\"\"\n    if len(padding) != 2:\n        raise ValueError(\n            \"Expected `padding` to be a tuple of 2 integers. \"\n            f\"Received: padding={padding}\"\n        )\n    pattern = [[0, 0], [padding[0], padding[1]], [0, 0]]\n    return tf.compat.v1.pad(x, pattern)\n\n\n@keras_export(\"keras._legacy.backend.tile\")\ndef tile(x, n):\n    \"\"\"DEPRECATED.\"\"\"\n    if isinstance(n, int):\n        n = [n]\n    return tf.tile(x, n)\n\n\n@keras_export(\"keras._legacy.backend.to_dense\")\ndef to_dense(tensor):\n    \"\"\"DEPRECATED.\"\"\"","sourceCodeStart":2163,"sourceCodeEnd":2199,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/legacy/backend.py#L2163-L2199","documentation":"The deprecated temporal_padding helper pads only the time axis (axis 1) of a 3D (batch, timesteps, features) tensor and requires `padding` to be exactly two integers: (left_pad, right_pad). Passing a nested tuple, a single int, a 3+-element tuple, or None raises this ValueError immediately.","triggerScenarios":"Calling keras._legacy.backend.temporal_padding(x, padding=1), padding=((1,1),(1,1)), padding=(1,1,1), or any non-length-2 argument.","commonSituations":"Migrating old Keras 1/2 code where padding semantics differed; copy-pasting a spatial padding argument into a temporal call; loading a saved config where the padding tuple was serialized differently.","solutions":["Pass exactly two ints, e.g. temporal_padding(x, padding=(2, 2)) — the default (1,1) is often fine","For a single int k, expand it to (k, k)","Prefer the modern keras.layers.ZeroPadding1D(padding=k), which accepts an int or a pair"],"exampleFix":"# before\ntemporal_padding(x, padding=2)\n# after\ntemporal_padding(x, padding=(2, 2))  # or: keras.layers.ZeroPadding1D(2)(x)","handlingStrategy":"validation","validationCode":"if isinstance(padding, int):\n    padding = (padding, padding)\nassert isinstance(padding, (tuple, list)) and len(padding) == 2, f'bad padding: {padding}'","typeGuard":"def is_temporal_padding(p) -> bool:\n    return isinstance(p, (tuple, list)) and len(p) == 2 and all(isinstance(v, int) for v in p)","tryCatchPattern":null,"preventionTips":["Prefer keras.layers.ZeroPadding1D in new code; it accepts int or pair","Normalize single-int padding to (k, k) at the config layer"],"tags":["keras","padding","legacy","argument-validation","time-series"],"backgroundTag":"invalid-argument-shape","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}