Repository navigation
Record OpenAI refusals in gen_ai.output.messages - #2582
Merged
alexmojaki merged 1 commit intoOct 19, 2026
Merged
Conversation
When a model refuses, OpenAI leaves `content` empty and puts the text in `message.refusal`. convert_openai_response_to_semconv only read `content`, so both streamed and non-streamed refusals produced an output message with no parts. The refusal is now recorded as a text part, as the OpenTelemetry GenAI OpenAI instrumentation does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Contributor
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a model refuses a request (for example with structured outputs), OpenAI leaves
contentempty and returns the text inmessage.refusal.convert_openai_response_to_semconvonly readcontent(and tool calls), so a refused call was recorded with an output message that had no parts. Both streamed calls (throughChatCompletionStreamState, whose snapshot carriesrefusal) and non-streamed calls went through it.The refusal is now added as a text part, the same way the OpenTelemetry GenAI OpenAI instrumentation records it.
Tests, in
tests/otel_integrations/test_openai.py:test_convert_openai_response_refusal: a non-streamed message with onlyrefusal.test_chat_completion_stream_state_refusal: a refusal streamed over two chunks throughOpenaiChatCompletionStreamState.Both fail on
main(parts: []) and pass with this change.tests/otel_integrations/test_openai.py: 72 passed (70 onmain).ruff format --check,ruff checkandpyrighton the changed module are clean.This change was written with Claude Code; the tests and checks above were run before opening the PR.