@@ -295,6 +295,9 @@ def convert_chat_completions_to_semconv(
295295
296296
297297def _convert_content_part_or_parts (content : object ) -> list [MessagePart ]:
298+ if not content :
299+ return []
300+
298301 if isinstance (content , list ):
299302 return [_convert_content_part (part ) for part in cast (list [Any ], content )]
300303 else :
@@ -329,9 +332,7 @@ def convert_responses_inputs_to_semconv(
329332) -> tuple [InputMessages , SystemInstructions ]:
330333 """Convert Responses API inputs to OTel Gen AI Semantic Convention format."""
331334 input_messages : InputMessages = []
332- system_instructions : SystemInstructions = []
333- if instructions :
334- system_instructions .append (TextPart (type = 'text' , content = instructions ))
335+ system_instructions : SystemInstructions = _convert_content_part_or_parts (instructions )
335336 if inputs :
336337 if isinstance (inputs , str ):
337338 input_messages .append (ChatMessage (role = 'user' , parts = [TextPart (type = 'text' , content = inputs )]))
@@ -386,10 +387,7 @@ def convert_openai_response_to_semconv(
386387 finish_reason : str | None = None ,
387388) -> OutputMessage :
388389 """Convert an OpenAI ChatCompletionMessage to OTel Gen AI Semantic Convention format."""
389- parts : list [MessagePart ] = []
390-
391- if message .content :
392- parts .append (TextPart (type = 'text' , content = message .content ))
390+ parts : list [MessagePart ] = _convert_content_part_or_parts (message .content )
393391
394392 if message .tool_calls : # pragma: no cover
395393 for tc in message .tool_calls :
0 commit comments