{"record":{"id":"b8e90ca406d8d9f7","repo":"sgl-project/sglang","slug":"invalid-prompts-type-for-score-prompts","errorCode":null,"errorMessage":"Invalid prompts type for score_prompts.","messagePattern":"Invalid prompts type for score_prompts\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/managers/tokenizer_manager_score_mixin.py","lineNumber":66,"sourceCode":"                items=prompts,  # type: ignore[arg-type]\n                label_token_ids=label_token_ids,\n                apply_softmax=apply_softmax,\n                item_first=False,\n                request=request,\n            )\n\n        # Tokenized prompts\n        if isinstance(prompts, list) and (not prompts or isinstance(prompts[0], list)):\n            return await self.score_request(\n                query=[],\n                items=prompts,\n                label_token_ids=label_token_ids,\n                apply_softmax=apply_softmax,\n                item_first=False,\n                request=request,\n            )\n\n        raise ValueError(\"Invalid prompts type for score_prompts.\")\n\n    def _build_multi_item_token_sequence(\n        self, query: List[int], items: List[List[int]], delimiter_token_id: int\n    ) -> Tuple[List[int], List[int]]:\n        \"\"\"\n        Build a single token sequence for multi-item scoring.\n        Format: query<delimiter>item1<delimiter>item2<delimiter>item3<delimiter>\n        \"\"\"\n        combined_sequence = query[:]  # Start with query\n        delimiter_indices = []\n\n        for item in items:\n            delimiter_indices.append(len(combined_sequence))\n            combined_sequence.append(delimiter_token_id)  # Add delimiter\n            combined_sequence.extend(item)  # Add item tokens\n\n        # Add final delimiter after the last item for logprob extraction\n        delimiter_indices.append(len(combined_sequence))","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/managers/tokenizer_manager_score_mixin.py#L48-L84","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nscores = engine.score_prompts(prompts=np.array([\"a\", \"b\"]))\n\n# after\nscores = engine.score_prompts(prompts=[\"a\", \"b\"])\n# or token ids\nscores = engine.score_prompts(prompts=[[1,2,3]])","handlingStrategy":"type-guard","validationCode":"assert isinstance(prompts, (str, list)), type(prompts)\nif isinstance(prompts, list):\n    assert all(isinstance(p, (str, list)) for p in prompts)","typeGuard":"def valid_score_prompts(p) -> bool:\n    if isinstance(p, str): return True\n    if isinstance(p, list):\n        return all(isinstance(x, str) or (isinstance(x, list) and all(isinstance(t, int) for t in x)) for x in p)\n    return False","tryCatchPattern":"try:\n    scores = engine.score_prompts(prompts=prompts)\nexcept ValueError as e:\n    if \"Invalid prompts type\" in str(e):\n        prompts = prompts.tolist() if hasattr(prompts, \"tolist\") else list(prompts)\n        scores = engine.score_prompts(prompts=prompts)\n    else:\n        raise","preventionTips":["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"],"tags":["scoring","type-validation","input-format"],"backgroundTag":"invalid-input-type","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}