From 277391a389496222556db45ee0f2ef8ad430f29c Mon Sep 17 00:00:00 2001 From: Paul Silvis Date: Sun, 2 Nov 2025 09:43:29 -0800 Subject: [PATCH] fix(google): Fixes Gemini API parse issue by converting nullable type arrays to single types in tool schemas Fixes issue where Gemini API rejected tool schemas containing type arrays like ["string", "null"]. Gemini's API expects type fields to be single string values, not arrays. The root cause was in the process_map function, which was cloning values for most keys instead of calling process_value. The process_value function already had logic to convert type arrays to single values, but it was only being called for specific keys (properties, items, anyOf, allOf), not for the type key itself. This fix changes the default case in process_map to call process_value, which properly converts type arrays like ["string", "null"] to "string" (extracting the non-null type). Signed-off-by: Paul Silvis --- crates/goose/src/providers/formats/google.rs | 34 +++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/crates/goose/src/providers/formats/google.rs b/crates/goose/src/providers/formats/google.rs index 7fd1dd075197..786762328b15 100644 --- a/crates/goose/src/providers/formats/google.rs +++ b/crates/goose/src/providers/formats/google.rs @@ -238,7 +238,7 @@ pub fn process_map(map: &Map, parent_key: Option<&str>) -> Value value.clone() } } - _ => value.clone(), + _ => process_value(value, Some(key.as_str())), }; Some((key.clone(), processed_value)) @@ -858,4 +858,36 @@ mod tests { assert_eq!(payload, expected_payload); } + + #[test] + fn test_tools_with_nullable_types_converted_to_single_type() { + // Test that type arrays like ["string", "null"] are converted to single types + let params = object!({ + "properties": { + "nullable_field": { + "type": ["string", "null"], + "description": "A nullable string field" + }, + "regular_field": { + "type": "number", + "description": "A regular number field" + } + } + }); + let tools = vec![Tool::new("test_tool", "test description", params)]; + let result = format_tools(&tools); + + assert_eq!(result.len(), 1); + assert_eq!(result[0]["name"], "test_tool"); + + // Verify that the type array was converted to a single string type + let nullable_field = &result[0]["parameters"]["properties"]["nullable_field"]; + assert_eq!(nullable_field["type"], "string"); + assert_eq!(nullable_field["description"], "A nullable string field"); + + // Verify that regular types are unchanged + let regular_field = &result[0]["parameters"]["properties"]["regular_field"]; + assert_eq!(regular_field["type"], "number"); + assert_eq!(regular_field["description"], "A regular number field"); + } }