From 42aa3638ba6e9ce209523d80dcb076cddebb5f44 Mon Sep 17 00:00:00 2001 From: Paul Parkinson Date: Tue, 3 Feb 2026 16:32:37 -0500 Subject: [PATCH] fix(tools): Add type checking for schema parameter in _sanitize_schema_formats_for_gemini Fixes #4363 Added early type checking to handle non-dict schema types (lists and primitives) before attempting to iterate with schema.items(). This prevents AttributeError when the function is called recursively with non-dict types. --- src/google/adk/tools/_gemini_schema_util.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/google/adk/tools/_gemini_schema_util.py b/src/google/adk/tools/_gemini_schema_util.py index 07df5379d8..b193834c4b 100644 --- a/src/google/adk/tools/_gemini_schema_util.py +++ b/src/google/adk/tools/_gemini_schema_util.py @@ -145,6 +145,14 @@ def _sanitize_schema_formats_for_gemini( schema: dict[str, Any], preserve_null_type: bool = False ) -> dict[str, Any]: """Filters the schema to only include fields that are supported by JSONSchema.""" + # Handle non-dict schemas early + if isinstance(schema, list): + # Handle array schemas - pass through + return schema + elif not isinstance(schema, dict): + # Handle primitive types - pass through + return schema + supported_fields: set[str] = set(_ExtendedJSONSchema.model_fields.keys()) # Gemini rejects schemas that include `additionalProperties`, so drop it. supported_fields.discard("additional_properties")