[Bugfix] Accept logprobs=-1 in the Completion API (#46175)

Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>

Yufeng He committed Aug 18, 2026 at 16:22 UTC 5c9ff5366b039a69b344773bdfead8466ed9a097
2 files changed +30 -2
tests/entrypoints/openai/completion/test_completion_error.py
+24
@@ -476,6 +476,30 @@ def test_negative_prompt_token_ids_flat():
476 )
477
478
479 +def test_logprobs_minus_one_allowed():
480 + """logprobs=-1 means "return all logprobs". The sampling layer and the chat
481 + top_logprobs / prompt_logprobs validators all accept -1, so the completion
482 + logprobs validator must accept it too instead of rejecting it as negative."""
483 + request = CompletionRequest(
484 + model=MODEL_NAME,
485 + prompt="Test prompt",
486 + max_tokens=10,
487 + logprobs=-1,
488 + )
489 + assert request.logprobs == -1
490 +
491 +
492 +def test_logprobs_below_minus_one_rejected():
493 + """Values more negative than -1 stay invalid."""
494 + with pytest.raises(Exception, match="must be a positive value or -1"):
495 + CompletionRequest(
496 + model=MODEL_NAME,
497 + prompt="Test prompt",
498 + max_tokens=10,
499 + logprobs=-2,
500 + )
501 +
502 +
503 class TestCompletionPromptListLimit:
504 """Regression tests for CVE: unbounded prompt list fan-out."""
505
vllm/entrypoints/openai/completion/protocol.py
+6 -2
@@ -526,9 +526,13 @@ class CompletionRequest(OpenAIBaseModel):
526 parameter="prompt_logprobs",
527 value=prompt_logprobs,
528 )
529 - if (logprobs := data.get("logprobs")) is not None and logprobs < 0:
529 + if (
530 + (logprobs := data.get("logprobs")) is not None
531 + and logprobs < 0
532 + and logprobs != -1
533 + ):
534 raise VLLMValidationError(
531 - "`logprobs` must be a positive value.",
535 + "`logprobs` must be a positive value or -1.",
536 parameter="logprobs",
537 value=logprobs,
538 )