sgl-project/sglang · error · ValueError
elements must be int or list; got {type(v[0]).__name__}
Error message
elements must be int or list; got {type(v[0]).__name__} What it means
The outer value is a non-empty list but its first element is neither an int nor a list, so the validator cannot decide between 1D and 2D shapes and rejects the input.
Source
Thrown at python/sglang/srt/utils/field_validators.py:81
# Accept None
return v
if not isinstance(v, list):
raise ValueError(f"must be list or null; got {type(v).__name__}")
if not v:
# Accept empty list
return v
if isinstance(v[0], int):
# Accept list[int]
return validate_list_i64_1d(v)
if isinstance(v[0], list):
# Accept list[list[int]]
for i, row in enumerate(v):
try:
validate_list_i64_1d(row)
except ValueError as e:
raise ValueError(f"row {i}: {e}") from None
return v
raise ValueError(f"elements must be int or list; got {type(v[0]).__name__}")
View on GitHub (pinned to 0132848349)
Solutions
- Convert string elements to int before passing (e.g. [int(x) for x in vals])
- Remove None/dict/tuple elements
- If you meant nested rows, wrap each element in a list
Example fix
# before arg = ['1', '2', '3'] # after arg = [1, 2, 3]
Defensive patterns
Strategy: validation
Validate before calling
first = v[0] if v else None
assert first is None or type(first) in (int, list), f'bad first element {first!r}' Type guard
def has_homogeneous_first(v) -> TypeGuard[list]:
return isinstance(v, list) and (not v or type(v[0]) in (int, list)) Prevention
- Convert CLI string args with [int(x) for x in s.split(',')]
- Never mix strings and ints in config lists
When it happens
Trigger: Passing ['1','2'], [None], [[1],'2'] style lists, or a list of dicts/tuples where list[int] | list[list[int]] is expected.
Common situations: Parsing CLI input as strings and passing through unparsed, or JSON configs with mixed types.
Related errors
- Invalid component residency assignment: {value!r}
- Invalid component residency assignment: {raw_selector!r}={ra
- must be list or null; got {type(v).__name__}
- Unknown type: {type(other)}
- Invalid threshold_type for topk: {threshold_type}. Choose 'q
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/93bc5997b30730d6.
Report an issue: GitHub.