-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(LiteLlm): add fallback user message to prevent empty content error with include_contents='none' #3255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(LiteLlm): add fallback user message to prevent empty content error with include_contents='none' #3255
Conversation
...messages empty due to include_contents='none'
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
Response from ADK Triaging Agent
Hello @ishanrajsingh, thank you for creating this PR!
To help reviewers to review your PR more efficiently, could you please provide the followings:
- a Github issue associated with this PR. If there is no existing issue, could you please create one?
- a testing plan for your changes.
- logs or screenshot after the fix is applied.
Thanks!
@gemini-code-assist
gemini-code-assist
bot
left a comment
There was a problem hiding this 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 addresses an issue where the LiteLlm integration would error when include_contents='none' due to an empty content payload. The fix adds a fallback user message to ensure a non-empty content array is always sent to the LLM provider. I have identified a potential issue with the placement of the fallback logic that could lead to unexpected behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handle empty file content
GitHub Issue:
This PR addresses the bug reported in issue #3242 titled "LiteLlm + include_contents='none' results in empty content sent to the provider -> Error". The issue is already created and linked here: #3242
Testing Plan:
I verified the fix by running a scenario where an LlmAgent uses LiteLlm with include_contents='none'.
The test confirms that the LLM request no longer sends empty content, preventing the BadRequestError from the LLM provider.
Additionally, I ran existing LiteLlm unit tests to ensure no regressions occur.
For thoroughness, a new test can be added simulating include_contents='none' to confirm fallback content insertion.
/gemini review
@gemini-code-assist
gemini-code-assist
bot
left a comment
There was a problem hiding this 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 addresses a critical issue where the LiteLlm integration fails when include_contents='none' due to an empty content payload. The fix introduces a fallback user message to ensure a non-empty content array is always sent to the LLM provider. I have added a review comment to suggest a minor improvement to the fallback message.
...messages empty due to include_contents='none'
/gemini review
@gemini-code-assist
gemini-code-assist
bot
left a comment
There was a problem hiding this 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 addresses a critical issue where LiteLlm integration with include_contents='none' results in an empty content payload, causing a BadRequestError. The fix introduces a fallback user message when no messages are included, ensuring a non-empty content array is always sent. This review focuses on the correctness and maintainability of the implemented solution, ensuring it effectively prevents the error and adheres to best practices.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Hi thank you for the contribution!
Two comments
- Can you close the ChatCompletionUserMessage( and create tests to show this change working
- Instead of truncating the entire system instruction (and duplicating it as user content), can you look at reusing the fallback text inserted by _maybe_append_user_content. That keeps behavior aligned with the Gemini path and stops us from slicing instructions midsentence.
...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 - Fixes google#3242
Thank you @GWeale for the feedback! I've updated the PR to address both points:
-
✅ Aligned fallback content with
BaseLlm._maybe_append_user_content: The fix now uses the exact same fallback text ("Handle the requests as specified in the System Instruction.") as the base class, keeping behavior consistent with the Gemini path. -
✅ Added comprehensive tests: Created tests that demonstrate the fix works correctly:
test_include_contents_none_with_fallback: Verifies empty contents are handled gracefullytest_include_contents_none_with_tools: Confirms the fix works with function declarationstest_include_contents_with_existing_content: Ensures normal operation is unaffected
All tests pass successfully (6/6). The fix ensures that when include_contents='none' is used with LiteLlm, a minimal fallback user message is added to prevent the "contents is not specified" error from the LLM provider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
align fallback content with BaseLlm._maybe_append_user_content and add tests
Uh oh!
There was an error while loading. Please reload this page.
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. The patch adds a minimal fallback user message in the generate_content_async method when no messages are included, ensuring a non-empty content array is always sent. This prevents errors from providers that require non-empty input and improves compatibility when using LiteLlm with the Agent Development Kit.
GitHub Issue:
This PR addresses the bug reported in issue #3242 titled "LiteLlm + include_contents='none' results in empty content sent to the provider -> Error". The issue is already created and linked here: #3242
Testing Plan:
I verified the fix by running a scenario where an LlmAgent uses LiteLlm with include_contents='none'.
The test confirms that the LLM request no longer sends empty content, preventing the BadRequestError from the LLM provider.
Additionally, I ran existing LiteLlm unit tests to ensure no regressions occur.
For thoroughness, a new test can be added simulating include_contents='none' to confirm fallback content insertion.