sgl-project/sglang · error · ValueError
Invalid prompts type for score_prompts.
Error message
Invalid prompts type for score_prompts.
What it means
score_prompts only accepts prompts as a string, a list of strings, or a list of token-id lists (and similar list forms); after trying all supported shapes it falls through to this ValueError. Any other type (dict, tuple, nested irregular structure, None) is rejected.
Source
Thrown at python/sglang/srt/managers/tokenizer_manager_score_mixin.py:66
items=prompts, # type: ignore[arg-type]
label_token_ids=label_token_ids,
apply_softmax=apply_softmax,
item_first=False,
request=request,
)
# Tokenized prompts
if isinstance(prompts, list) and (not prompts or isinstance(prompts[0], list)):
return await self.score_request(
query=[],
items=prompts,
label_token_ids=label_token_ids,
apply_softmax=apply_softmax,
item_first=False,
request=request,
)
raise ValueError("Invalid prompts type for score_prompts.")
def _build_multi_item_token_sequence(
self, query: List[int], items: List[List[int]], delimiter_token_id: int
) -> Tuple[List[int], List[int]]:
"""
Build a single token sequence for multi-item scoring.
Format: query<delimiter>item1<delimiter>item2<delimiter>item3<delimiter>
"""
combined_sequence = query[:] # Start with query
delimiter_indices = []
for item in items:
delimiter_indices.append(len(combined_sequence))
combined_sequence.append(delimiter_token_id) # Add delimiter
combined_sequence.extend(item) # Add item tokens
# Add final delimiter after the last item for logprob extraction
delimiter_indices.append(len(combined_sequence))View on GitHub (pinned to 0132848349)
Solutions
- Convert prompts to str, List[str], or List[List[int]] before calling score_prompts
- If using numpy arrays, call .tolist() first
- Guard the call with an isinstance check on the input shape
Example fix
# before scores = engine.score_prompts(prompts=np.array(["a", "b"])) # after scores = engine.score_prompts(prompts=["a", "b"]) # or token ids scores = engine.score_prompts(prompts=[[1,2,3]])
Defensive patterns
Strategy: type-guard
Validate before calling
assert isinstance(prompts, (str, list)), type(prompts)
if isinstance(prompts, list):
assert all(isinstance(p, (str, list)) for p in prompts) Type guard
def valid_score_prompts(p) -> bool:
if isinstance(p, str): return True
if isinstance(p, list):
return all(isinstance(x, str) or (isinstance(x, list) and all(isinstance(t, int) for t in x)) for x in p)
return False Try / catch
try:
scores = engine.score_prompts(prompts=prompts)
except ValueError as e:
if "Invalid prompts type" in str(e):
prompts = prompts.tolist() if hasattr(prompts, "tolist") else list(prompts)
scores = engine.score_prompts(prompts=prompts)
else:
raise Prevention
- Convert numpy/torch tensors with .tolist() before calling scoring APIs
- Normalize inputs at the client boundary with an isinstance guard
- Never pass dict/tokenizer-encoding objects as prompts
When it happens
Trigger: Calling score_prompts(prompts=...) with a non-supported type such as a dict, tuple, numpy array, or None; or a heterogeneous list whose elements are neither strings nor int-lists.
Common situations: Passing tokenizer output objects (BatchEncoding) or numpy arrays directly instead of plain lists; refactoring code that previously called a different scoring API with different input shapes; None defaults leaking through.
Related errors
- Invalid combination of query/items types for score_request.
- num_token_non_padded must be a torch.Tensor
- actions must be a list[list[str]]
- rollout_noise_level must be a number, got {noise!r}
- {field_name} must be a JSON object
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/b8e90ca406d8d9f7.
Report an issue: GitHub.