diff --git a/src/google/adk/tools/_function_parameter_parse_util.py b/src/google/adk/tools/_function_parameter_parse_util.py index a8e98980d5..1dd95fece3 100644 --- a/src/google/adk/tools/_function_parameter_parse_util.py +++ b/src/google/adk/tools/_function_parameter_parse_util.py @@ -434,7 +434,7 @@ def _parse_schema_from_parameter( def _get_required_fields(schema: types.Schema) -> list[str]: if not schema.properties: - return + return [] return [ field_name for field_name, field_schema in schema.properties.items() diff --git a/tests/unittests/tools/test_build_function_declaration.py b/tests/unittests/tools/test_build_function_declaration.py index 04d7ed7f60..6dac8d98ce 100644 --- a/tests/unittests/tools/test_build_function_declaration.py +++ b/tests/unittests/tools/test_build_function_declaration.py @@ -198,6 +198,18 @@ def simple_function(input_str: str, tool_context: ToolContext) -> str: assert function_decl.parameters.properties['input_str'].type == 'STRING' assert 'tool_context' not in function_decl.parameters.properties + def test_empty_properties_required_is_empty_list_not_none(self): + """_get_required_fields must return [] not None when properties is empty.""" + from google.adk.tools._function_parameter_parse_util import _get_required_fields + from google.genai import types as genai_types + + # Schema with no properties — previously returned None (bare `return`), causing + # TypeError: 'NoneType' object is not iterable on downstream iteration. + schema = genai_types.Schema(type='OBJECT', properties={}) + result = _get_required_fields(schema) + assert result == [], f'Expected [], got {result!r}' + _ = list(result) # must not raise TypeError + def test_basemodel(self): class SimpleFunction(BaseModel): input_str: str