{"record":{"id":"32036690996bbaf8","repo":"keras-team/keras","slug":"invalid-value-for-argument-output-mode-expected-320366","errorCode":null,"errorMessage":"Invalid value for argument `output_mode`. Expected one of {accepted_output_modes}. Received: output_mode={output_mode}","messagePattern":"Invalid value for argument `output_mode`\\. Expected one of (.+?)\\. Received: output_mode=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/hashing.py","lineNumber":177,"sourceCode":"\n        if num_bins is None or num_bins <= 0:\n            raise ValueError(\n                \"The `num_bins` for `Hashing` cannot be `None` or \"\n                f\"non-positive values. Received: num_bins={num_bins}.\"\n            )\n\n        if output_mode == \"int\" and (\n            self.dtype_policy.name not in (\"int32\", \"int64\")\n        ):\n            raise ValueError(\n                'When `output_mode=\"int\"`, `dtype` should be an integer '\n                f\"type, 'int32' or 'in64'. Received: dtype={kwargs['dtype']}\"\n            )\n\n        # 'output_mode' must be one of (INT, ONE_HOT, MULTI_HOT, COUNT)\n        accepted_output_modes = (\"int\", \"one_hot\", \"multi_hot\", \"count\")\n        if output_mode not in accepted_output_modes:\n            raise ValueError(\n                \"Invalid value for argument `output_mode`. \"\n                f\"Expected one of {accepted_output_modes}. \"\n                f\"Received: output_mode={output_mode}\"\n            )\n\n        if sparse and output_mode == \"int\":\n            raise ValueError(\n                \"`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","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/hashing.py#L159-L195","documentation":"The Hashing preprocessing layer only supports four output modes: 'int', 'one_hot', 'multi_hot', and 'count'. The layer validates output_mode in __init__ and raises this ValueError when any other string (or a typo) is passed. Internally the mode decides how the hashed bucket index is converted into an output tensor.","triggerScenarios":"Calling keras.layers.Hashing(output_mode=...) with a misspelled or unsupported value, e.g. 'onehot', 'multi-hot', 'INT', 'freq', 'binary', or passing None.","commonSituations":"Porting code from tf.keras StringLookup/IntegerLookup (which accept 'tf_idf' and other modes) to the standalone Hashing layer; typos from camelCase vs snake_case mode names.","solutions":["Set output_mode to one of exactly 'int', 'one_hot', 'multi_hot', or 'count'.","Note that 'tf_idf' is not supported by Hashing; use TextVectorization if you need tf-idf output.","Check for leading/trailing whitespace or wrong case in the string you pass programmatically."],"exampleFix":"# before\nlayer = keras.layers.Hashing(num_bins=100, output_mode=\"onehot\")\n# after\nlayer = keras.layers.Hashing(num_bins=100, output_mode=\"one_hot\")","handlingStrategy":"validation","validationCode":"ALLOWED = {\"int\", \"one_hot\", \"multi_hot\", \"count\"}\nif output_mode not in ALLOWED:\n    raise ValueError(f\"unsupported output_mode {output_mode!r}\")","typeGuard":"def is_valid_output_mode(m):\n    return isinstance(m, str) and m in {\"int\", \"one_hot\", \"multi_hot\", \"count\"}\n","tryCatchPattern":null,"preventionTips":["Keep output mode names in a module-level constant set and reuse it at every call site.","Add a unit test that constructs the layer with each supported mode."],"tags":["keras","preprocessing","hashing","invalid-argument"],"backgroundTag":"invalid-enum-argument","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}