Skip to content

Conversation

@heisenberglit
Copy link
Contributor

@heisenberglit heisenberglit commented Jul 23, 2025

Overview:

This PR addresses issue #2064 where the /chat/completions endpoint returns a cryptic internal error when receiving an empty messages array. The fix adds proper validation and returns a clear, user-friendly error message instead.

Details:

Added validation: Check for empty messages array before processing the request
Improved error handling: Return HTTP 400 with descriptive error message instead of internal server error

Where should the reviewer start?

Added a function to validate chat completion required field in llm->http->service->openai.rs

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation for chat completion requests to ensure that required fields are present, returning an error if the messages field is missing or empty.

- Add proper validation for empty messages array
- Return clear error message instead of cryptic internal error
- Fixes ai-dynamo#2064"
@heisenberglit heisenberglit requested a review from a team as a code owner July 23, 2025 07:41
@copy-pr-bot
Copy link

copy-pr-bot bot commented Jul 23, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions
Copy link

👋 Hi heisenberglit! Thank you for contributing to ai-dynamo/dynamo.

Just a reminder: The NVIDIA Test Github Validation CI runs an essential subset of the testing framework to quickly catch errors.Your PR reviewers may elect to test the changes comprehensively before approving your changes.

🚀

@github-actions github-actions bot added the external-contribution Pull request is from an external contributor label Jul 23, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 23, 2025

Walkthrough

A new validation function was introduced to ensure that the messages field in chat completion requests is not empty. This check is performed early in the request handler, and if the field is empty, a 400 Bad Request error is returned. The function is publicly exported for use in the handler.

Changes

File(s) Change Summary
lib/llm/src/http/service/openai.rs Added validate_chat_completion_required_fields function; integrated it into request handling.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Handler
    participant Validator

    Client->>Handler: POST /chat/completions (with request)
    Handler->>Validator: validate_chat_completion_required_fields(request)
    alt messages empty
        Validator-->>Handler: Err (400 Bad Request)
        Handler-->>Client: Respond with error
    else messages present
        Validator-->>Handler: Ok
        Handler->>Handler: Continue processing (template, engine, etc.)
        Handler-->>Client: Respond with completion
    end
Loading

Estimated code review effort

1 (~4 minutes)

Poem

In the warren of code, a new check appears,
No more cryptic errors, just clarity cheers!
If your messages are empty, a Bad Request you’ll see—
The handler now guards, as strict as can be.
🐇✨
Hop along, dear user, with requests that are right,
For clear error messages make debugging light!


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2c642fd and b54fb16.

📒 Files selected for processing (1)
  • lib/llm/src/http/service/openai.rs (2 hunks)
🔇 Additional comments (2)
lib/llm/src/http/service/openai.rs (2)

416-417: LGTM! Well-integrated validation call.

The validation is correctly placed early in the request processing flow, after unsupported field validation but before template application. The error handling follows the established pattern in the codebase.


564-578: Excellent implementation! Addresses the core issue effectively.

The validation function is well-implemented:

  • Clear error message: Replaces the cryptic internal server error with a descriptive HTTP 400 response that clearly explains the problem and requirement
  • Appropriate status code: Uses HTTP 400 Bad Request which is correct for client input validation errors
  • Consistent pattern: Follows the same signature and error handling approach as existing validation functions
  • Focused logic: Simple and targeted check that directly addresses the issue described in the PR objectives

This perfectly solves the problem of unclear error messages when the messages array is empty.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@heisenberglit heisenberglit changed the title Fix cryptic error message for empty messages list in /chat/completions fix: cryptic error message for empty messages list in /chat/completions #2067 Jul 23, 2025
@github-actions github-actions bot added the fix label Jul 23, 2025
@pull-request-size pull-request-size bot added size/M and removed size/S labels Jul 23, 2025
@grahamking grahamking merged commit 6a69ef4 into ai-dynamo:main Jul 23, 2025
10 checks passed
@rmccorm4
Copy link
Contributor

Thanks for the contribution @heisenberglit !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contribution Pull request is from an external contributor fix size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: /chat/completions requests with empty messages list has cryptic error message

3 participants