{"record":{"id":"6e28ba51197596fc","repo":"keras-team/keras","slug":"salt-can-only-be-used-when-oov-method-farmhash","errorCode":null,"errorMessage":"`salt` can only be used when `oov_method='farmhash'`. Received: oov_method={oov_method}","messagePattern":"`salt` can only be used when `oov_method='farmhash'`\\. Received: oov_method=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/index_lookup.py","lineNumber":162,"sourceCode":"        if num_oov_indices < 0:\n            raise ValueError(\n                \"`num_oov_indices` must be greater than or equal to 0. \"\n                f\"Received: num_oov_indices={num_oov_indices}\"\n            )\n\n        argument_validation.validate_string_arg(\n            oov_method,\n            allowable_strings=(\"floormod\", \"farmhash\"),\n            caller_name=self.__class__.__name__,\n            arg_name=\"oov_method\",\n        )\n\n        if salt is not None:\n            if (\n                tf.as_dtype(vocabulary_dtype).is_integer\n                and oov_method != \"farmhash\"\n            ):\n                raise ValueError(\n                    \"`salt` can only be used when `oov_method='farmhash'`. \"\n                    f\"Received: oov_method={oov_method}\"\n                )\n            if isinstance(salt, (tuple, list)) and len(salt) == 2:\n                salt = list(salt)\n            elif isinstance(salt, int):\n                salt = [salt, salt]\n            else:\n                raise ValueError(\n                    \"The `salt` argument for `IndexLookup` can only be a tuple \"\n                    \"of 2 integers, or a single integer. \"\n                    f\"Received: salt={salt}.\"\n                )\n\n        # Support deprecated names for output_modes.\n        if output_mode == \"binary\":\n            output_mode = \"multi_hot\"\n        if output_mode == \"tf-idf\":","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/index_lookup.py#L144-L180","documentation":"When IndexLookup hashes integer inputs it can apply a `salt` to perturb the FarmHash output, making hashes reproducible. Salt is only meaningful with `oov_method='farmhash'` and an integer vocabulary dtype, so the constructor rejects the combination otherwise.","triggerScenarios":"`IndexLookup(vocabulary_dtype='int64', salt=42)` while leaving `oov_method` at a non-farmhash value, or changing `oov_method` later without removing `salt`.","commonSituations":"Porting hashing configurations between layers or enabling salt for deterministic integer hashing, then switching the OOV method.","solutions":["Set `oov_method='farmhash'` when using salt.","Or drop the `salt` argument entirely.","Or switch to a string vocabulary, where salt does not apply."],"exampleFix":"# before\nlayer = IndexLookup(vocabulary_dtype='int64', salt=42)\n\n# after\nlayer = IndexLookup(vocabulary_dtype='int64', salt=42, oov_method='farmhash')","handlingStrategy":"validation","validationCode":"if salt is not None and oov_method != 'farmhash':\n    raise ValueError('salt requires oov_method=farmhash')\nlayer = IndexLookup(vocabulary_dtype='int64', salt=salt, oov_method=oov_method)","typeGuard":"def salt_is_valid(salt) -> bool:\n    return salt is None or (isinstance(salt, int) and not isinstance(salt, bool)) or (isinstance(salt, (tuple, list)) and len(salt) == 2 and all(isinstance(x, int) for x in salt))","tryCatchPattern":"try:\n    layer = IndexLookup(salt=salt, oov_method=om)\nexcept ValueError:\n    layer = IndexLookup(salt=None, oov_method=om)","preventionTips":["Treat salt and oov_method as one coupled setting in config validation.","Salt only affects integer-input hashing; string vocabularies never need it."],"tags":["keras","preprocessing","index-lookup","hashing","argument-validation"],"backgroundTag":"constructor-argument-validation","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}