keras-team/keras · error · ValueError

`salt` can only be used when `oov_method='farmhash'`. Receiv

Error message

`salt` can only be used when `oov_method='farmhash'`. Received: oov_method={oov_method}

What it means

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.

Source

Thrown at keras/src/layers/preprocessing/index_lookup.py:162

        if num_oov_indices < 0:
            raise ValueError(
                "`num_oov_indices` must be greater than or equal to 0. "
                f"Received: num_oov_indices={num_oov_indices}"
            )

        argument_validation.validate_string_arg(
            oov_method,
            allowable_strings=("floormod", "farmhash"),
            caller_name=self.__class__.__name__,
            arg_name="oov_method",
        )

        if salt is not None:
            if (
                tf.as_dtype(vocabulary_dtype).is_integer
                and oov_method != "farmhash"
            ):
                raise ValueError(
                    "`salt` can only be used when `oov_method='farmhash'`. "
                    f"Received: oov_method={oov_method}"
                )
            if isinstance(salt, (tuple, list)) and len(salt) == 2:
                salt = list(salt)
            elif isinstance(salt, int):
                salt = [salt, salt]
            else:
                raise ValueError(
                    "The `salt` argument for `IndexLookup` can only be a tuple "
                    "of 2 integers, or a single integer. "
                    f"Received: salt={salt}."
                )

        # Support deprecated names for output_modes.
        if output_mode == "binary":
            output_mode = "multi_hot"
        if output_mode == "tf-idf":

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Set `oov_method='farmhash'` when using salt.
  2. Or drop the `salt` argument entirely.
  3. Or switch to a string vocabulary, where salt does not apply.

Example fix

# before
layer = IndexLookup(vocabulary_dtype='int64', salt=42)

# after
layer = IndexLookup(vocabulary_dtype='int64', salt=42, oov_method='farmhash')
Defensive patterns

Strategy: validation

Validate before calling

if salt is not None and oov_method != 'farmhash':
    raise ValueError('salt requires oov_method=farmhash')
layer = IndexLookup(vocabulary_dtype='int64', salt=salt, oov_method=oov_method)

Type guard

def salt_is_valid(salt) -> bool:
    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))

Try / catch

try:
    layer = IndexLookup(salt=salt, oov_method=om)
except ValueError:
    layer = IndexLookup(salt=None, oov_method=om)

Prevention

When it happens

Trigger: `IndexLookup(vocabulary_dtype='int64', salt=42)` while leaving `oov_method` at a non-farmhash value, or changing `oov_method` later without removing `salt`.

Common situations: Porting hashing configurations between layers or enabling salt for deterministic integer hashing, then switching the OOV method.

Related errors


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/6e28ba51197596fc. Report an issue: GitHub.