Skip to content

fix(anthropic): handle plain string in part_to_message_block#5571

Open
AliMuhammadAslam wants to merge 1 commit intogoogle:mainfrom
AliMuhammadAslam:main
Open

fix(anthropic): handle plain string in part_to_message_block#5571
AliMuhammadAslam wants to merge 1 commit intogoogle:mainfrom
AliMuhammadAslam:main

Conversation

@AliMuhammadAslam
Copy link
Copy Markdown

@AliMuhammadAslam AliMuhammadAslam commented May 1, 2026

Problem

part_to_message_block() in anthropic_llm.py iterates over response_data["content"] without checking whether the value is a list or a plain string. When a tool returns a response where content is a string, the loop yields one character per iteration, so the assembled result is individual characters joined by newlines instead of the full text.

LoadSkillResourceTool is a concrete example: it returns {"skill_name": ..., "file_path": ..., "content": "<file text>"} where content is a string, not a list.

Closes #5358

Fix

Added an isinstance(response_data["content"], str) check before the loop. When content is a string it is passed through directly. When it is a list, the existing item-by-item join logic runs as before.

Testing

Added test_part_to_message_block_with_string_content to tests/unittests/models/test_anthropic_llm.py. The test creates a function response matching the LoadSkillResourceTool shape and asserts the full string comes through unchanged.

All existing part_to_message_block tests continue to pass.

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 1, 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 services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc label May 1, 2026
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented May 1, 2026

Response from ADK Triaging Agent

Hello @AliMuhammadAslam, thank you for your contribution!

Before we can merge this PR, you need to sign the Contributor License Agreement (CLA). It seems that the CLA check has failed.

For more details, please review our contribution guidelines.

Thank you!

@AliMuhammadAslam
Copy link
Copy Markdown
Author

I have signed the CLA.

@AliMuhammadAslam AliMuhammadAslam changed the title fix(code_executors): handle genai.ClientError 404 in sandbox recovery fix(anthropic): handle plain string in part_to_message_block May 2, 2026
@adk-bot adk-bot added the models [Component] Issues related to model support label May 2, 2026
When a tool returns a response where the "content" key holds a plain
string, part_to_message_block() was iterating over it directly. Since
strings are iterable in Python, the loop produced one character per
iteration instead of the full text.

LoadSkillResourceTool is a concrete case: it returns a response dict
with a "content" key that is a string, not a list.

The fix adds an isinstance check before the loop. When content is a
string it is used directly. When it is a list, the existing join
logic runs unchanged. A unit test covers both paths.

Fixes google#5358
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

models [Component] Issues related to model support services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AnthropicLlm.part_to_message_block() iterates "content" string char-by-character when LoadSkillResourceTool is used with Claude

2 participants