fix(langchain): Stop double-counting usage in multi-candidate responses - #7064
Open
alexander-alderman-webb wants to merge 6 commits into
Open
fix(langchain): Stop double-counting usage in multi-candidate responses#7064alexander-alderman-webb wants to merge 6 commits into
alexander-alderman-webb wants to merge 6 commits into
Conversation
Contributor
Codecov Results 📊✅ 99182 passed | ⏭️ 6527 skipped | Total: 105709 | Pass Rate: 93.83% | Execution Time: 357m 15s 📊 Comparison with Base Branch
➖ Removed Tests (1)View removed tests
All tests are passing successfully. ✅ Patch coverage is 88.89%. Project has 2496 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 89.99% 89.99% —%
==========================================
Files 193 193 —
Lines 24946 24947 +1
Branches 9000 9000 —
==========================================
+ Hits 22451 22451 —
- Misses 2495 2496 +1
- Partials 1435 1435 —Generated by Codecov Action |
alexander-alderman-webb
marked this pull request as ready for review
August 6, 2026 13:38
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.
Description
Take token usage from the first candidate object in each generation, instead of summing token usage from each candidate.
The inner list in
LLMResult.generationscontains candidate generations (multiple output choices). Candidates do not have independent token usage, butlangchainhooks duplicate the token usage on each candidate.Add a test using a
google-genairesponse, asChatOpenAImodels do not enter theelse:branch below:sentry-python/sentry_sdk/integrations/langchain.py
Lines 769 to 774 in f670a1b
Issues
Reminders
uv run ruff.feat:,fix:,ref:,meta:)