Skip to content

fix(parser): safely handle non-string inputs in has_a2ui_parts#1941

Open
janandrzejnowakowski wants to merge 3 commits into
a2ui-project:mainfrom
janandrzejnowakowski:fix-has-a2ui-parts-type-check
Open

fix(parser): safely handle non-string inputs in has_a2ui_parts#1941
janandrzejnowakowski wants to merge 3 commits into
a2ui-project:mainfrom
janandrzejnowakowski:fix-has-a2ui-parts-type-check

Conversation

@janandrzejnowakowski

Copy link
Copy Markdown

Summary
Guards has_a2ui_parts against non-string inputs so that inspecting arbitrary tool/function responses (e.g., integers, dicts, booleans, or None) does not raise a TypeError.

Root Cause & Error
When an agent or tool emits a FunctionResponse part whose result is a non-string data type (such as an integer return value like {"result": 6}), passing that value into has_a2ui_parts(content) raises:

Traceback (most recent call last):
File ".../a2ui_agent/src/a2ui/adk/a2a/part_converter.py", line 120, in convert
if has_a2ui_parts(result):
File ".../a2ui_agent/src/a2ui/parser/parser.py", line 30, in has_a2ui_parts
return A2UI_OPEN_TAG in content and A2UI_CLOSE_TAG in content
TypeError: argument of type 'int' is not iterable

Fix
Updated has_a2ui_parts(content: Any) -> bool to return False early if content is not a string (if not isinstance(content, str): return False).
Added unit test coverage for string, integer, dictionary, and None inputs in test_parser.py.

jnowakowski@noj:~/src/A2UI/scripts$ ./e2e_test.sh
...
01:42 +4: All tests passed!

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 updates the has_a2ui_parts function to accept any input type, returning False if the input is not a string, and adds comprehensive unit tests for this behavior. The review feedback correctly points out an unused pytest import in the new test file, which should be removed.

Comment thread agent_sdks/python/a2ui_agent/tests/parser/test_parser.py Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: janandrzejnowakowski <39009594+janandrzejnowakowski@users.noreply.github.com>
@github-actions github-actions Bot added the status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs label Jul 8, 2026
Signed-off-by: janandrzejnowakowski <39009594+janandrzejnowakowski@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant