{"record":{"id":"5ee17ccbb347d15c","repo":"keras-team/keras","slug":"the-salt-argument-for-hashing-can-only-be-a-tu","errorCode":null,"errorMessage":"The `salt` argument for `Hashing` can only be a tuple of size 2 integers, or a single integer. Received: salt={salt}.","messagePattern":"The `salt` argument for `Hashing` can only be a tuple of size 2 integers, or a single integer\\. Received: salt=(.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/hashing.py","lineNumber":203,"sourceCode":"                \"`sparse` may only be true if `output_mode` is \"\n                '`\"one_hot\"`, `\"multi_hot\"`, or `\"count\"`. '\n                f\"Received: sparse={sparse} and \"\n                f\"output_mode={output_mode}\"\n            )\n\n        self.num_bins = num_bins\n        self.mask_value = mask_value\n        self.strong_hash = True if salt is not None else False\n        self.output_mode = output_mode\n        self.sparse = sparse\n        self.salt = None\n        if salt is not None:\n            if isinstance(salt, (tuple, list)) and len(salt) == 2:\n                self.salt = list(salt)\n            elif isinstance(salt, int):\n                self.salt = [salt, salt]\n            else:\n                raise ValueError(\n                    \"The `salt` argument for `Hashing` can only be a tuple of \"\n                    \"size 2 integers, or a single integer. \"\n                    f\"Received: salt={salt}.\"\n                )\n        self._convert_input_args = False\n        self._allow_non_tensor_positional_args = True\n        self.supports_jit = False\n\n    def compute_output_shape(self, input_shape):\n        if self.output_mode == \"int\":\n            return tuple(input_shape)\n        # `one_hot`, `multi_hot` and `count` encode the last (sample) axis\n        # into a `num_bins`-sized axis.\n        if len(input_shape) == 0:\n            return (self.num_bins,)\n        return tuple(input_shape[:-1]) + (self.num_bins,)\n\n    def call(self, inputs):","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/hashing.py#L185-L221","documentation":"The salt parameter of the Hashing layer seeds the hash function so results are stable across runs. It accepts either a single integer (used for both parts of the SipHash salt) or a tuple/list of exactly two integers. Anything else - strings, floats, wrong-length lists - raises this ValueError in __init__.","triggerScenarios":"Passing salt=\"foo\", salt=0.5, salt=(1,2,3), or salt=[1.0, 2.0] to keras.layers.Hashing().","commonSituations":"Copying a salt value from another library (e.g. a string seed from TensorFlow hashing or a random seed float); assuming salt works like the seed argument of initializers.","solutions":["Pass a single int, e.g. salt=1337, which becomes [1337, 1337].","Or pass a tuple/list of exactly two ints, e.g. salt=(1337, 7331).","If you need a string-derived salt, convert it to an int first (e.g. an integer hash of the string)."],"exampleFix":"# before\nlayer = keras.layers.Hashing(num_bins=64, salt=\"my_seed\")\n# after\nlayer = keras.layers.Hashing(num_bins=64, salt=1337)","handlingStrategy":"type-guard","validationCode":"assert salt is None or isinstance(salt, int) or (isinstance(salt, (tuple, list)) and len(salt) == 2 and all(isinstance(s, int) for s in salt)), f\"bad salt: {salt!r}\"","typeGuard":"def is_valid_salt(s):\n    return s is None or isinstance(s, int) or (isinstance(s, (tuple, list)) and len(s) == 2 and all(isinstance(x, int) for x in s))\n","tryCatchPattern":null,"preventionTips":["Derive salts from ints (e.g. fixed seeds), never strings.","Document the [int, int] internal representation when storing configs."],"tags":["keras","preprocessing","hashing","salt","invalid-argument"],"backgroundTag":"invalid-argument-type","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}