Skip to content

Commit 28d588a

Browse files
committed
Added strict validation for nested array inputs in parse_raw_prompts
Signed-off-by: Kayvan Mivehnejad <[email protected]>
1 parent dc7480e commit 28d588a

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

vllm/inputs/parse.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,19 @@ def parse_raw_prompts(
4545

4646
# case 4: array of token arrays
4747
if is_list_of(prompt, list):
48-
first = prompt[0]
49-
if not isinstance(first, list):
50-
raise ValueError("prompt expected to be a list of lists")
51-
52-
if len(first) == 0:
53-
raise ValueError("Please provide at least one prompt")
54-
55-
# strict validation: every nested list must be list[int]
56-
if not all(is_list_of(elem, int) for elem in prompt):
57-
raise TypeError("Nested lists must contain only integers")
48+
for elem in prompt:
49+
if not isinstance(elem, list):
50+
raise TypeError(
51+
"prompt must be a list of lists, but found a non-list element."
52+
)
53+
if not elem:
54+
raise ValueError(
55+
"Empty lists of tokens are not allowed in prompts."
56+
)
57+
if not is_list_of(elem, int, check="all"):
58+
raise TypeError(
59+
"Nested lists of tokens must contain only integers."
60+
)
5861

5962
prompt = cast(list[list[int]], prompt)
6063
return [TokensPrompt(prompt_token_ids=elem) for elem in prompt]

0 commit comments

Comments
 (0)