A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 10, 11:30 UTC
[Frontend] Improve error message (#31987)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
Cyrus Leung committed
Jan 9, 2026 at 04:07 UTC
aa125ecf0edb9cd67656553d11d643aeb444ff9e
3 files changed
+20
-4
tests/entrypoints/test_utils.py
new
+10
@@ -0,0 +1,10 @@
1
+# SPDX-License-Identifier: Apache-2.0
2
+# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
+from vllm.entrypoints.utils import sanitize_message
4
+
5
+
6
+def test_sanitize_message():
7
+ assert (
8
+ sanitize_message("<_io.BytesIO object at 0x7a95e299e750>")
9
+ == "<_io.BytesIO object>"
10
+ )
vllm/entrypoints/openai/api_server.py
+4
-4
@@ -88,8 +88,10 @@ from vllm.entrypoints.utils import (
88
log_non_default_args,
89
process_chat_template,
90
process_lora_modules,
91
+ sanitize_message,
92
with_cancellation,
93
)
94
+from vllm.exceptions import VLLMValidationError
95
from vllm.logger import init_logger
96
from vllm.reasoning import ReasoningParserManager
97
from vllm.tasks import POOLING_TASKS
@@ -902,7 +904,7 @@ def build_app(args: Namespace) -> FastAPI:
904
async def http_exception_handler(_: Request, exc: HTTPException):
905
err = ErrorResponse(
906
error=ErrorInfo(
905
- message=exc.detail,
907
+ message=sanitize_message(exc.detail),
908
type=HTTPStatus(exc.status_code).phrase,
909
code=exc.status_code,
910
)
@@ -911,8 +913,6 @@ def build_app(args: Namespace) -> FastAPI:
913
914
@app.exception_handler(RequestValidationError)
915
async def validation_exception_handler(_: Request, exc: RequestValidationError):
914
- from vllm.exceptions import VLLMValidationError
915
-
916
param = None
917
for error in exc.errors():
918
if "ctx" in error and "error" in error["ctx"]:
@@ -931,7 +931,7 @@ def build_app(args: Namespace) -> FastAPI:
931
932
err = ErrorResponse(
933
error=ErrorInfo(
934
- message=message,
934
+ message=sanitize_message(message),
935
type=HTTPStatus.BAD_REQUEST.phrase,
936
code=HTTPStatus.BAD_REQUEST,
937
param=param,
vllm/entrypoints/utils.py
+6
@@ -9,6 +9,7 @@ from argparse import Namespace
9
from pathlib import Path
10
from typing import Any
11
12
+import regex as re
13
from fastapi import Request
14
from fastapi.responses import JSONResponse, StreamingResponse
15
from starlette.background import BackgroundTask, BackgroundTasks
@@ -317,3 +318,8 @@ async def process_chat_template(
318
model_config.model,
319
)
320
return resolved_chat_template
321
+
322
+
323
+def sanitize_message(message: str) -> str:
324
+ # Avoid leaking memory address from object reprs
325
+ return re.sub(r" at 0x[0-9a-f]+>", ">", message)