Skip to content

fix: suppress UserWarning when logging function_call responses#4689

Open
OiPunk wants to merge 1 commit intogoogle:mainfrom
OiPunk:codex/adk-4685-fix-function-call-warning
Open

fix: suppress UserWarning when logging function_call responses#4689
OiPunk wants to merge 1 commit intogoogle:mainfrom
OiPunk:codex/adk-4685-fix-function-call-warning

Conversation

@OiPunk
Copy link

@OiPunk OiPunk commented Mar 3, 2026

Summary

Fixes #4685

  • _build_response_log() accesses resp.text which triggers a UserWarning from google.genai whenever the response contains non-text parts (e.g. function_call)
  • This warning floods logs on every tool invocation, even though the tool call executes correctly

Changes

  • Added _get_text_from_response() helper that extracts text from response.candidates[0].content.parts directly, bypassing the .text property that emits the warning
  • Updated _build_response_log() to use the new helper

Test plan

  • test_text_only_response — verifies text extraction for normal responses
  • test_function_call_response_no_warning — verifies no warning on function-call-only responses
  • test_mixed_parts_no_warning — verifies text extraction from mixed text+function_call responses
  • test_empty_candidates / test_none_content — edge cases
  • test_function_call_log_no_warning — regression test for Adk Function Call Warning #4685

🤖 Generated with Claude Code

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 addresses an issue where UserWarning messages were flooding logs during tool invocations due to the google.genai library's resp.text property. The core change involves introducing a new helper function to extract text safely from LLM responses, preventing these warnings and significantly cleaning up the logging output, especially in scenarios involving function calls.

Highlights

  • Warning Suppression: Implemented a mechanism to suppress UserWarning messages that were previously triggered when resp.text was accessed from google.genai responses containing non-text parts, such as function_call.
  • New Helper Function: Introduced a new helper function, _get_text_from_response(), which safely extracts text from GenerateContentResponse objects by iterating directly over content parts, thereby bypassing the problematic .text property.
  • Logging Update: Updated the _build_response_log() function to utilize the new _get_text_from_response() helper, ensuring that response logging no longer generates unnecessary warnings during tool invocations.
  • Comprehensive Testing: Added a suite of new unit tests to validate the correct text extraction behavior of _get_text_from_response() across various response types (text-only, function-call-only, mixed parts, empty/none content) and to confirm that _build_response_log() no longer emits warnings for function call responses.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/google/adk/models/google_llm.py
    • Added _get_text_from_response helper function to extract text from GenerateContentResponse without triggering warnings.
    • Modified _build_response_log to use _get_text_from_response for text extraction.
  • tests/unittests/models/test_google_llm.py
    • Imported the warnings module to facilitate warning suppression testing.
    • Imported _build_response_log and _get_text_from_response for testing purposes.
    • Added TestGetTextFromResponse class with tests for text-only, function-call, mixed-part, empty, and None content responses.
    • Added TestBuildResponseLogNoWarning class with a regression test to ensure _build_response_log does not trigger warnings for function calls.
Activity
  • The author has provided a detailed test plan, including specific test cases for text-only responses, function-call responses without warnings, mixed-part responses without warnings, edge cases for empty/none candidates, and a regression test for the original issue.
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.

@google-cla
Copy link

google-cla bot commented Mar 3, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Mar 3, 2026
Copy link
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 effectively addresses the issue of UserWarning messages being logged excessively when function_call responses are encountered. The introduction of the _get_text_from_response helper function provides a clean and robust way to extract text content without triggering these warnings. The accompanying unit tests are comprehensive, covering various scenarios including text-only, function-call-only, mixed content, and edge cases like empty candidates or None content, ensuring the fix is reliable and prevents regressions. The solution is well-implemented and directly resolves the reported problem.

_build_response_log() accessed resp.text on responses containing
function_call parts, triggering a UserWarning from google.genai on
every tool invocation. Extract text from parts directly via a new
_get_text_from_response() helper to avoid the warning.

Fixes google#4685
@OiPunk OiPunk force-pushed the codex/adk-4685-fix-function-call-warning branch from 52a649b to b448fed Compare March 3, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adk Function Call Warning

2 participants