{"record":{"id":"2304e340714e6801","repo":"PaddlePaddle/PaddleOCR","slug":"value-is-not-a-valid-cls-name-please-sele","errorCode":null,"errorMessage":"{value} is not a valid {cls.__name__}, please select one of {list(cls._value2member_map_.keys())}","messagePattern":"(.+?) is not a valid (.+?), please select one of (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ppocr/data/imaug/label_ops.py","lineNumber":1898,"sourceCode":"            for idx, seq in enumerate(process_seq):\n                l = len(seq)\n                labels[idx][:l] = seq\n            topk[k] = labels\n        return (\n            np.array(topk[\"input_ids\"]).astype(np.int64),\n            np.array(topk[\"attention_mask\"]).astype(np.int64),\n            max_length,\n        )\n\n\nclass ExplicitEnum(str, Enum):\n    \"\"\"\n    Enum with more explicit error message for missing values.\n    \"\"\"\n\n    @classmethod\n    def _missing_(cls, value):\n        raise ValueError(\n            f\"{value} is not a valid {cls.__name__}, please select one of {list(cls._value2member_map_.keys())}\"\n        )\n\n\nclass TruncationStrategy(ExplicitEnum):\n    \"\"\"\n    Possible values for the `truncation` argument in [`PreTrainedTokenizerBase.__call__`]. Useful for tab-completion in\n    an IDE.\n    \"\"\"\n\n    ONLY_FIRST = \"only_first\"\n    ONLY_SECOND = \"only_second\"\n    LONGEST_FIRST = \"longest_first\"\n    DO_NOT_TRUNCATE = \"do_not_truncate\"\n\n\nclass PaddingStrategy(ExplicitEnum):\n    \"\"\"","sourceCodeStart":1880,"sourceCodeEnd":1916,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/data/imaug/label_ops.py#L1880-L1916","documentation":"ExplicitEnum is the base class (copied from HuggingFace transformers) for tokenizer strategy enums such as TruncationStrategy. Python calls _missing_ when a value cannot be matched to a member; this override replaces the default cryptic message with an explicit list of valid values.","triggerScenarios":"Passing a 'truncation' (or padding) argument to the tokenizer used by the recognition label pipeline whose value is not one of the enum members, e.g. truncation='True' (string), truncation='both', or a boolean True.","commonSituations":"Reading truncation/padding settings from a yml config where YAML renders booleans as strings; passing Python True instead of 'longest'/'only_first'; version drift between transformers and the vendored tokenizer code in label_ops.py.","solutions":["Read the valid values from the error message itself and use one of them exactly, e.g. truncation: only_first or longest_only equivalent ('longest' for padding)","If the setting comes from YAML, quote the string and avoid boolean keywords: truncation: 'only_first', not truncation: yes","Check for boolean leakage: use str(value).lower() comparisons or normalize config values before passing them to the tokenizer","Align the transformers version with the one PaddleOCR pins if you also import HF tokenizers"],"exampleFix":"# before\ntokenizer(text, truncation='True')\n# after\nfrom ppocr.data.imaug.label_ops import TruncationStrategy\ntokenizer(text, truncation=TruncationStrategy.ONLY_FIRST)","handlingStrategy":"validation","validationCode":"from ppocr.data.imaug.label_ops import TruncationStrategy\nif isinstance(truncation, str):\n    if truncation not in TruncationStrategy._value2member_map_:\n        raise SystemExit(f'truncation must be one of {list(TruncationStrategy._value2member_map_)}')\n    truncation = TruncationStrategy(truncation)","typeGuard":"def is_valid_truncation(v) -> bool:\n    from ppocr.data.imaug.label_ops import TruncationStrategy\n    return v is None or v in TruncationStrategy._value2member_map_ or isinstance(v, TruncationStrategy)","tryCatchPattern":"try:\n    tokenizer(texts, truncation=truncation)\nexcept ValueError as e:\n    if 'is not a valid' in str(e):\n        # fall back to a safe default instead of crashing the loader\n        tokenizer(texts, truncation='only_first')\n    else:\n        raise","preventionTips":["Normalize config strings: reject YAML booleans for enum-typed settings","Pass enum members (TruncationStrategy.ONLY_FIRST) instead of raw strings from code","Centralize tokenizer kwarg construction so validation happens in one place"],"tags":["tokenizer","enum","config","nlp"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}