fix(parser): safely handle non-string inputs in has_a2ui_parts#1941
Open
janandrzejnowakowski wants to merge 3 commits into
Open
fix(parser): safely handle non-string inputs in has_a2ui_parts#1941janandrzejnowakowski wants to merge 3 commits into
janandrzejnowakowski wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
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.
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>
Signed-off-by: janandrzejnowakowski <39009594+janandrzejnowakowski@users.noreply.github.com>
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.
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!