Repository navigation
Enable strict tool use on the Anthropic structured-output call - #99
Merged
Merged
Conversation
Relates to ISSUE-96 -- the retry added there was a client-side mitigation for a server-side gap. strict: true closes that gap at the source via grammar-constrained decoding, so the schema-mismatch failures the retry exists to catch should no longer occur. The retry stays in place as a dormant safety net. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
There was a problem hiding this comment.
🤖 marginal review
PR #99: Enable strict tool use on the Anthropic structured-output call · open · 5144f395166e65483d632dc93bfe8fed207eb597 → 341e1765212417684125dd2f0298255680e2a54b · 3 files changed
Changed files (3)
CHANGELOG.mdmarginal/providers/anthropic.pytests/test_providers.py
This was referenced Sep 20, 2026
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
AnthropicProvider.generate_structurednow sets"strict": trueon its tool definitioninput_schemainto a grammar and constrains token sampling at generation time, so the response is guaranteed schema-conformant -- not just requested to be. This is the server-side fix for the failure class ISSUE-96's retry was mitigating client-side: an extra wrapper key, a double-encoded string, a stringified array -- all observed live on_FindingsResponse, all a symptom of the model's free-form generation drifting from the schema_FindingsResponseand its nestedFindingalready emit"additionalProperties": falseat every level (astrictmode expectation, per Anthropic's docs examples) via pydantic's existingConfigDict(extra="forbid")-- no schema changes needed, only the flag_FindingsResponseever grows complex enough to hit strict mode's documented compilation-time limits, that fails at the request level (anthropic.APIError, already handled, not retried) rather than reintroducing a validation mismatch, so the retry branch should simply go unused rather than get in the wayRelates to #96 -- not a new issue, this is the follow-up fix for the same root problem.
Test plan
make lint-- cleanmake test-- 160 passed (1 new), assertingstrict: Trueis actually present in the request sent tomessages.createreviewcheck on Resolve a diff's changed functions to their out-of-diff callers #94 (which has repeatedly hit this exact failure) to confirm it now comes back clean