fix: avoid UserWarning in _build_response_log when response has funct…#6127
Closed
AdeevMardia2008 wants to merge 2 commits into
Closed
fix: avoid UserWarning in _build_response_log when response has funct…#6127AdeevMardia2008 wants to merge 2 commits into
AdeevMardia2008 wants to merge 2 commits into
Conversation
|
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. |
5 tasks
3 tasks
copybara-service Bot
pushed a commit
that referenced
this pull request
Jun 17, 2026
Merge #6127 # Fix: `_build_response_log()` triggers genai SDK UserWarning on every tool call Closes #4685 ## What's the problem? Every time an ADK agent invokes a tool, the debug logger calls `_build_response_log(response)`, which includes `resp.text` in its f-string: ```python return f""" LLM Response: ... Text: {resp.text} # ← triggers UserWarning ... """ ``` The `GenerateContentResponse.text` property in the google-genai SDK raises a `UserWarning` whenever the response contains non-text parts — which is exactly the case when the model responds with a `function_call`. This means **every single tool invocation floods the log with warnings** like: ``` UserWarning: Warning: there are non-text parts in the response: ['function_call'],returning concatenated text result from text parts, check `response.parts` directly to inspect non-text parts warnings.warn( ``` Since `_build_response_log` is only called inside `if logger.isEnabledFor(logging.DEBUG)`, this hits any developer who enables debug logging — which is common when debugging agents. ## Root cause `GenerateContentResponse.text` is a convenience property that warns when mixed content is present. Accessing it in a log formatter silently poisons the log output whenever agents use tools. ## Fix Replace `resp.text` with a manual join of only the text parts from `resp.candidates`, bypassing the warning entirely: ```python # Before return f""" ... Text: {resp.text} ... """ # After — safe extraction with no warning text_parts = [] if resp.candidates: for candidate in resp.candidates: if candidate.content and candidate.content.parts: text_parts.extend( p.text for p in candidate.content.parts if p.text is not None ) text = ''.join(text_parts) return f""" ... Text: {text} ... """ ``` This produces identical output when only text parts are present, and correctly shows an empty string (rather than a warning) when the response is a function call — which is the right behavior for a debug log. ## Files changed - `src/google/adk/models/google_llm.py` — 10-line change inside `_build_response_log()`, no other logic touched Co-authored-by: Yifan Wang <wanyif@google.com> COPYBARA_INTEGRATE_REVIEW=#6127 from AdeevMardia2008:fix/response-log-text-warning 011c153 PiperOrigin-RevId: 933440866
Collaborator
|
Thank you @AdeevMardia2008 for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit f022307. Closing this PR as the changes are now in the main branch. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix:
_build_response_log()triggers genai SDK UserWarning on every tool callCloses #4685
What's the problem?
Every time an ADK agent invokes a tool, the debug logger calls
_build_response_log(response), which includesresp.textin its f-string:The
GenerateContentResponse.textproperty in the google-genai SDK raises aUserWarningwhenever the response contains non-text parts — which is exactly the case when the model responds with afunction_call. This means every single tool invocation floods the log with warnings like:Since
_build_response_logis only called insideif logger.isEnabledFor(logging.DEBUG), this hits any developer who enables debug logging — which is common when debugging agents.Root cause
GenerateContentResponse.textis a convenience property that warns when mixed content is present. Accessing it in a log formatter silently poisons the log output whenever agents use tools.Fix
Replace
resp.textwith a manual join of only the text parts fromresp.candidates, bypassing the warning entirely:This produces identical output when only text parts are present, and correctly shows an empty string (rather than a warning) when the response is a function call — which is the right behavior for a debug log.
Files changed
src/google/adk/models/google_llm.py— 10-line change inside_build_response_log(), no other logic touched