[Misc] Use VLLMValidationError in pooling input validation (#51931)

Signed-off-by: frank-suwen <suwenw2@outlook.com>

Frank committed Aug 12, 2026 at 23:13 UTC 7bc1660bd67d94cd2c8188d5e2cf2828e5b1bc7a
3 files changed +83 -5
tests/entrypoints/pooling/basic/test_encode.py
+2 -1
@@ -7,6 +7,7 @@ import pytest
7
8 from vllm import LLM, PoolingParams
9 from vllm.distributed import cleanup_dist_env_and_memory
10 +from vllm.exceptions import VLLMValidationError
11
12 MODEL_NAME = "intfloat/multilingual-e5-small"
13
@@ -61,7 +62,7 @@ def test_multiple_pooling_params(llm: LLM):
62 assert len(PROMPTS) == len(outputs)
63
64 # Exception raised, if the size of params does not match the size of prompts
64 - with pytest.raises(ValueError):
65 + with pytest.raises(VLLMValidationError):
66 outputs = llm.encode(
67 PROMPTS, pooling_params=pooling_params[:3], pooling_task="embed"
68 )
tests/entrypoints/pooling/test_io_processor.py new
+76
@@ -0,0 +1,76 @@
1 +# SPDX-License-Identifier: Apache-2.0
2 +# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 +
4 +from types import SimpleNamespace
5 +
6 +import pytest
7 +
8 +from vllm import PoolingParams
9 +from vllm.entrypoints.pooling.base.io_processor import PoolingIOProcessor
10 +from vllm.entrypoints.pooling.typing import OfflineEncodeInputsContext
11 +from vllm.exceptions import VLLMValidationError
12 +from vllm.renderers import TokenizeParams
13 +
14 +
15 +@pytest.fixture
16 +def processor() -> PoolingIOProcessor:
17 + return object.__new__(PoolingIOProcessor)
18 +
19 +
20 +def test_rejects_untrusted_request_chat_template(processor: PoolingIOProcessor):
21 + with pytest.raises(VLLMValidationError) as exc_info:
22 + processor._validate_chat_template("template", None, False)
23 +
24 + assert str(exc_info.value) == (
25 + "Chat template is passed with request, but "
26 + "--trust-request-chat-template is not set. "
27 + "Refused request with untrusted chat template."
28 + )
29 + assert exc_info.value.parameter is None
30 + assert exc_info.value.value is None
31 +
32 +
33 +def test_rejects_mismatched_pooling_params(processor: PoolingIOProcessor):
34 + with pytest.raises(VLLMValidationError) as exc_info:
35 + processor._params_to_seq([PoolingParams()], num_requests=2)
36 +
37 + assert str(exc_info.value) == (
38 + "The lengths of prompts (2) and params (1) must be the same."
39 + )
40 + assert exc_info.value.parameter is None
41 + assert exc_info.value.value is None
42 +
43 +
44 +def test_rejects_mismatched_lora_requests(processor: PoolingIOProcessor):
45 + with pytest.raises(VLLMValidationError) as exc_info:
46 + processor._lora_request_to_seq([None], num_requests=2)
47 +
48 + assert str(exc_info.value) == (
49 + "The lengths of prompts (2) and lora_request (1) must be the same."
50 + )
51 + assert exc_info.value.parameter is None
52 + assert exc_info.value.value is None
53 +
54 +
55 +def test_rejects_conflicting_pooling_task(processor: PoolingIOProcessor):
56 + processor.model_config = SimpleNamespace(is_encoder_decoder=False)
57 + processor.renderer = SimpleNamespace(
58 + default_cmpl_tok_params=TokenizeParams(max_total_tokens=None)
59 + )
60 + ctx = OfflineEncodeInputsContext(
61 + pooling_task="embed",
62 + tokenization_kwargs=None,
63 + lora_request=None,
64 + priorities=None,
65 + prompts=[[1]],
66 + pooling_params=PoolingParams(task="classify"),
67 + )
68 +
69 + with pytest.raises(VLLMValidationError) as exc_info:
70 + processor.get_request_factory_offline(ctx)
71 +
72 + assert str(exc_info.value) == (
73 + "You cannot overwrite param.task='classify' with pooling_task='embed'!"
74 + )
75 + assert exc_info.value.parameter is None
76 + assert exc_info.value.value is None
vllm/entrypoints/pooling/base/io_processor.py
+5 -4
@@ -13,6 +13,7 @@ from vllm.config import VllmConfig
13 from vllm.entrypoints.chat_utils import (
14 ChatTemplateConfig,
15 )
16 +from vllm.exceptions import VLLMValidationError
17 from vllm.lora.request import LoRARequest
18 from vllm.renderers import BaseRenderer, merge_kwargs
19 from vllm.renderers.inputs.preprocess import parse_model_prompt, prompt_to_seq
@@ -217,7 +218,7 @@ class PoolingIOProcessor:
218 pass
219 elif param.task != pooling_task:
220 msg = f"You cannot overwrite {param.task=!r} with {pooling_task=!r}!"
220 - raise ValueError(msg)
221 + raise VLLMValidationError(msg)
222
223 seq_lora_requests = self._lora_request_to_seq(ctx.lora_request, num_requests)
224 seq_priority = self._priority_to_seq(ctx.priorities, num_requests)
@@ -293,7 +294,7 @@ class PoolingIOProcessor:
294 and chat_template_kwargs.get("chat_template") is not None
295 )
296 ):
296 - raise ValueError(
297 + raise VLLMValidationError(
298 "Chat template is passed with request, but "
299 "--trust-request-chat-template is not set. "
300 "Refused request with untrusted chat template."
@@ -307,7 +308,7 @@ class PoolingIOProcessor:
308 ) -> Sequence[PoolingParams]:
309 if isinstance(params, Sequence):
310 if len(params) != num_requests:
310 - raise ValueError(
311 + raise VLLMValidationError(
312 f"The lengths of prompts ({num_requests}) "
313 f"and params ({len(params)}) must be the same."
314 )
@@ -323,7 +324,7 @@ class PoolingIOProcessor:
324 ) -> Sequence[LoRARequest | None]:
325 if isinstance(lora_request, Sequence):
326 if len(lora_request) != num_requests:
326 - raise ValueError(
327 + raise VLLMValidationError(
328 f"The lengths of prompts ({num_requests}) "
329 f"and lora_request ({len(lora_request)}) must be the same."
330 )