fix: Stringify gen_ai.tool.output attribute#6086
fix: Stringify gen_ai.tool.output attribute#6086alexander-alderman-webb wants to merge 2 commits intomasterfrom
gen_ai.tool.output attribute#6086Conversation
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 27 passed | Total: 27 | Pass Rate: 100% | Execution Time: 4.51s 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 40.00%. Project has 15422 uncovered lines. Files with missing lines (3)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 28.41% 27.82% -0.59%
==========================================
Files 190 190 —
Lines 21354 21366 +12
Branches 7068 7068 —
==========================================
+ Hits 6067 5944 -123
- Misses 15287 15422 +135
- Partials 558 557 -1Generated by Codecov Action |
| set_data_normalized( | ||
| span, SPANDATA.GEN_AI_TOOL_OUTPUT, safe_repr(output) | ||
| ) |
There was a problem hiding this comment.
safe_repr with set_data_normalized double-quotes string tool outputs
Using safe_repr(output) when output is a string adds Python repr quotes (e.g., "hello" becomes "'hello'"). The existing test at line 736 of test_langchain.py expects to call int() on the tool output - this will fail if the output "5" becomes "'5'". Other integrations use safe_repr directly with span.set_data(), not with set_data_normalized() which already handles type conversion.
Verification
Traced through safe_repr (sentry_sdk/utils.py line 562-566) which calls repr() on values. For strings, repr() adds quotes. Verified set_data_normalized (sentry_sdk/ai/utils.py lines 492-499) passes strings through unchanged. Confirmed existing test at tests/integrations/langchain/test_langchain.py:736 calls int() on tool output, which would fail with quoted strings.
Identified by Warden code-review · RLV-WJ8
Description
Issues
Reminders
tox -e linters.feat:,fix:,ref:,meta:)