Skip to content

fix: avoid UserWarning in _build_response_log when response has funct…#6127

Closed
AdeevMardia2008 wants to merge 2 commits into
google:mainfrom
AdeevMardia2008:fix/response-log-text-warning
Closed

fix: avoid UserWarning in _build_response_log when response has funct…#6127
AdeevMardia2008 wants to merge 2 commits into
google:mainfrom
AdeevMardia2008:fix/response-log-text-warning

Conversation

@AdeevMardia2008

Copy link
Copy Markdown
Contributor

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:

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:

# 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

@google-cla

google-cla Bot commented Jun 15, 2026

Copy link
Copy Markdown

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.

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
@adk-bot

adk-bot commented Jun 17, 2026

Copy link
Copy Markdown
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.

@adk-bot adk-bot added the merged [Status] This PR is merged label Jun 17, 2026
@adk-bot adk-bot closed this Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged [Status] This PR is merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adk Function Call Warning

5 participants