[Misc] Use VLLMValidationError in scoring input validation (#51753)
Signed-off-by: frank-suwen <suwenw2@outlook.com>
Frank committed
Aug 10, 2026 at 21:12 UTC
adc1200597c0e8e024173bf38270a660b176642d
2 files changed
+72
-4
tests/entrypoints/pooling/scoring/test_utils.py
new
+65
@@ -0,0 +1,65 @@
1
+# SPDX-License-Identifier: Apache-2.0
2
+# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
+
4
+import pytest
5
+
6
+from vllm.entrypoints.pooling.scoring.typing import ScoreInput
7
+from vllm.entrypoints.pooling.scoring.utils import validate_score_input
8
+from vllm.exceptions import VLLMValidationError
9
+
10
+
11
+@pytest.mark.parametrize(
12
+ ("data_1", "data_2", "is_multimodal_model", "architecture", "message"),
13
+ [
14
+ pytest.param(
15
+ {"content": []},
16
+ "document",
17
+ False,
18
+ "TestModel",
19
+ "MultiModalParam is not supported for TestModel",
20
+ id="unsupported-multimodal-input",
21
+ ),
22
+ pytest.param(
23
+ ["query 1", "query 2"],
24
+ ["document"],
25
+ False,
26
+ "TestModel",
27
+ "Input lengths must be either 1:1, 1:N or N:N",
28
+ id="incompatible-input-lengths",
29
+ ),
30
+ pytest.param(
31
+ [],
32
+ ["document"],
33
+ False,
34
+ "TestModel",
35
+ "At least one text element must be given",
36
+ id="empty-first-input",
37
+ ),
38
+ pytest.param(
39
+ ["query"],
40
+ [],
41
+ False,
42
+ "TestModel",
43
+ "At least one text_pair element must be given",
44
+ id="empty-second-input",
45
+ ),
46
+ ],
47
+)
48
+def test_validate_score_input_rejects_invalid_inputs(
49
+ data_1: ScoreInput | list[ScoreInput],
50
+ data_2: ScoreInput | list[ScoreInput],
51
+ is_multimodal_model: bool,
52
+ architecture: str,
53
+ message: str,
54
+):
55
+ with pytest.raises(VLLMValidationError) as exc_info:
56
+ validate_score_input(
57
+ data_1,
58
+ data_2,
59
+ is_multimodal_model=is_multimodal_model,
60
+ architecture=architecture,
61
+ )
62
+
63
+ assert str(exc_info.value) == message
64
+ assert exc_info.value.parameter is None
65
+ assert exc_info.value.value is None
vllm/entrypoints/pooling/scoring/utils.py
+7
-4
@@ -15,6 +15,7 @@ from vllm.entrypoints.chat_utils import (
15
MultiModalItemTracker,
16
_parse_chat_message_content_parts,
17
)
18
+from vllm.exceptions import VLLMValidationError
19
from vllm.inputs import MultiModalDataDict, MultiModalUUIDDict
20
21
from .typing import (
@@ -85,7 +86,9 @@ def _validate_mm_score_input(
86
out.append(d)
87
else:
88
if not is_multimodal_model:
88
- raise ValueError(f"MultiModalParam is not supported for {architecture}")
89
+ raise VLLMValidationError(
90
+ f"MultiModalParam is not supported for {architecture}"
91
+ )
92
content = cast(list[ScoreContentPartParam], d.get("content", []))
93
out.append(content)
94
return out
@@ -99,11 +102,11 @@ def _validate_score_input_lens(
102
len_2 = len(data_2)
103
104
if len_1 > 1 and len_1 != len_2:
102
- raise ValueError("Input lengths must be either 1:1, 1:N or N:N")
105
+ raise VLLMValidationError("Input lengths must be either 1:1, 1:N or N:N")
106
if len_1 == 0:
104
- raise ValueError("At least one text element must be given")
107
+ raise VLLMValidationError("At least one text element must be given")
108
if len_2 == 0:
106
- raise ValueError("At least one text_pair element must be given")
109
+ raise VLLMValidationError("At least one text_pair element must be given")
110
111
112
def validate_score_input(