@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 29f7d97715
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 11, 12:30 UTC

Improve parse_raw_prompt test cases for invalid input .v2 (#30512)

Signed-off-by: Kayvan Mivehnejad <K.Mivehnejad@gmail.com>

Kayvan Mivehnejad committed Dec 13, 2025 at 22:18 UTC 29f7d9771569f26238d67cf6ea3a8792fb6a7792
2 files changed +24 -8
tests/test_inputs.py
+7
@@ -34,6 +34,13 @@ INPUTS_SLICES = [
34 ]
35
36
37 +# Test that a nested mixed-type list of lists raises a TypeError.
38 +@pytest.mark.parametrize("invalid_input", [[[1, 2], ["foo", "bar"]]])
39 +def test_invalid_input_raise_type_error(invalid_input):
40 + with pytest.raises(TypeError):
41 + parse_raw_prompts(invalid_input)
42 +
43 +
44 def test_parse_raw_single_batch_empty():
45 with pytest.raises(ValueError, match="at least one prompt"):
46 parse_raw_prompts([])
vllm/inputs/parse.py
+17 -8
@@ -33,22 +33,31 @@ def parse_raw_prompts(
33 if len(prompt) == 0:
34 raise ValueError("please provide at least one prompt")
35
36 + # case 2: array of strings
37 if is_list_of(prompt, str):
37 - # case 2: array of strings
38 prompt = cast(list[str], prompt)
39 return [TextPrompt(prompt=elem) for elem in prompt]
40 +
41 + # case 3: array of tokens
42 if is_list_of(prompt, int):
41 - # case 3: array of tokens
43 prompt = cast(list[int], prompt)
44 return [TokensPrompt(prompt_token_ids=prompt)]
45 +
46 + # case 4: array of token arrays
47 if is_list_of(prompt, list):
45 - prompt = cast(list[list[int]], prompt)
46 - if len(prompt[0]) == 0:
47 - raise ValueError("please provide at least one prompt")
48 + first = prompt[0]
49 + if not isinstance(first, list):
50 + raise ValueError("prompt expected to be a list of lists")
51
49 - if is_list_of(prompt[0], int):
50 - # case 4: array of token arrays
51 - return [TokensPrompt(prompt_token_ids=elem) for elem in prompt]
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")
58 +
59 + prompt = cast(list[list[int]], prompt)
60 + return [TokensPrompt(prompt_token_ids=elem) for elem in prompt]
61
62 raise TypeError(
63 "prompt must be a string, array of strings, "