{"record":{"id":"40be7aff7856847b","repo":"jax-ml/jax","slug":"unknown-character-char","errorCode":null,"errorMessage":"Unknown character '{char}'","messagePattern":"Unknown character '(.+?)'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/custom_partitioning_sharding_rule.py","lineNumber":41,"sourceCode":"# A single character replacement for ... to simplify parsing.\nBATCHING: str = \"…\"\n\n# A prefix for names of batching dimension factors, used for expanding the\n# leading ... into factors.\n_BATCHING_DIM_FACTOR_PREFIX = \"?\"\n\n\ndef _check_factor(factor:str):\n  \"\"\"Validates a factor.\n\n  A factor is a string starting with a letter and containing only letters,\n  digits, or underscores.\n  \"\"\"\n  if not factor[0].isalpha():\n    raise ValueError(f\"Factor names have to start with a letter, but got '{factor[0]}'\")\n  for char in factor[1:]:\n    if char != \"_\" and not char.isdigit() and not char.isalpha():\n      raise ValueError(f\"Unknown character '{char}'\")\n\ndef _is_batching(factor: str) -> bool:\n  \"\"\"Checks if a factor is a representation for leading batching dimensions.\n\n  Leading batching dimensions is represented by a factor containing ... and\n     optionally followed by a digit, and ... is equivalent to ...0.\n  \"\"\"\n  if len(factor) < 1 or factor[0] != BATCHING:\n    return False\n  return len(factor) == 1 or factor[1:].isdigit()\n\ndef _get_batching_group(factor: str) -> str:\n  \"\"\"Extracts the batching group from a factor for leading batching dimensions.\"\"\"\n  return factor[1:] if len(factor) > 1 else \"0\"\n\nclass CompoundFactor(tuple):\n  \"\"\"Describes the factors for a compound factor.\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/custom_partitioning_sharding_rule.py#L23-L59","documentation":"Factor names in sharding rules may contain only letters, digits, and underscores after the first character. Any other character (e.g. '-', '.', ',', space) raises ValueError naming the offending character.","triggerScenarios":"A factor like 'my-factor', 'x.y', or 'b ' in an ArrayMapping or sharding-rule string; stray separators inside factor tokens.","commonSituations":"Using hyphenated mesh axis names or embedding punctuation in factor names when writing Einsum-like notation.","solutions":["Replace invalid characters with underscores or letters","Validate factor strings against ^[A-Za-z][A-Za-z0-9_]*$ before building rules","Rename mesh axes used as factors to alphanumeric/underscore form"],"exampleFix":"# before\nArrayMapping('batch-1', 'i')\n\n# after\nArrayMapping('batch_1', 'i')","handlingStrategy":"validation","validationCode":"import re\ndef check_factor(f): assert re.fullmatch(r'[A-Za-z][A-Za-z0-9_]*', f), f","typeGuard":"def valid_factor(f: str) -> bool:\n    return bool(re.fullmatch(r'[A-Za-z][A-Za-z0-9_]*', f))","tryCatchPattern":null,"preventionTips":["Restrict factor names to letters, digits, underscores","Avoid hyphens/dots in mesh axis names used as factors"],"tags":["jax","shardy","sharding-rule","validation"],"backgroundTag":"invalid-identifier-name","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}