Repository navigation
fix: type-guard llm message role and content attributes - #4194
Merged
Merged
Conversation
List-valued message content (OpenAI-style content blocks) was yielded into the string span attribute llm.input_messages.N.message.content, which is not a valid OTEL AttributeValue, and non-string role values were emitted likewise. Yield role only when it is a string, and route sequence content into the typed message.contents blocks channel when no explicit contents field is present. String content handling is unchanged. Fixes #3859
…tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CT7Y1w9UEbCEAMvefcd63d
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.
Carries #4172 by @Harsh23Kashyap over the line. Fixes #3859.
Changes
b99fafb), unchanged and with authorship kept:_llm_messages_attributesnow yieldsroleonly when it is a string, and routes list-valuedcontentinto the typedmessage.contents.N.message_content.*channel when there is no explicitcontents.main.tests/test_attributes.py:ruff format: one assert is wrapped to fit the line length.mypy: the four tests that pass deliberately malformed messages (a list ascontent, an int asrole) now carry# type: ignore[typeddict-item], the same pattern other test suites in the repo use.Verification
tox run -e py313-ci-instrumentationpasses: format, lint, mypy and 8596 tests.If #4172 is updated with the same fix commit, this PR can be closed in its favour.
Generated by Claude Code