Skip to content

fix: change token counting fallback log from warning to debug#2220

Merged
opieter-aws merged 1 commit intostrands-agents:mainfrom
opieter-aws:fix/token-count-fallback-log-level
Apr 28, 2026
Merged

fix: change token counting fallback log from warning to debug#2220
opieter-aws merged 1 commit intostrands-agents:mainfrom
opieter-aws:fix/token-count-fallback-log-level

Conversation

@opieter-aws
Copy link
Copy Markdown
Contributor

Description

Change the native token counting fallback log from warning to debug in all model providers. When a provider's native count_tokens API fails (e.g., missing credentials, API unavailable), the SDK falls back to heuristic estimation. This is expected behavior, not an actionable warning. Demoting it to debug reduces log noise.

Related Issues

#2189

Documentation PR

N/A

Type of Change

Bug fix

Testing

How have you tested the change?

  • I ran npm run check

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@opieter-aws opieter-aws marked this pull request as ready for review April 28, 2026 16:33
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@opieter-aws opieter-aws enabled auto-merge (squash) April 28, 2026 16:38
Comment thread tests/strands/models/test_openai_responses.py
@github-actions
Copy link
Copy Markdown

Assessment: Approve

Clean, well-scoped fix that correctly demotes the native token counting fallback log from warning to debug across all 5 providers with native count_tokens implementations. The rationale is sound — this fallback is expected behavior, not an actionable warning — and the tests are properly updated with correctly scoped caplog loggers.

Review Details
  • Completeness: All 5 providers (anthropic, bedrock, gemini, llamacpp, openai_responses) and their corresponding tests are updated consistently. No providers were missed.
  • Testing: One minor inconsistency noted inline — test_openai_responses.py has import logging inside the test method rather than at the top of the file like the other test files.

@opieter-aws opieter-aws merged commit 52cdb9d into strands-agents:main Apr 28, 2026
22 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants