{"record":{"id":"df35295753669b84","repo":"hankcs/HanLP","slug":"invalid-encoding-encoding-passed-to-to-bioul","errorCode":null,"errorMessage":"Invalid encoding {encoding} passed to 'to_bioul'.","messagePattern":"Invalid encoding (.+?) passed to 'to_bioul'\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"hanlp/utils/span_util.py","lineNumber":591,"sourceCode":"    span of the same type.\n\n    In the BIO scheme, I is a token inside a span, O is a token outside\n    a span and B is the beginning of a span.\n\n    # Parameters\n\n    tag_sequence : `List[str]`, required.\n        The tag sequence encoded in IOB1, e.g. [\"I-PER\", \"I-PER\", \"O\"].\n    encoding : `str`, optional, (default = `\"IOB1\"`).\n        The encoding type to convert from. Must be either \"IOB1\" or \"BIO\".\n\n    # Returns\n\n    bioul_sequence : `List[str]`\n        The tag sequence encoded in IOB1, e.g. [\"B-PER\", \"L-PER\", \"O\"].\n    \"\"\"\n    if encoding not in {\"IOB1\", \"BIO\"}:\n        raise ValueError(f\"Invalid encoding {encoding} passed to 'to_bioul'.\")\n\n    def replace_label(full_label, new_label):\n        # example: full_label = 'I-PER', new_label = 'U', returns 'U-PER'\n        parts = list(full_label.partition(\"-\"))\n        parts[0] = new_label\n        return \"\".join(parts)\n\n    def pop_replace_append(in_stack, out_stack, new_label):\n        # pop the last element from in_stack, replace the label, append\n        # to out_stack\n        tag = in_stack.pop()\n        new_tag = replace_label(tag, new_label)\n        out_stack.append(new_tag)\n\n    def process_stack(stack, out_stack):\n        # process a stack of labels, add them to out_stack\n        if len(stack) == 1:\n            # just a U token","sourceCodeStart":573,"sourceCodeEnd":609,"githubUrl":"https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/span_util.py#L573-L609","documentation":"ValueError from to_bioul, a scheme converter that only understands source encodings 'IOB1' and 'BIO'. Passing any other string (e.g. 'IOB2', 'BIOUL', 'iob1' lowercase, or a typo) is rejected.","triggerScenarios":"Calling to_bioul(tag_sequence, encoding=...) with encoding not in {'IOB1','BIO'} — commonly via iob1_to_bioul wrappers or direct calls with 'IOB2' (which is the same as BIO but spelled differently) or lowercase 'iob1'.","commonSituations":"Copy-pasted scheme names from other libraries (IOB2, BIOES, IOBES); case-sensitive string mismatch; assuming any standard scheme name is accepted.","solutions":["Pass exactly 'IOB1' or 'BIO' (uppercase)","If your scheme is IOB2/BIO2, use encoding='BIO'","If your source is IOBES/BIOUL, you don't need this converter — decode with iobes_tags_to_spans/bioul_tags_to_spans directly"],"exampleFix":"# before\nbioul = to_bioul(tags, encoding='IOB2')  # ValueError\n# after\nbioul = to_bioul(tags, encoding='BIO')","handlingStrategy":"validation","validationCode":"assert encoding in {'IOB1', 'BIO'}, f\"encoding must be IOB1 or BIO, got {encoding}\"","typeGuard":"def is_supported_encoding(enc: str) -> bool:\n    return enc in ('IOB1', 'BIO')","tryCatchPattern":"try:\n    to_bioul(tags, encoding=enc)\nexcept ValueError:\n    to_bioul(tags, encoding='BIO')  # IOB2 == BIO","preventionTips":["Use exact uppercase literals 'IOB1'/'BIO'","Remember IOB2 must be passed as 'BIO'"],"tags":["ner","tagging-scheme","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"ddb1299bddff079e447af52ec12549c50636bfa8","analyzedAt":"2026-08-27T03:36:54.287Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}