fix(openai): reject non-numeric logprobs with 400 instead of 500 (#49144)

Signed-off-by: Chenglun Hu <chenglunhu@gmail.com>
This commit is contained in:
hcl
2026-07-20 10:04:50 +00:00
committed by GitHub
parent d835ad572c
commit 530ee36a0d
4 changed files with 49 additions and 0 deletions
@@ -468,6 +468,18 @@ class CompletionRequest(OpenAIBaseModel):
parameter="logprob_token_ids",
)
# These fields are integers, but `mode="before"` runs on the raw
# request data, so a non-numeric value (e.g. a JSON string) would
# reach the comparisons below and raise TypeError -> HTTP 500. Reject
# it here so the client gets a clean 400 instead.
for field_name in ("prompt_logprobs", "logprobs"):
field_value = data.get(field_name)
if field_value is not None and not isinstance(field_value, (int, float)):
raise VLLMValidationError(
f"`{field_name}` must be an integer.",
parameter=field_name,
value=field_value,
)
if (prompt_logprobs := data.get("prompt_logprobs")) is not None:
if data.get("stream") and (prompt_logprobs > 0 or prompt_logprobs == -1):
raise VLLMValidationError(