fix(anthropic): warn when response is truncated by max_tokens limit#2212
Open
citizen204 wants to merge 1 commit into
Open
fix(anthropic): warn when response is truncated by max_tokens limit#2212citizen204 wants to merge 1 commit into
citizen204 wants to merge 1 commit into
Conversation
Log a WARNING when the Anthropic API returns stop_reason "max_tokens" so users understand why output is cut short and know to raise max_tokens. Applies to both try_run (non-streaming) and try_stream paths. Closes griptape-ai#1982
collindutter
requested changes
Jun 23, 2026
collindutter
left a comment
Member
There was a problem hiding this comment.
@citizen204 this was made against the dev branch, please make the PR against the main branch.
Author
|
Hi @collindutter — just to flag: the PR is currently targeting |
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.
Summary
Closes #1982
When the Anthropic API stops generation because the response hit the
max_tokenslimit, users currently receive silently truncated output with no indication of what happened. This PR adds aWARNING-level log message in both the streaming and non-streaming paths so the problem is immediately visible.try_run: checksresponse.stop_reason == "max_tokens"and logs a warning with the currentmax_tokensvalue.try_stream: checksevent.delta.stop_reason == "max_tokens"in themessage_deltaevent and logs the same warning.No behaviour changes — the message is still returned as-is; users who want longer output can simply increase
max_tokens.Test plan
test_try_run_warns_on_max_tokens— mocks a response withstop_reason="max_tokens", asserts a WARNING containing"max_tokens"is emitted.test_try_stream_warns_on_max_tokens— mocks a stream with amessage_deltawhosedelta.stop_reason="max_tokens", asserts same warning.test_try_run/test_try_stream_runtests are unaffected (mock responses have a non-stringstop_reasonthat never equals"max_tokens").📚 Documentation preview 📚: https://griptape--2212.org.readthedocs.build//2212/