@@ -370,6 +370,38 @@ fn test_tool_result_content_requires_content() {
370370 assert ! ( err. to_string( ) . contains( "missing field `content`" ) ) ;
371371}
372372
373+ #[ tokio:: test]
374+ async fn test_tool_result_content_with_array_structured_content ( ) -> Result < ( ) > {
375+ let structured =
376+ serde_json:: json!( [ { "city" : "SF" , "temp" : 72 } , { "city" : "NY" , "temp" : 65 } ] ) ;
377+ let mut tool_result = ToolResultContent :: new ( "call_123" , vec ! [ ContentBlock :: text( "forecast" ) ] ) ;
378+ tool_result. structured_content = Some ( structured) ;
379+
380+ let json = serde_json:: to_string ( & tool_result) ?;
381+ let deserialized: ToolResultContent = serde_json:: from_str ( & json) ?;
382+ assert_eq ! ( tool_result, deserialized) ;
383+ assert ! ( deserialized. structured_content. unwrap( ) . is_array( ) ) ;
384+
385+ Ok ( ( ) )
386+ }
387+
388+ #[ tokio:: test]
389+ async fn test_tool_result_content_with_primitive_structured_content ( ) -> Result < ( ) > {
390+ let structured = serde_json:: json!( 42 ) ;
391+ let mut tool_result = ToolResultContent :: new ( "call_123" , vec ! [ ContentBlock :: text( "count" ) ] ) ;
392+ tool_result. structured_content = Some ( structured) ;
393+
394+ let json = serde_json:: to_string ( & tool_result) ?;
395+ let deserialized: ToolResultContent = serde_json:: from_str ( & json) ?;
396+ assert_eq ! ( tool_result, deserialized) ;
397+ assert ! ( matches!(
398+ deserialized. structured_content,
399+ Some ( serde_json:: Value :: Number ( _) )
400+ ) ) ;
401+
402+ Ok ( ( ) )
403+ }
404+
373405#[ tokio:: test]
374406async fn test_sampling_message_with_tool_use ( ) -> Result < ( ) > {
375407 let message = SamplingMessage :: assistant_tool_use (
0 commit comments