@@ -52,6 +52,9 @@ async def test_async_structured_output_with_content(
5252 response_format = CalendarEvent ,
5353 )
5454
55+ # Verify wrapper doesn't interfere with parse() return
56+ assert response .choices [0 ].message .parsed is not None
57+
5558 spans = span_exporter .get_finished_spans ()
5659 assert len (spans ) == 1
5760 assert_all_attributes (
@@ -69,7 +72,8 @@ async def test_async_structured_output_with_content(
6972 if latest_experimental_enabled
7073 else GenAIAttributes .GEN_AI_OPENAI_REQUEST_RESPONSE_FORMAT
7174 )
72- assert spans [0 ].attributes [output_type_attr_key ] == "json_schema"
75+ expected_value = "json" if latest_experimental_enabled else "json_schema"
76+ assert spans [0 ].attributes [output_type_attr_key ] == expected_value
7377
7478 if latest_experimental_enabled :
7579 assert_messages_attribute (
@@ -78,18 +82,14 @@ async def test_async_structured_output_with_content(
7882 )
7983 assert_messages_attribute (
8084 spans [0 ].attributes ["gen_ai.output.messages" ],
81- format_simple_expected_output_message (
82- response .choices [0 ].message .content
83- ),
85+ format_simple_expected_output_message (response .choices [0 ].message .content ),
8486 )
8587 else :
8688 logs = log_exporter .get_finished_logs ()
8789 assert len (logs ) == 2
8890
8991 user_message = {"content" : STRUCTURED_OUTPUT_PROMPT [0 ]["content" ]}
90- assert_message_in_logs (
91- logs [0 ], "gen_ai.user.message" , user_message , spans [0 ]
92- )
92+ assert_message_in_logs (logs [0 ], "gen_ai.user.message" , user_message , spans [0 ])
9393
9494 choice_event = {
9595 "index" : 0 ,
@@ -99,9 +99,7 @@ async def test_async_structured_output_with_content(
9999 "content" : response .choices [0 ].message .content ,
100100 },
101101 }
102- assert_message_in_logs (
103- logs [1 ], "gen_ai.choice" , choice_event , spans [0 ]
104- )
102+ assert_message_in_logs (logs [1 ], "gen_ai.choice" , choice_event , spans [0 ])
105103
106104
107105@pytest .mark .asyncio ()
@@ -121,6 +119,9 @@ async def test_async_structured_output_no_content(
121119 response_format = CalendarEvent ,
122120 )
123121
122+ # Verify wrapper doesn't interfere with parse() return
123+ assert response .choices [0 ].message .parsed is not None
124+
124125 spans = span_exporter .get_finished_spans ()
125126 assert len (spans ) == 1
126127 assert_all_attributes (
@@ -138,7 +139,8 @@ async def test_async_structured_output_no_content(
138139 if latest_experimental_enabled
139140 else GenAIAttributes .GEN_AI_OPENAI_REQUEST_RESPONSE_FORMAT
140141 )
141- assert spans [0 ].attributes [output_type_attr_key ] == "json_schema"
142+ expected_value = "json" if latest_experimental_enabled else "json_schema"
143+ assert spans [0 ].attributes [output_type_attr_key ] == expected_value
142144
143145 logs = log_exporter .get_finished_logs ()
144146 if latest_experimental_enabled :
@@ -155,6 +157,4 @@ async def test_async_structured_output_no_content(
155157 "finish_reason" : "stop" ,
156158 "message" : {"role" : "assistant" },
157159 }
158- assert_message_in_logs (
159- logs [1 ], "gen_ai.choice" , choice_event , spans [0 ]
160- )
160+ assert_message_in_logs (logs [1 ], "gen_ai.choice" , choice_event , spans [0 ])
0 commit comments