{"record":{"id":"5a4fcca0b3d0f11d","repo":"hankcs/HanLP","slug":"unknown-constraint-type-constraint-type","errorCode":null,"errorMessage":"Unknown constraint type: {constraint_type}","messagePattern":"Unknown constraint type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"hanlp/utils/span_util.py","lineNumber":244,"sourceCode":"    elif constraint_type == \"BMES\":\n        if from_tag == \"START\":\n            return to_tag in (\"B\", \"S\")\n        if to_tag == \"END\":\n            return from_tag in (\"E\", \"S\")\n        return any(\n            [\n                # Can only transition to B or S from E or S.\n                to_tag in (\"B\", \"S\") and from_tag in (\"E\", \"S\"),\n                # Can only transition to M-x from B-x, where\n                # x is the same tag.\n                to_tag == \"M\" and from_tag in (\"B\", \"M\") and from_entity == to_entity,\n                # Can only transition to E-x from B-x or M-x, where\n                # x is the same tag.\n                to_tag == \"E\" and from_tag in (\"B\", \"M\") and from_entity == to_entity,\n            ]\n        )\n    else:\n        raise ValueError(f\"Unknown constraint type: {constraint_type}\")\n\n\nTypedSpan = Tuple[int, Tuple[int, int]]\nTypedStringSpan = Tuple[str, Tuple[int, int]]\n\n\nclass InvalidTagSequence(Exception):\n    def __init__(self, tag_sequence=None):\n        super().__init__()\n        self.tag_sequence = tag_sequence\n\n    def __str__(self):\n        return \" \".join(self.tag_sequence)\n\n\nT = str\n\n","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/span_util.py#L226-L262","documentation":"allowed_transitions/is_transition_allowed builds legal tag-transition tables for BMES or BIO constraint types. Any constraint_type string other than those two branches falls through to ValueError('Unknown constraint type: ...').","triggerScenarios":"Calling allowed_transitions('BIOUL', ...) or with a typo/case mismatch ('bio', 'IOB') — the function accepts only the exact strings handled by its if/elif chain (BMES and BIO).","commonSituations":"Porting AllenNLP code that uses 'BIOUL'; assuming IOB/IOB2 names work; passing config values through without normalizing case.","solutions":["Use exactly 'BMES' or 'BIO' as constraint_type (uppercase, as implemented).","Convert BIOUL/IOB2 tag sets to one of the supported schemes before requesting transitions.","Check for case: lowercase 'bio' will not match."],"exampleFix":"# before\ntransitions = allowed_transitions('BIOUL', labels)\n# after\ntransitions = allowed_transitions('BMES', labels)","handlingStrategy":"validation","validationCode":"assert constraint_type in ('BMES', 'BIO'), f'unsupported constraint_type: {constraint_type}'","typeGuard":"def valid_constraint(t):\n    return t in ('BMES', 'BIO')","tryCatchPattern":null,"preventionTips":["Define constraint types as module constants.","Reject unknown config values early with a clear message."],"tags":["nlp","span","config","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"ddb1299bddff079e447af52ec12549c50636bfa8","analyzedAt":"2026-08-27T03:36:54.287Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}