Skip to content

Commit 78ba1dc

Browse files
Google: Use parameters_json_schema for function declarations
Use parameters_json_schema instead of parameters (with schema_from_param conversion) for FunctionDeclaration. This preserves the full JSON Schema including anyOf types, which Gemini 3+ handles correctly but the Schema format loses by converting to TYPE_UNSPECIFIED. Also fix schema_from_param anyOf handling as fallback for response schemas: pick the first non-null type instead of TYPE_UNSPECIFIED, which Gemini 3+ models reject. See: google/adk-python#3424
1 parent eac4142 commit 78ba1dc

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,12 @@ def _categorize_tool(
783783
FunctionDeclaration(
784784
name=tool.name,
785785
description=tool.description,
786-
parameters=schema_from_param(tool.parameters)
786+
# Use parameters_json_schema to preserve full JSON Schema
787+
# including anyOf types, which Gemini 3+ handles correctly
788+
# but the Schema format (via schema_from_param) loses
789+
parameters_json_schema=tool.parameters.model_dump(
790+
exclude_none=True
791+
)
787792
if len(tool.parameters.properties) > 0
788793
else None,
789794
)
@@ -1221,7 +1226,16 @@ def schema_from_param(
12211226
param.anyOf[0], nullable=True, description=param_description
12221227
)
12231228
else:
1224-
return Schema(type=Type.TYPE_UNSPECIFIED, description=param_description)
1229+
# Gemini 3+ models reject TYPE_UNSPECIFIED, so pick the first non-null
1230+
# type as a fallback. This is a lossy conversion but allows the tool
1231+
# to work. See: https://github.com/google/adk-python/issues/3424
1232+
for sub_param in param.anyOf:
1233+
if sub_param.type and sub_param.type != "null":
1234+
return schema_from_param(
1235+
sub_param, nullable=nullable, description=param_description
1236+
)
1237+
# If no non-null type found, fall back to STRING as safest default
1238+
return Schema(type=Type.STRING, description=param_description)
12251239
elif param.enum:
12261240
return Schema(
12271241
type=Type.STRING,

0 commit comments

Comments
 (0)