{"record":{"id":"8f423d71cd83f87d","repo":"jax-ml/jax","slug":"brackets-are-not-balanced","errorCode":null,"errorMessage":"Brackets are not balanced","messagePattern":"Brackets are not balanced","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/custom_partitioning_sharding_rule.py","lineNumber":288,"sourceCode":"        batching_group = str(int(batching_group_str))\n      else:\n        batching_group = \"0\"\n\n      add_factor(f\"{BATCHING}{batching_group}\")\n      continue\n    if char in \"(), \":\n      if current_factor is not None:\n        add_factor(current_factor)\n        current_factor = None\n      if char == \"(\":\n        if current_compound_dim is not None:\n          raise ValueError(\n              \"Compound factors should be one level, nested brackets are not\"\n              \" allowed\")\n        current_compound_dim = []\n      elif char == \")\":\n        if current_compound_dim is None:\n          raise ValueError(\"Brackets are not balanced\")\n        if len(current_compound_dim) <= 1:\n          raise ValueError(\"Brackets should contain at least two factors\")\n        value.append(CompoundFactor(*current_compound_dim))\n        current_compound_dim = None\n      elif char == \",\":\n        all_values.append(ArrayMapping(*value))\n        value = []\n    elif char == \"_\" or char.isdigit() or char.isalpha():\n      if current_factor is None:\n        if str.isdigit(char):\n          raise ValueError(f\"Factor names have to start with a letter, but got '{char}'\")\n        current_factor = char\n      else:\n        current_factor += char\n    else:\n      raise ValueError(f\"Unknown character '{char}'\")\n\n  if current_compound_dim is not None:","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/custom_partitioning_sharding_rule.py#L270-L306","documentation":"A closing ')' was encountered while current_compound_dim is None, i.e. no compound factor is open. Parentheses in the rule must be balanced per operand/result expression.","triggerScenarios":"Rule fragment like 'i),j' or 'ij)->(ji' with a stray closing parenthesis.","commonSituations":"Hand-editing rule strings and deleting an opening '(' but not the ')'.","solutions":["Add the missing opening '(' so each ')' pairs with a '('","Re-count parentheses in each comma-separated operand/result expression"],"exampleFix":"# before\nrule = 'i)->(i'\n# after\nrule = '(i)->(i)'","handlingStrategy":"validation","validationCode":"import re\nfor side in rule.split('->'):\n    depth = 0\n    for c in side:\n        depth += c == '('\n        depth -= c == ')'\n        assert depth >= 0, 'unbalanced ) '\n    assert depth == 0, 'unbalanced ('","typeGuard":"def parens_balanced(rule: str) -> bool:\n    d = 0\n    for c in rule.replace('->', ''):\n        d += (c == '(') - (c == ')')\n        if d < 0: return False\n    return d == 0","tryCatchPattern":null,"preventionTips":["Validate balance before calling; a simple depth counter catches both this and 434"],"tags":["jax","sharding","unbalanced-parens","rule-syntax"],"backgroundTag":"unbalanced-delimiters","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}