From 4773df831577b6b2fa2170c7119334743dd90497 Mon Sep 17 00:00:00 2001 From: Kayvan Mivehnejad Date: Wed, 10 Dec 2025 20:00:45 -0500 Subject: [PATCH 1/7] Added a test for invalid inputs for parse_raw_prompts Signed-off-by: Kayvan Mivehnejad --- tests/test_inputs.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_inputs.py b/tests/test_inputs.py index 073be24a4a07..989c845fd9ad 100644 --- a/tests/test_inputs.py +++ b/tests/test_inputs.py @@ -33,6 +33,16 @@ slice(None, None, -2), ] +@pytest.mark.parametrize( + "invalid_input", + [ + ["foo", 1], # mixed of string and token + [["foo"], ["bar"]] # list of list of strings + ] +) +def test_invalid_input_raise_type_error(invalid_input): + with pytest.raises(TypeError): + parse_raw_prompts(invalid_input) # Test that a nested mixed-type list of lists raises a TypeError. @pytest.mark.parametrize("invalid_input", [[[1, 2], ["foo", "bar"]]]) From 0ac3b2f3d91aed1470c84beba56457e807b0e18e Mon Sep 17 00:00:00 2001 From: Kayvan Mivehnejad Date: Thu, 11 Dec 2025 13:31:34 -0500 Subject: [PATCH 2/7] Updated the invalid_input condition for parse_raw_prompt Signed-off-by: Kayvan Mivehnejad --- tests/test_inputs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_inputs.py b/tests/test_inputs.py index 989c845fd9ad..2e9057ed391d 100644 --- a/tests/test_inputs.py +++ b/tests/test_inputs.py @@ -33,11 +33,11 @@ slice(None, None, -2), ] +# List of lists that prompt[0] passes test case#4, but no TypeError will be raised. @pytest.mark.parametrize( "invalid_input", [ - ["foo", 1], # mixed of string and token - [["foo"], ["bar"]] # list of list of strings + [[1, 2], ["foo", "bar"]] ] ) def test_invalid_input_raise_type_error(invalid_input): From c9a523a4e71317ef4ebbf6e713f738d6a5121564 Mon Sep 17 00:00:00 2001 From: Kayvan Mivehnejad Date: Thu, 11 Dec 2025 14:29:50 -0500 Subject: [PATCH 3/7] Updated parse_raw_promptinput validation tests - uv pre-commit installed Signed-off-by: Kayvan Mivehnejad --- tests/test_inputs.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/test_inputs.py b/tests/test_inputs.py index 2e9057ed391d..073be24a4a07 100644 --- a/tests/test_inputs.py +++ b/tests/test_inputs.py @@ -33,16 +33,6 @@ slice(None, None, -2), ] -# List of lists that prompt[0] passes test case#4, but no TypeError will be raised. -@pytest.mark.parametrize( - "invalid_input", - [ - [[1, 2], ["foo", "bar"]] - ] -) -def test_invalid_input_raise_type_error(invalid_input): - with pytest.raises(TypeError): - parse_raw_prompts(invalid_input) # Test that a nested mixed-type list of lists raises a TypeError. @pytest.mark.parametrize("invalid_input", [[[1, 2], ["foo", "bar"]]]) From d9dd01da99d1f1e01a3ba97a99a2d123262cf3ee Mon Sep 17 00:00:00 2001 From: Kayvan Mivehnejad Date: Sun, 14 Dec 2025 13:29:59 -0500 Subject: [PATCH 4/7] Added strict validation for nested array inputs in parse_raw_prompts Signed-off-by: Kayvan Mivehnejad --- vllm/inputs/parse.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/vllm/inputs/parse.py b/vllm/inputs/parse.py index 71289277eb98..a8269ffa90bf 100644 --- a/vllm/inputs/parse.py +++ b/vllm/inputs/parse.py @@ -45,16 +45,19 @@ def parse_raw_prompts( # case 4: array of token arrays if is_list_of(prompt, list): - first = prompt[0] - if not isinstance(first, list): - raise ValueError("prompt expected to be a list of lists") - - if len(first) == 0: - raise ValueError("Please provide at least one prompt") - - # strict validation: every nested list must be list[int] - if not all(is_list_of(elem, int) for elem in prompt): - raise TypeError("Nested lists must contain only integers") + for elem in prompt: + if not isinstance(elem, list): + raise TypeError( + "prompt must be a list of lists, but found a non-list element." + ) + if not elem: + raise ValueError( + "Empty lists of tokens are not allowed in prompts." + ) + if not is_list_of(elem, int, check="all"): + raise TypeError( + "Nested lists of tokens must contain only integers." + ) prompt = cast(list[list[int]], prompt) return [TokensPrompt(prompt_token_ids=elem) for elem in prompt] From 4c8d1fc1bb0dd5df86250e40dc4b03ec885fc339 Mon Sep 17 00:00:00 2001 From: Kayvan Mivehnejad Date: Mon, 15 Dec 2025 09:31:08 -0500 Subject: [PATCH 5/7] Updated parse_raw_prompt control flow to raise ValueError for empty nested list inputs Signed-off-by: Kayvan Mivehnejad --- vllm/inputs/parse.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vllm/inputs/parse.py b/vllm/inputs/parse.py index a8269ffa90bf..60a2d713fa15 100644 --- a/vllm/inputs/parse.py +++ b/vllm/inputs/parse.py @@ -45,6 +45,10 @@ def parse_raw_prompts( # case 4: array of token arrays if is_list_of(prompt, list): + if len(prompt) == 0 or ( + len(prompt) == 1 and isinstance(prompt[0], list) and len(prompt[0]) == 0 + ): + raise ValueError("please provide at least one prompt") for elem in prompt: if not isinstance(elem, list): raise TypeError( From 5cc0f4a0511eab6576b51fd48c7de147515296b9 Mon Sep 17 00:00:00 2001 From: Kayvan Mivehnejad Date: Tue, 16 Dec 2025 10:21:27 -0500 Subject: [PATCH 6/7] Updated nested token validation to avoid expensive asymptotic check Signed-off-by: Kayvan Mivehnejad --- tests/test_inputs.py | 7 ------- vllm/inputs/parse.py | 10 ++-------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/tests/test_inputs.py b/tests/test_inputs.py index 073be24a4a07..8351af2528e4 100644 --- a/tests/test_inputs.py +++ b/tests/test_inputs.py @@ -34,13 +34,6 @@ ] -# Test that a nested mixed-type list of lists raises a TypeError. -@pytest.mark.parametrize("invalid_input", [[[1, 2], ["foo", "bar"]]]) -def test_invalid_input_raise_type_error(invalid_input): - with pytest.raises(TypeError): - parse_raw_prompts(invalid_input) - - def test_parse_raw_single_batch_empty(): with pytest.raises(ValueError, match="at least one prompt"): parse_raw_prompts([]) diff --git a/vllm/inputs/parse.py b/vllm/inputs/parse.py index 60a2d713fa15..5e7795a14072 100644 --- a/vllm/inputs/parse.py +++ b/vllm/inputs/parse.py @@ -45,20 +45,14 @@ def parse_raw_prompts( # case 4: array of token arrays if is_list_of(prompt, list): - if len(prompt) == 0 or ( - len(prompt) == 1 and isinstance(prompt[0], list) and len(prompt[0]) == 0 - ): + if len(prompt) == 1 and isinstance(prompt[0], list) and len(prompt[0]) == 0: raise ValueError("please provide at least one prompt") for elem in prompt: if not isinstance(elem, list): raise TypeError( "prompt must be a list of lists, but found a non-list element." ) - if not elem: - raise ValueError( - "Empty lists of tokens are not allowed in prompts." - ) - if not is_list_of(elem, int, check="all"): + if not is_list_of(elem, int): raise TypeError( "Nested lists of tokens must contain only integers." ) From 46511617a9c69c07e1daacc244c7a9c20c45dfa6 Mon Sep 17 00:00:00 2001 From: Kayvan Mivehnejad Date: Wed, 17 Dec 2025 16:42:33 -0500 Subject: [PATCH 7/7] Added a test for nested mixed-type list of lists raising TypeError Signed-off-by: Kayvan Mivehnejad --- tests/test_inputs.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_inputs.py b/tests/test_inputs.py index 8351af2528e4..073be24a4a07 100644 --- a/tests/test_inputs.py +++ b/tests/test_inputs.py @@ -34,6 +34,13 @@ ] +# Test that a nested mixed-type list of lists raises a TypeError. +@pytest.mark.parametrize("invalid_input", [[[1, 2], ["foo", "bar"]]]) +def test_invalid_input_raise_type_error(invalid_input): + with pytest.raises(TypeError): + parse_raw_prompts(invalid_input) + + def test_parse_raw_single_batch_empty(): with pytest.raises(ValueError, match="at least one prompt"): parse_raw_prompts([])