Skip to content

Commit 420253b

Browse files
refactor: apply Gemini review round 2 feedback
1 parent 3c29a55 commit 420253b

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/google/adk/tools/function_tool.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def _preprocess_args(
139139
if inspect.isclass(target_type) and issubclass(
140140
target_type, pydantic.BaseModel
141141
):
142-
if args[param_name] is None:
142+
if args[param_name] is None and is_optional:
143143
continue
144144
if not isinstance(args[param_name], target_type):
145145
try:
@@ -170,10 +170,16 @@ def _preprocess_args(
170170
f"Parameter '{param_name}': expected type '{target_type}',"
171171
f' validation error: {e}'
172172
)
173-
except (TypeError, NameError):
173+
except (TypeError, NameError) as e:
174174
# TypeAdapter could not handle this annotation (e.g. a forward
175-
# reference string). Skip validation silently.
176-
pass
175+
# reference string). Skip validation but log a warning.
176+
logger.warning(
177+
"Skipping validation for parameter '%s' due to unhandled"
178+
" annotation type '%s': %s",
179+
param_name,
180+
target_type,
181+
e,
182+
)
177183

178184
return converted_args, validation_errors
179185

tests/unittests/tools/test_function_tool_arg_validation.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,12 @@ def test_multiple_param_errors(self):
155155
args, errors = tool._preprocess_args(
156156
{"name": 123, "count": "not_a_number", "flag": "not_a_bool"}
157157
)
158-
# name: int->str coercion might fail in strict, but lax mode might
159-
# handle it. count: "not_a_number"->int will fail. flag: depends on
160-
# pydantic behavior.
158+
# All three fail: pydantic rejects int->str, "not_a_number"->int,
159+
# and "not_a_bool"->bool.
160+
assert len(errors) == 3
161+
assert any("name" in e for e in errors)
161162
assert any("count" in e for e in errors)
163+
assert any("flag" in e for e in errors)
162164

163165

164166
# --- run_async integration tests ---

0 commit comments

Comments
 (0)