Skip to content

Commit 672d94c

Browse files
Google: Handle anyOf types for Gemini 3+ models
Gemini 3+ models reject TYPE_UNSPECIFIED in function parameter schemas, which was previously used as a fallback for anyOf types that weren't simple nullable types ([type, null]). This change picks the first non-null type from anyOf as the fallback type instead. This is a lossy conversion (we lose the union semantics) but allows tools with union-typed parameters like `str | list[str]` to work with Gemini 3 models. See: google/adk-python#3424
1 parent eac4142 commit 672d94c

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎src/inspect_ai/model/_providers/google.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,16 @@ def schema_from_param(
12211221
param.anyOf[0], nullable=True, description=param_description
12221222
)
12231223
else:
1224-
return Schema(type=Type.TYPE_UNSPECIFIED, description=param_description)
1224+
# Gemini 3+ models reject TYPE_UNSPECIFIED, so pick the first non-null
1225+
# type as a fallback. This is a lossy conversion but allows the tool
1226+
# to work. See: https://github.com/google/adk-python/issues/3424
1227+
for sub_param in param.anyOf:
1228+
if sub_param.type and sub_param.type != "null":
1229+
return schema_from_param(
1230+
sub_param, nullable=nullable, description=param_description
1231+
)
1232+
# If no non-null type found, fall back to STRING as safest default
1233+
return Schema(type=Type.STRING, description=param_description)
12251234
elif param.enum:
12261235
return Schema(
12271236
type=Type.STRING,

0 commit comments

Comments
 (0)