{"record":{"id":"59b87ea87de2c6ed","repo":"keras-team/keras","slug":"feature-name-has-output-mode-one-hot-thus","errorCode":null,"errorMessage":"Feature '{name}' has `output_mode='one_hot'`. Thus its preprocessor should return an integer dtype. Instead it returns a {dtype} dtype.","messagePattern":"Feature '(.+?)' has `output_mode='one_hot'`\\. Thus its preprocessor should return an integer dtype\\. Instead it returns a (.+?) dtype\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/feature_space.py","lineNumber":685,"sourceCode":"        ] + [\n            self.crosses_by_name[name] for name in self._crossed_features_names\n        ]\n\n        for name, feature, spec in zip(all_names, all_features, all_specs):\n            if tree.is_nested(feature):\n                dtype = tree.flatten(feature)[0].dtype\n            else:\n                dtype = feature.dtype\n            dtype = backend.standardize_dtype(dtype)\n\n            if spec.output_mode == \"one_hot\":\n                preprocessor = self.preprocessors.get(\n                    name\n                ) or self.crossers.get(name)\n\n                cardinality = None\n                if not dtype.startswith(\"int\"):\n                    raise ValueError(\n                        f\"Feature '{name}' has `output_mode='one_hot'`. \"\n                        \"Thus its preprocessor should return an integer dtype. \"\n                        f\"Instead it returns a {dtype} dtype.\"\n                    )\n\n                if isinstance(\n                    preprocessor, (layers.IntegerLookup, layers.StringLookup)\n                ):\n                    cardinality = preprocessor.vocabulary_size()\n                elif isinstance(preprocessor, layers.CategoryEncoding):\n                    cardinality = preprocessor.num_tokens\n                elif isinstance(preprocessor, layers.Discretization):\n                    cardinality = preprocessor.num_bins\n                elif isinstance(\n                    preprocessor, (layers.HashedCrossing, layers.Hashing)\n                ):\n                    cardinality = preprocessor.num_bins\n                else:","sourceCodeStart":667,"sourceCodeEnd":703,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/feature_space.py#L667-L703","documentation":"When FeatureSpace is configured to produce one-hot output for a feature (output_mode='one_hot'), the feature's preprocessor must emit integer indices that can be binarized. The code checks the dtype flowing out of the preprocessor and rejects non-integer output such as float32 or string.","triggerScenarios":"A feature whose preprocessor returns floats (e.g. normalization) combined with FeatureSpace output_mode='one_hot'; a crossing outputting floats while crossing_output_mode='one_hot'.","commonSituations":"A custom feature spec or crossing returns floats; mixing output_mode='one_hot' with a preprocessor that has not been set to integer output; misconfigured crossing_output_mode on FeatureSpace.","solutions":["Make the feature's preprocessor return integer indices (e.g. use integer_hashed, string_hashed, or a lookup layer with output_mode='int')","If the feature must stay continuous, do not one-hot encode it — use output_mode='float' for that feature or keep it out of one_hot mode","For crossing features in one_hot mode, set crossing_output_mode='one_hot' or 'int' with an appropriate hasher"],"exampleFix":"// before\nfs = FeatureSpace(..., output_mode=\"one_hot\")\n# feature 'x' preprocessor returns float\n// after\nfs = FeatureSpace(\n    features={\"x\": FeatureSpace.integer_hashed(max_tokens=32)},\n    output_mode=\"one_hot\",\n)","handlingStrategy":"validation","validationCode":"out = fs.preprocessors[name](sample_batch)\nassert str(out.dtype).startswith(\"int\"), f\"{name} yields {out.dtype}\"","typeGuard":"def is_int_preprocessor(p):\n    d = getattr(p, \"dtype\", None)\n    return d is not None and str(d).startswith(\"int\")","tryCatchPattern":"catch ValueError from fs.get_encoded_features() and inspect the offending feature's preprocessor output dtype via fs.preprocessors[name] before correcting the feature spec","preventionTips":["Check that the preprocessor assigned to a feature returns integer output before setting output_mode='one_hot'","Keep FeatureSpace feature specs consistent with the desired output_mode"],"tags":["keras","feature-space","one-hot","dtype"],"backgroundTag":"dtype-mismatch","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}