From 35c1ee3d587cb983b9bb26bbbef7cfd82484c757 Mon Sep 17 00:00:00 2001 From: EugenYushin Date: Fri, 17 Apr 2026 15:29:56 +0400 Subject: [PATCH 1/2] add unit test with repro --- .../tools/test_from_function_with_options.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/unittests/tools/test_from_function_with_options.py b/tests/unittests/tools/test_from_function_with_options.py index 537094da39..6c20b62724 100644 --- a/tests/unittests/tools/test_from_function_with_options.py +++ b/tests/unittests/tools/test_from_function_with_options.py @@ -361,3 +361,29 @@ def complex_tool( ), }, ) + + +def test_sanitized_in_json_schema_fallback(): + """Test schema is sanitzed for complex union type.""" + + def complex_tool( + query: str, + mode: str = 'default', + tags: dict[str, str] | None = None, + ) -> str: + return query + + declaration = _automatic_function_calling_util.from_function_with_options( + complex_tool, GoogleLLMVariant.GEMINI_API + ) + + assert declaration.parameters.properties['tags'] == types.Schema( + any_of=[ + types.Schema( + # should not contain `additional_properties={'type': 'string'} from pydantic + type=types.Type.OBJECT, + ), + types.Schema(type=types.Type.NULL), + ], + nullable=True, + ) From 82b6abc2777b77df4680f60b32ba882433c816c9 Mon Sep 17 00:00:00 2001 From: EugenYushin Date: Fri, 17 Apr 2026 15:33:03 +0400 Subject: [PATCH 2/2] sanitize schema in fallback call --- src/google/adk/tools/_automatic_function_calling_util.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/google/adk/tools/_automatic_function_calling_util.py b/src/google/adk/tools/_automatic_function_calling_util.py index aef4424a49..0ad0c90a87 100644 --- a/src/google/adk/tools/_automatic_function_calling_util.py +++ b/src/google/adk/tools/_automatic_function_calling_util.py @@ -37,6 +37,7 @@ from ..features import FeatureName from ..features import is_feature_enabled from ..utils.variant_utils import GoogleLLMVariant +from ._gemini_schema_util import _sanitize_schema_formats_for_gemini _py_type_2_schema_type = { 'str': types.Type.STRING, @@ -366,7 +367,7 @@ def from_function_with_options( ) parameters_json_schema[name] = types.Schema.model_validate( - json_schema_dict + _sanitize_schema_formats_for_gemini(json_schema_dict) ) if param.default is not inspect.Parameter.empty: if param.default is not None: