{"record":{"id":"2669deb4afbe2521","repo":"huggingface/transformers","slug":"invalid-padding-strategy-padding-side","errorCode":null,"errorMessage":"Invalid padding strategy:{padding_side}","messagePattern":"Invalid padding strategy:(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/feature_extraction_sequence_utils.py","lineNumber":292,"sourceCode":"                if return_attention_mask:\n                    processed_features[\"attention_mask\"] = np.pad(\n                        processed_features[\"attention_mask\"], (0, difference)\n                    )\n                padding_shape = ((0, difference), (0, 0)) if self.feature_size > 1 else (0, difference)\n                processed_features[self.model_input_names[0]] = np.pad(\n                    required_input, padding_shape, \"constant\", constant_values=self.padding_value\n                )\n            elif self.padding_side == \"left\":\n                if return_attention_mask:\n                    processed_features[\"attention_mask\"] = np.pad(\n                        processed_features[\"attention_mask\"], (difference, 0)\n                    )\n                padding_shape = ((difference, 0), (0, 0)) if self.feature_size > 1 else (difference, 0)\n                processed_features[self.model_input_names[0]] = np.pad(\n                    required_input, padding_shape, \"constant\", constant_values=self.padding_value\n                )\n            else:\n                raise ValueError(\"Invalid padding strategy:\" + str(self.padding_side))\n\n        return processed_features\n\n    def _truncate(\n        self,\n        processed_features: dict[str, np.ndarray] | BatchFeature,\n        max_length: int | None = None,\n        pad_to_multiple_of: int | None = None,\n        truncation: bool | None = None,\n    ):\n        \"\"\"\n        Truncate inputs to predefined length or max length in the batch\n\n        Args:\n            processed_features(`Union[dict[str, np.ndarray], BatchFeature]`):\n                Dictionary of input values (`np.ndarray[float]`) / input vectors (`list[np.ndarray[float]]`) or batch\n                of inputs values (`list[np.ndarray[int]]`) / input vectors (`list[np.ndarray[int]]`)\n            max_length (`int`, *optional*):","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/feature_extraction_sequence_utils.py#L274-L310","documentation":"The padder supports only padding_side 'right' and 'left'. If the feature extractor's padding_side attribute is anything else (typo like 'both', 'center', an empty string, or a mis-set value on a custom extractor), the else branch raises this ValueError.","triggerScenarios":"Setting feature_extractor.padding_side to an unsupported value in __init__ kwargs or after construction, then calling with padding enabled; subclassing a sequence feature extractor and forgetting to override padding handling for a custom side.","commonSituations":"Copy-pasting config from processors that use different side names; loading a saved extractor JSON whose padding_side was hand-edited; assuming symmetric/center padding exists because some preprocessing libs offer it.","solutions":["Set feature_extractor.padding_side = 'right' (or 'left') — the only supported values","If you loaded a config file, fix the padding_side entry in the preprocessor_config.json","For center/symmetric padding, pad manually with np.pad before calling the extractor"],"exampleFix":"# before\nfe.padding_side = \"both\"\nfe.pad(batch, padding=True)\n\n# after\nfe.padding_side = \"left\"\nfe.pad(batch, padding=True)","handlingStrategy":"validation","validationCode":"if fe.padding_side not in (\"right\", \"left\"):\n    fe.padding_side = \"right\"","typeGuard":"def is_valid_padding_side(side) -> bool:\n    return side in (\"right\", \"left\")","tryCatchPattern":"try:\n    fe.pad(batch, padding=True)\nexcept ValueError as e:\n    if \"Invalid padding strategy\" in str(e):\n        fe.padding_side = \"right\"\n        fe.pad(batch, padding=True)\n    else:\n        raise","preventionTips":["Only use 'left' or 'right' for padding_side","Validate loaded preprocessor configs before use","Pad manually with np.pad for any non-standard scheme"],"tags":["feature-extractor","padding","config","transformers"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}