Skip to content

Conversation

@ishanrajsingh
Copy link

This fix addresses an issue in the LiteLlm integration where setting include_contents='none' causes the content payload sent to the LLM provider to be empty, resulting in a BadRequestError.

Changes

  • Added fallback user message in generate_content_async when messages list is empty
  • Uses same fallback text as BaseLlm._maybe_append_user_content for consistency
  • Added comprehensive integration tests with real dict responses for proper serialization testing

Testing

  • All 6 tests pass successfully (3 test functions × 2 backends: GOOGLE_AI and VERTEX)
  • Tests verify empty content handling with and without tools
  • Tests use actual dict responses instead of MagicMock for proper payload testing

Related Issue

Fixes #3242

…content and add tests

- Add fallback user message when messages list is empty due to include_contents='none'
- Use same fallback text as BaseLlm._maybe_append_user_content for consistency
- Add comprehensive tests covering empty contents scenarios with and without tools
- Use actual dict responses in tests for proper serialization testing
- Fixes google#3242
@gemini-code-assist
Copy link

Summary of Changes

Hello @ishanrajsingh, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical issue within the LiteLlm integration where an empty content payload, often triggered by include_contents='none', would lead to a BadRequestError. The solution introduces a robust fallback mechanism that inserts a default user message when no content is provided, ensuring that API calls to LLM providers are always valid. This enhancement significantly improves the stability and error handling of the LiteLlm model, particularly in scenarios where content generation might be implicitly handled or optional.

Highlights

  • Bug Fix for Empty Content: Addresses a BadRequestError in LiteLlm when include_contents='none' results in an empty content payload, ensuring robust handling of such scenarios.
  • Fallback User Message Implementation: Introduces a fallback user message in generate_content_async for cases where the messages list is empty, maintaining consistency with BaseLlm._maybe_append_user_content.
  • Enhanced Integration Testing: Adds comprehensive integration tests that utilize real dictionary responses to thoroughly validate serialization and the correct handling of empty content, both with and without tools.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@adk-bot adk-bot added the models [Component] Issues related to model support label Oct 28, 2025
Copy link

@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 successfully addresses a BadRequestError in the LiteLlm integration when include_contents='none' by adding a fallback user message. The change is accompanied by a comprehensive new test suite that validates the fix for various scenarios, including with and without tools, which is excellent. My review includes a comment on a potential logic redundancy in the implementation and suggestions to improve conciseness in the new tests.

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

Labels

models [Component] Issues related to model support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LiteLlm + include_contents="none" results in empty content sent to the provider -> Error

2 participants