Skip to content

Commit ab7cb7c

Browse files
refactor: hoist Optional None check before Pydantic branch
1 parent d410954 commit ab7cb7c

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/google/adk/tools/function_tool.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,14 @@ def _preprocess_args(
135135
target_type = non_none_types[0]
136136
is_optional = len(union_args) != len(non_none_types)
137137

138+
# Skip None values only for Optional params
139+
if args[param_name] is None and is_optional:
140+
continue
141+
138142
# Pydantic models: keep existing graceful-failure behavior
139143
if inspect.isclass(target_type) and issubclass(
140144
target_type, pydantic.BaseModel
141145
):
142-
if args[param_name] is None and is_optional:
143-
continue
144146
if not isinstance(args[param_name], target_type):
145147
try:
146148
converted_args[param_name] = target_type.model_validate(
@@ -155,10 +157,6 @@ def _preprocess_args(
155157
)
156158
continue
157159

158-
# Skip None values only for Optional params
159-
if args[param_name] is None and is_optional:
160-
continue
161-
162160
# Validate and coerce all other annotated types using TypeAdapter.
163161
# This handles primitives (int, float, str, bool), enums, and
164162
# container types (list[int], dict[str, float], etc.).

0 commit comments

Comments
 (0)