Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/google/adk/tools/_function_parameter_parse_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions tests/unittests/tools/test_build_function_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading