[Bugfix] complete VLLMValidationError migration in chat_utils.py (#50254)
Signed-off-by: shaolila <shaolila@buaa.edu.cn> Co-authored-by: shaolila <shaolila@buaa.edu.cn>
Adababy committed
Sep 5, 2026 at 17:56 UTC
2902ca17e335457a0fa214638936d154907a2e18
3 files changed
+12
-7
tests/entrypoints/launchers/test_cli_args.py
+2
-1
@@ -11,6 +11,7 @@ from vllm.entrypoints.launchers.cli_args import (
11
validate_parsed_serve_args,
12
)
13
from vllm.entrypoints.openai.models.protocol import LoRAModulePath
14
+from vllm.exceptions import VLLMValidationError
15
from vllm.utils.argparse_utils import FlexibleArgumentParser
16
17
LORA_MODULE = {
@@ -204,7 +205,7 @@ def test_chat_template_validation_for_happy_paths(serve_parser):
205
def test_chat_template_validation_for_sad_paths(serve_parser):
206
"""Ensure validation fails if the chat template doesn't exist"""
207
args = serve_parser.parse_args(args=["--chat-template", "does/not/exist"])
207
- with pytest.raises(ValueError):
208
+ with pytest.raises(VLLMValidationError):
209
validate_parsed_serve_args(args)
210
211
tests/renderers/test_hf.py
+2
-1
@@ -6,6 +6,7 @@ import pytest
6
from vllm.config import ModelConfig
7
from vllm.entrypoints.chat_utils import load_chat_template
8
from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionRequest
9
+from vllm.exceptions import VLLMValidationError
10
from vllm.renderers.hf import (
11
_consolidate_system_messages,
12
_convert_developer_to_system,
@@ -97,7 +98,7 @@ def test_no_load_chat_template_filelike():
98
# Testing chatml template
99
template = "../../examples/does_not_exist"
100
100
- with pytest.raises(ValueError, match="looks like a file path"):
101
+ with pytest.raises(VLLMValidationError, match="looks like a file path"):
102
load_chat_template(chat_template=template)
103
104
vllm/entrypoints/chat_utils.py
+8
-5
@@ -1446,10 +1446,11 @@ def validate_chat_template(chat_template: Path | str | None):
1446
1447
builtin_template_path = CHAT_TEMPLATES_DIR / chat_template
1448
if not builtin_template_path.exists():
1449
- raise ValueError(
1449
+ raise VLLMValidationError(
1450
f"The supplied chat template string ({chat_template}) "
1451
f"appears path-like, but doesn't exist! "
1452
- f"Tried: {chat_template} and {builtin_template_path}"
1452
+ f"Tried: {chat_template} and {builtin_template_path}",
1453
+ parameter="chat_template",
1454
)
1455
1456
else:
@@ -1497,7 +1498,7 @@ def _load_chat_template(
1498
f"Tried: {chat_template} and {builtin_template_path}. "
1499
f"Reason: {e}"
1500
)
1500
- raise ValueError(msg) from e
1501
+ raise VLLMValidationError(msg, parameter="chat_template") from e
1502
1503
# If opening a file fails, set chat template to be args to
1504
# ensure we decode so our escape are interpreted correctly
@@ -1575,7 +1576,8 @@ def _get_full_multimodal_text_prompt(
1576
logger.debug("Input prompt: %s", text_prompt)
1577
raise VLLMValidationError(
1578
f"Found more '{placeholder}' placeholders in input prompt than "
1578
- "actual multimodal data items."
1579
+ "actual multimodal data items.",
1580
+ parameter="messages",
1581
)
1582
1583
missing_placeholders.extend([placeholder] * placeholder_counts[placeholder])
@@ -1833,7 +1835,8 @@ def _reject_reserved_placeholder_in_text(text: str, model_config: ModelConfig) -
1835
raise VLLMValidationError(
1836
_RESERVED_PLACEHOLDER_IN_TEXT_ERROR.format(
1837
token=PROMPT_EMBEDS_PLACEHOLDER_TOKEN
1836
- )
1838
+ ),
1839
+ parameter="messages",
1840
)
1841
1842