Skip to content

Commit ce8315a

Browse files
fix(models): avoid spurious UserWarning on tool-call responses in _build_response_log
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 342b59d commit ce8315a

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/google/adk/models/google_llm.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,15 @@ def _build_request_log(req: LlmRequest) -> str:
605605
"""
606606

607607

608+
def _safe_response_text(resp: types.GenerateContentResponse) -> str:
609+
"""Extracts text from a response without triggering UserWarning on tool-call responses."""
610+
try:
611+
parts = resp.candidates[0].content.parts
612+
except (AttributeError, IndexError, TypeError):
613+
return ''
614+
return ''.join(part.text for part in parts if part.text is not None)
615+
616+
608617
def _build_response_log(resp: types.GenerateContentResponse) -> str:
609618
function_calls_text = []
610619
if function_calls := resp.function_calls:
@@ -616,7 +625,7 @@ def _build_response_log(resp: types.GenerateContentResponse) -> str:
616625
LLM Response:
617626
-----------------------------------------------------------
618627
Text:
619-
{resp.text}
628+
{_safe_response_text(resp)}
620629
-----------------------------------------------------------
621630
Function calls:
622631
{_NEW_LINE.join(function_calls_text)}

0 commit comments

Comments
 (0)