Skip to content

[Misc] Use VLLMValidationError consistently in completion and chat completion protocol#35666

Closed
umut-polat wants to merge 1 commit intovllm-project:mainfrom
umut-polat:fix/completion-protocol-validation-errors
Closed

[Misc] Use VLLMValidationError consistently in completion and chat completion protocol#35666
umut-polat wants to merge 1 commit intovllm-project:mainfrom
umut-polat:fix/completion-protocol-validation-errors

Conversation

@umut-polat
Copy link
Copy Markdown
Contributor

Purpose

Replace remaining ValueError raises with VLLMValidationError in the
model validators for CompletionRequest and ChatCompletionRequest.

This follows the same pattern established in the responses protocol and
SamplingParams, where VLLMValidationError provides structured error
context (parameter, value) for better client-side error handling.

Changes

vllm/entrypoints/openai/completion/protocol.py

  • validate_prompt_and_prompt_embeds: ValueError → VLLMValidationError
  • check_cache_salt_support: ValueError → VLLMValidationError (with parameter/value)

vllm/entrypoints/openai/chat_completion/protocol.py

  • check_structured_outputs_count: 2× ValueError → VLLMValidationError
  • check_tool_usage: 6× ValueError → VLLMValidationError (with parameter/value)
  • check_generation_prompt: ValueError → VLLMValidationError
  • check_cache_salt_support: ValueError → VLLMValidationError (with parameter/value)

Test Plan

Existing tests cover these validators. The change only affects the
exception type raised (VLLMValidationError extends ValueError), so all
existing error handling continues to work.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request does a good job of consistently using VLLMValidationError instead of ValueError for request validation, which improves error reporting for clients. I've identified a couple of instances where the new validation errors could be made even more informative by including the parameter argument, aligning them more closely with the other changes in this PR. My suggestions aim to enhance this consistency.

Comment on lines +720 to 723
raise VLLMValidationError(
"Cannot set both `continue_final_message` "
"and `add_generation_prompt` to True.",
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

For consistency with the other changes in this PR, it would be better to specify which parameter is causing the validation error. Since this is a conflict between two parameters, you can pick one to report. add_generation_prompt seems like a reasonable choice.

Suggested change
raise VLLMValidationError(
"Cannot set both `continue_final_message` "
"and `add_generation_prompt` to True.",
)
raise VLLMValidationError(
"Cannot set both `continue_final_message` "
"and `add_generation_prompt` to True.",
parameter="add_generation_prompt",
)

Comment on lines +418 to 421
raise VLLMValidationError(
"Either prompt or prompt_embeds must be "
"provided and non-empty.",
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

For consistency with the goal of this PR to provide structured error context, it's a good idea to include the parameter that failed validation. In this case, since either prompt or prompt_embeds is required, you can specify prompt as the parameter.

Suggested change
raise VLLMValidationError(
"Either prompt or prompt_embeds must be "
"provided and non-empty.",
)
raise VLLMValidationError(
"Either prompt or prompt_embeds must be "
"provided and non-empty.",
parameter="prompt",
)

@mergify
Copy link
Copy Markdown

mergify bot commented Mar 1, 2026

Hi @umut-polat, the pre-commit checks have failed. Please run:

uv pip install pre-commit
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Tip

Is mypy or markdownlint failing?
mypy and markdownlint are run differently in CI. If the failure is related to either of these checks, please use the following commands to run them locally:
# For mypy (substitute "3.10" with the failing version if needed)
pre-commit run --hook-stage manual mypy-3.10
# For markdownlint
pre-commit run --hook-stage manual markdownlint

@umut-polat umut-polat force-pushed the fix/completion-protocol-validation-errors branch from 04f6ac4 to 0aaa659 Compare March 1, 2026 16:41
@robertgshaw2-redhat
Copy link
Copy Markdown
Collaborator

how does this change impact user-facing status codes/

@umut-polat
Copy link
Copy Markdown
Contributor Author

No change in status codes — ValueError and VLLMValidationError both return 400 already (create_error_response handles both as BadRequestError). The actual difference is the param field in the JSON error body: VLLMValidationError populates it (e.g. "param": "max_tokens"), plain ValueError leaves it null. So clients get better diagnostics without any breaking change.

…lidators

replace remaining ValueError raises with VLLMValidationError in
model validators for CompletionRequest and ChatCompletionRequest,
consistent with the pattern established in the responses protocol.

Signed-off-by: umut-polat <52835619+umut-polat@users.noreply.github.com>
@umut-polat umut-polat force-pushed the fix/completion-protocol-validation-errors branch from b6b799a to 29f4aa8 Compare March 17, 2026 18:00
raise ValueError("When using `tool_choice`, `tools` must be set.")
raise VLLMValidationError(
"When using `tool_choice`, `tools` must be set.",
parameter="tool_choice",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter here should be tools

Copy link
Copy Markdown
Member

@DarkLight1337 DarkLight1337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this PR looks like a duplicate of #36254

@umut-polat
Copy link
Copy Markdown
Contributor Author

closing in favor of #36254 which covers the same files. will rebase that one if needed.

@umut-polat umut-polat closed this Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants