Skip to content

Commit a209e6a

Browse files
fix(openai): handle complex output types in responses API for openai 2 compat (#2253)
Signed-off-by: Adrian Cole <[email protected]>
1 parent 4e441f2 commit a209e6a

File tree

1 file changed

+6
-2
lines changed
  • python/instrumentation/openinference-instrumentation-openai/src/openinference/instrumentation/openai/_attributes

1 file changed

+6
-2
lines changed

python/instrumentation/openinference-instrumentation-openai/src/openinference/instrumentation/openai/_attributes/_responses_api.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,9 @@ def _get_attributes_from_response_input_param_function_call_output(
482482
if (call_id := obj.get("call_id")) is not None:
483483
yield f"{prefix}{MessageAttributes.MESSAGE_TOOL_CALL_ID}", call_id
484484
if (output := obj.get("output")) is not None:
485-
yield f"{prefix}{MessageAttributes.MESSAGE_CONTENT}", output
485+
# output can be str or complex type - serialize complex types to JSON
486+
output_value = output if isinstance(output, str) else safe_json_dumps(output)
487+
yield f"{prefix}{MessageAttributes.MESSAGE_CONTENT}", output_value
486488

487489
@classmethod
488490
@stop_on_exception
@@ -495,7 +497,9 @@ def _get_attributes_from_response_custom_tool_call_output_param(
495497
if (call_id := obj.get("call_id")) is not None:
496498
yield f"{prefix}{MessageAttributes.MESSAGE_TOOL_CALL_ID}", call_id
497499
if (output := obj.get("output")) is not None:
498-
yield f"{prefix}{MessageAttributes.MESSAGE_CONTENT}", output
500+
# output can be str or complex type - serialize complex types to JSON
501+
output_value = output if isinstance(output, str) else safe_json_dumps(output)
502+
yield f"{prefix}{MessageAttributes.MESSAGE_CONTENT}", output_value
499503

500504
@classmethod
501505
@stop_on_exception

0 commit comments

Comments
 (0)