From 040cbf95cc05b14af8874ea980f3f4deb71b4708 Mon Sep 17 00:00:00 2001 From: Umut Polat <52835619+umut-polat@users.noreply.github.com> Date: Tue, 21 Jul 2026 14:38:20 +0300 Subject: [PATCH] [Misc] Use VLLMValidationError in chat completion tool and batch validators (#49214) Signed-off-by: Umut Polat <52835619+umut-polat@users.noreply.github.com> --- .../openai/chat_completion/protocol.py | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/vllm/entrypoints/openai/chat_completion/protocol.py b/vllm/entrypoints/openai/chat_completion/protocol.py index af8a19c643..3b65faa5aa 100644 --- a/vllm/entrypoints/openai/chat_completion/protocol.py +++ b/vllm/entrypoints/openai/chat_completion/protocol.py @@ -687,9 +687,9 @@ class ChatCompletionRequest(OpenAIBaseModel): skip_special_tokens=self.skip_special_tokens, spaces_between_special_tokens=self.spaces_between_special_tokens, include_stop_str_in_output=self.include_stop_str_in_output, - output_kind=RequestOutputKind.DELTA - if self.stream - else RequestOutputKind.FINAL_ONLY, + output_kind=( + RequestOutputKind.DELTA if self.stream else RequestOutputKind.FINAL_ONLY + ), structured_outputs=self.extract_structured_outputs(), logit_bias=self.logit_bias, bad_words=self.bad_words, @@ -849,9 +849,10 @@ class ChatCompletionRequest(OpenAIBaseModel): # Reject empty tools array, matching OpenAI API behavior if data.get("tools") == []: - raise ValueError( + raise VLLMValidationError( "`tools` must not be an empty array. " - "Either provide at least one tool or omit the field entirely." + "Either provide at least one tool or omit the field entirely.", + parameter="tools", ) # if "tool_choice" is not specified but tools are provided, @@ -1075,13 +1076,15 @@ class BatchChatCompletionRequest(OpenAIBaseModel): if isinstance(data, BatchChatCompletionRequest): data = data.model_dump(exclude_unset=True) if data.get("use_beam_search"): - raise ValueError( + raise VLLMValidationError( "Batch chat completions do not support beam search. " - "Please set `use_beam_search` to False." + "Please set `use_beam_search` to False.", + parameter="use_beam_search", ) if data.get("logprob_token_ids") and not data.get("logprobs"): - raise ValueError( - "when using `logprob_token_ids`, `logprobs` must be set to true." + raise VLLMValidationError( + "when using `logprob_token_ids`, `logprobs` must be set to true.", + parameter="logprob_token_ids", ) response_format = data.get("response_format") rf_type = ( @@ -1095,8 +1098,10 @@ class BatchChatCompletionRequest(OpenAIBaseModel): validate_structured_outputs_structural_tag(structured_outputs) n = data.get("n", 1) if n is not None and n != 1: - raise ValueError( - "Batch chat completions do not support `n > 1`. Please set `n` to 1." + raise VLLMValidationError( + "Batch chat completions do not support `n > 1`. Please set `n` to 1.", + parameter="n", + value=n, ) return data