[Frontend][Core] Standardize request error handling with VLLMError hierarchy (#49665)

Signed-off-by: Zach Zhu <zzqshu@126.com>
This commit is contained in:
Zach Zhu
2026-07-29 04:20:40 +00:00
committed by GitHub
parent f37f03db4a
commit 58f9659397
46 changed files with 370 additions and 248 deletions
@@ -4,6 +4,7 @@
import pytest
from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionRequest
from vllm.exceptions import VLLMValidationError
def test_chat_completion_request_with_no_tools():
@@ -27,7 +28,7 @@ def test_chat_completion_request_with_no_tools():
assert request.tool_choice == "none"
# tools key present but empty -- should be rejected
with pytest.raises(ValueError, match="must not be an empty array"):
with pytest.raises(VLLMValidationError, match="must not be an empty array"):
ChatCompletionRequest.model_validate(
{
"messages": [{"role": "user", "content": "Hello"}],
@@ -40,7 +41,7 @@ def test_chat_completion_request_with_no_tools():
@pytest.mark.parametrize("tool_choice", ["auto", "required"])
def test_chat_completion_request_with_tool_choice_but_no_tools(tool_choice):
with pytest.raises(
ValueError, match="When using `tool_choice`, `tools` must be set."
VLLMValidationError, match="When using `tool_choice`, `tools` must be set."
):
ChatCompletionRequest.model_validate(
{
@@ -51,7 +52,7 @@ def test_chat_completion_request_with_tool_choice_but_no_tools(tool_choice):
)
with pytest.raises(
ValueError, match="When using `tool_choice`, `tools` must be set."
VLLMValidationError, match="When using `tool_choice`, `tools` must be set."
):
ChatCompletionRequest.model_validate(
{
@@ -134,7 +135,7 @@ SAMPLE_TOOL = {
def test_structured_outputs_with_named_tool_choice_rejected():
"""structured_outputs cannot be combined with a named tool_choice."""
with pytest.raises(
ValueError,
VLLMValidationError,
match="structured outputs or tools, not both",
):
ChatCompletionRequest.model_validate(
@@ -168,7 +169,7 @@ def test_structured_outputs_with_auto_tool_choice_allowed():
def test_multiple_structured_outputs_rejected():
"""Only one kind of structured output constraint is allowed."""
with pytest.raises(
ValueError,
VLLMValidationError,
match="You can only use one kind of constraints",
):
ChatCompletionRequest.model_validate(
@@ -2,12 +2,12 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import pytest
from pydantic import ValidationError
from vllm.entrypoints.openai.responses.protocol import (
ResponsesRequest,
ResponsesResponse,
)
from vllm.exceptions import VLLMValidationError
SAMPLE_TOOL = {
"type": "function",
@@ -58,13 +58,13 @@ def test_responses_request_required_without_tools(tools):
if tools is not None:
kwargs["tools"] = tools
with pytest.raises(
ValidationError, match="Tool choice 'required' must be specified"
VLLMValidationError, match="Tool choice 'required' must be specified"
):
ResponsesRequest.model_validate(kwargs)
def test_responses_request_named_tool_choice_without_tools():
with pytest.raises(ValidationError, match="not found in 'tools' parameter"):
with pytest.raises(VLLMValidationError, match="not found in 'tools' parameter"):
ResponsesRequest.model_validate(
{
"input": "Hello",
@@ -107,7 +107,7 @@ def test_responses_request_named_tool_choice_matching():
def test_responses_request_named_tool_choice_not_matching():
with pytest.raises(ValidationError, match="not found in 'tools' parameter"):
with pytest.raises(VLLMValidationError, match="not found in 'tools' parameter"):
ResponsesRequest.model_validate(
{
"input": "Hello",
@@ -164,7 +164,7 @@ def test_responses_request_empty_tools_tool_choice_auto():
],
)
def test_responses_request_named_tool_choice_missing_name(tool_choice):
with pytest.raises(ValidationError, match="not found in 'tools' parameter"):
with pytest.raises(VLLMValidationError, match="not found in 'tools' parameter"):
ResponsesRequest.model_validate(
{
"input": "Hello",
@@ -176,7 +176,7 @@ def test_responses_request_named_tool_choice_missing_name(tool_choice):
def test_responses_request_empty_tools_named_tool_choice():
with pytest.raises(ValidationError, match="not found in 'tools' parameter"):
with pytest.raises(VLLMValidationError, match="not found in 'tools' parameter"):
ResponsesRequest.model_validate(
{
"input": "Hello",