From 50191766c3c6336ed2761078f5af9be426d11c3d Mon Sep 17 00:00:00 2001 From: Paul Silvis Date: Sun, 2 Nov 2025 11:49:36 -0800 Subject: [PATCH] Fixes Gemini API parse issue by converting nullable type arrays to single types in tool schemas (#5530) 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 7fd1dd07..78676232 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"); + } }