[Misc] Use VLLMValidationError in chat completion tool and batch validators (#49214)
Signed-off-by: Umut Polat <52835619+umut-polat@users.noreply.github.com>
Umut Polat committed
Jul 21, 2026 at 14:38 UTC
040cbf95cc05b14af8874ea980f3f4deb71b4708
1 file changed
+16
-11
vllm/entrypoints/openai/chat_completion/protocol.py
+16
-11
@@ -687,9 +687,9 @@ class ChatCompletionRequest(OpenAIBaseModel):
687
skip_special_tokens=self.skip_special_tokens,
688
spaces_between_special_tokens=self.spaces_between_special_tokens,
689
include_stop_str_in_output=self.include_stop_str_in_output,
690
- output_kind=RequestOutputKind.DELTA
691
- if self.stream
692
- else RequestOutputKind.FINAL_ONLY,
690
+ output_kind=(
691
+ RequestOutputKind.DELTA if self.stream else RequestOutputKind.FINAL_ONLY
692
+ ),
693
structured_outputs=self.extract_structured_outputs(),
694
logit_bias=self.logit_bias,
695
bad_words=self.bad_words,
@@ -849,9 +849,10 @@ class ChatCompletionRequest(OpenAIBaseModel):
849
850
# Reject empty tools array, matching OpenAI API behavior
851
if data.get("tools") == []:
852
- raise ValueError(
852
+ raise VLLMValidationError(
853
"`tools` must not be an empty array. "
854
- "Either provide at least one tool or omit the field entirely."
854
+ "Either provide at least one tool or omit the field entirely.",
855
+ parameter="tools",
856
)
857
858
# if "tool_choice" is not specified but tools are provided,
@@ -1075,13 +1076,15 @@ class BatchChatCompletionRequest(OpenAIBaseModel):
1076
if isinstance(data, BatchChatCompletionRequest):
1077
data = data.model_dump(exclude_unset=True)
1078
if data.get("use_beam_search"):
1078
- raise ValueError(
1079
+ raise VLLMValidationError(
1080
"Batch chat completions do not support beam search. "
1080
- "Please set `use_beam_search` to False."
1081
+ "Please set `use_beam_search` to False.",
1082
+ parameter="use_beam_search",
1083
)
1084
if data.get("logprob_token_ids") and not data.get("logprobs"):
1083
- raise ValueError(
1084
- "when using `logprob_token_ids`, `logprobs` must be set to true."
1085
+ raise VLLMValidationError(
1086
+ "when using `logprob_token_ids`, `logprobs` must be set to true.",
1087
+ parameter="logprob_token_ids",
1088
)
1089
response_format = data.get("response_format")
1090
rf_type = (
@@ -1095,8 +1098,10 @@ class BatchChatCompletionRequest(OpenAIBaseModel):
1098
validate_structured_outputs_structural_tag(structured_outputs)
1099
n = data.get("n", 1)
1100
if n is not None and n != 1:
1098
- raise ValueError(
1099
- "Batch chat completions do not support `n > 1`. Please set `n` to 1."
1101
+ raise VLLMValidationError(
1102
+ "Batch chat completions do not support `n > 1`. Please set `n` to 1.",
1103
+ parameter="n",
1104
+ value=n,
1105
)
1106
return data
1107