{"record":{"id":"876f9f98250b4927","repo":"sgl-project/sglang","slug":"invalid-value-other","errorCode":null,"errorMessage":"Invalid value: {other}","messagePattern":"Invalid value: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/lang/interpreter.py","lineNumber":1096,"sourceCode":"    def __getitem__(self, i: int):\n        return self.states[i]\n\n    def __setitem__(self, i: int, value):\n        assert self.states[i] == value\n\n    def __iadd__(self, other):\n        if isinstance(other, Callable):\n            # lambda function\n            for i in range(len(self.states)):\n                self.states[i] += other(i)\n        elif isinstance(other, SglExpr):\n            for i in range(len(self.states)):\n                self.states[i] += other\n        elif isinstance(other, (list, tuple)):\n            for i in range(len(self.states)):\n                self.states[i] += other[i]\n        else:\n            raise ValueError(f\"Invalid value: {other}\")\n\n        return self\n","sourceCodeStart":1078,"sourceCodeEnd":1099,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/lang/interpreter.py#L1078-L1099","documentation":"Raised by the batch-state __iadd__ (broadcasting a value across forked states) when `other` is not a single appendable value, a list, or a tuple. The multi-state container only supports appending one value to all states or element-wise lists/tuples of the same length.","triggerScenarios":"`states += x` where x is a dict, generator, set, or a list whose length != number of forked states; passing a tuple of the wrong arity.","commonSituations":"Broadcasting per-branch prompts built as a dict comprehension or generator; length mismatch after changing fork(size=N); assuming any iterable works when only list/tuple are accepted.","solutions":["Materialize per-state values as a list with exactly len(states) entries: states += [v1, v2, ...]","Or append a single str/Sgl primitive to broadcast to all states","Check len(your_list) == number of forked states before +="],"exampleFix":"# before\nstates += (f\"prompt {i}\" for i in range(n))  # generator -> raises\n# after\nstates += [f\"prompt {i}\" for i in range(n)]   # list, len == n_states","handlingStrategy":"type-guard","validationCode":"if isinstance(other, (list, tuple)):\n    assert len(other) == len(states), f\"need {len(states)} values, got {len(other)}\"\n    states += list(other)\nelse:\n    states += other  # broadcast single primitive","typeGuard":"def broadcastable(other, n_states: int) -> bool:\n    if isinstance(other, (list, tuple)):\n        return len(other) == n_states\n    return isinstance(other, (str,)) or type(other).__name__.startswith(\"Sgl\")","tryCatchPattern":"try:\n    states += other\nexcept ValueError as e:\n    if \"Invalid value\" in str(e):\n        states += list(other)  # materialize iterables\n    else:\n        raise","preventionTips":["Materialize generators/comprehensions to list before broadcasting","Keep per-state value lists length-aligned with fork size","Prefer broadcasting a single string when all branches share content"],"tags":["operator-overload","fork-join","type-error","dsl"],"backgroundTag":"unsupported-operand-type","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}