From b3f97dae24a8d73535feca70b1c75cf6db4737e1 Mon Sep 17 00:00:00 2001 From: Cyrus Leung Date: Mon, 3 Aug 2026 14:51:27 +0800 Subject: [PATCH] [Frontend] Require cache_salt to be non-empty via schema (#50816) Signed-off-by: DarkLight1337 --- .../openai/chat_completion/protocol.py | 13 +------------ vllm/entrypoints/openai/completion/protocol.py | 13 +------------ vllm/entrypoints/openai/responses/protocol.py | 13 +------------ vllm/entrypoints/pooling/base/protocol.py | 15 --------------- .../scale_out/token_in_token_out/protocol.py | 1 + 5 files changed, 4 insertions(+), 51 deletions(-) diff --git a/vllm/entrypoints/openai/chat_completion/protocol.py b/vllm/entrypoints/openai/chat_completion/protocol.py index 1cdfd2f698f..fc3b8103bc1 100644 --- a/vllm/entrypoints/openai/chat_completion/protocol.py +++ b/vllm/entrypoints/openai/chat_completion/protocol.py @@ -452,6 +452,7 @@ class ChatCompletionRequest(OpenAIBaseModel): cache_salt: str | None = Field( default=None, + min_length=1, description=( "If specified, the prefix cache will be salted with the provided " "string to prevent an attacker to guess prompts in multi-user " @@ -968,18 +969,6 @@ class ChatCompletionRequest(OpenAIBaseModel): ) return data - @model_validator(mode="before") - @classmethod - def check_cache_salt_support(cls, data): - if data.get("cache_salt") is not None and ( - not isinstance(data["cache_salt"], str) or not data["cache_salt"] - ): - raise VLLMValidationError( - "Parameter 'cache_salt' must be a non-empty string if provided.", - parameter="cache_salt", - ) - return data - @model_validator(mode="before") @classmethod def check_system_message_content_type(cls, data): diff --git a/vllm/entrypoints/openai/completion/protocol.py b/vllm/entrypoints/openai/completion/protocol.py index 79ad9799e18..31c35b5bcce 100644 --- a/vllm/entrypoints/openai/completion/protocol.py +++ b/vllm/entrypoints/openai/completion/protocol.py @@ -184,6 +184,7 @@ class CompletionRequest(OpenAIBaseModel): cache_salt: str | None = Field( default=None, + min_length=1, description=( "If specified, the prefix cache will be salted with the provided " "string to prevent an attacker to guess prompts in multi-user " @@ -575,18 +576,6 @@ class CompletionRequest(OpenAIBaseModel): return data - @model_validator(mode="before") - @classmethod - def check_cache_salt_support(cls, data): - if data.get("cache_salt") is not None and ( - not isinstance(data["cache_salt"], str) or not data["cache_salt"] - ): - raise VLLMValidationError( - "Parameter 'cache_salt' must be a non-empty string if provided.", - parameter="cache_salt", - ) - return data - class CompletionLogProbs(OpenAIBaseModel): text_offset: list[int] = Field(default_factory=list) diff --git a/vllm/entrypoints/openai/responses/protocol.py b/vllm/entrypoints/openai/responses/protocol.py index ad92766cb7b..c739ffe25c3 100644 --- a/vllm/entrypoints/openai/responses/protocol.py +++ b/vllm/entrypoints/openai/responses/protocol.py @@ -243,6 +243,7 @@ class ResponsesRequest(OpenAIBaseModel): ) cache_salt: str | None = Field( default=None, + min_length=1, description=( "If specified, the prefix cache will be salted with the provided " "string to prevent an attacker to guess prompts in multi-user " @@ -476,18 +477,6 @@ class ResponsesRequest(OpenAIBaseModel): ) return data - @model_validator(mode="before") - @classmethod - def check_cache_salt_support(cls, data): - if data.get("cache_salt") is not None and ( - not isinstance(data["cache_salt"], str) or not data["cache_salt"] - ): - raise VLLMValidationError( - "Parameter 'cache_salt' must be a non-empty string if provided.", - parameter="cache_salt", - ) - return data - @model_validator(mode="before") @classmethod def input_item_parsing(cls, data): diff --git a/vllm/entrypoints/pooling/base/protocol.py b/vllm/entrypoints/pooling/base/protocol.py index c0fff022d26..fcc7c24b28c 100644 --- a/vllm/entrypoints/pooling/base/protocol.py +++ b/vllm/entrypoints/pooling/base/protocol.py @@ -82,21 +82,6 @@ class PoolingBasicRequestMixin(OpenAIBaseModel): ) # --8<-- [end:pooling-common-extra-params] - @model_validator(mode="before") - @classmethod - def check_cache_salt_support(cls, data): - if not isinstance(data, dict): - return data - - if data.get("cache_salt") is not None and ( - not isinstance(data["cache_salt"], str) or not data["cache_salt"] - ): - raise VLLMValidationError( - "Parameter 'cache_salt' must be a non-empty string if provided.", - parameter="cache_salt", - ) - return data - def _build_pooling_tok_params( self, model_config: ModelConfig, diff --git a/vllm/entrypoints/scale_out/token_in_token_out/protocol.py b/vllm/entrypoints/scale_out/token_in_token_out/protocol.py index 8dad837613d..86c0a8c8b17 100644 --- a/vllm/entrypoints/scale_out/token_in_token_out/protocol.py +++ b/vllm/entrypoints/scale_out/token_in_token_out/protocol.py @@ -113,6 +113,7 @@ class GenerateRequest(BaseModel): stream_options: StreamOptions | None = None cache_salt: str | None = Field( default=None, + min_length=1, description=( "If specified, the prefix cache will be salted with the provided " "string to prevent an attacker to guess prompts in multi-user "