Handle Anthropic tool_use retries on ValidationError#1810
Merged
jxnl merged 2 commits into567-labs:mainfrom Sep 15, 2025
Merged
Handle Anthropic tool_use retries on ValidationError#1810jxnl merged 2 commits into567-labs:mainfrom
jxnl merged 2 commits into567-labs:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to b113c93 in 29 seconds. Click for details.
- Reviewed
21lines of code in1files - Skipped
0files when reviewing. - Skipped posting
1draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. instructor/providers/anthropic/utils.py:161
- Draft comment:
Using the union operator (ValidationError | InstructorValidationError) is concise, but consider using a tuple (i.e., isinstance(exception, (ValidationError, InstructorValidationError))) for better compatibility with Python versions < 3.10 if needed. - Reason this comment was not posted:
Confidence changes required:80%<= threshold85%None
Workflow ID: wflow_kWOx7kI2oe9JZ86u
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Contributor
Author
|
This is caused by changes in #1804. The InstructorError.from_exception() method that enriches exceptions with failed attempts data effectively creates a different class of |
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.
Auto-retry when is not working when using Anthropic Claude tool use because of this error:
This is when first attempt resulted in
ValidationError, eg,:To Reproduce
Something like the below when the client is instantiated with
mode=instructor.Mode.ANTHROPIC_TOOLSor the equivalent:Expected behavior and fix
That retried requests will contain the tool call result and successful generate responses (whether valid or not)
Root cause
In instructor/core/retry.py line 599, the
handle_reask_kwargs()function calls:This converts pydantic
ValidationErrorexceptions to instructorValidationErrorexceptions, so by the time the exception reachesreask_anthropic_tools(), it's an instructorValidationError, not a pydantic one.Fix Applied
File:
instructor/providers/anthropic/utils.pyChange:
to
Seems only the
providers/anthropic/utils.pyhas the problematic pattern as it is the only provider that:So OpenAI, Mistral, Gemini, Cohere, Cerebras, Fireworks, Writer, XAI, Bedrock, Perplexity, VertexAI seem unaffected.
Important
Fixes auto-retry issue in
reask_anthropic_tools()by handling bothValidationErrorandInstructorValidationErrorfor Anthropic provider.reask_anthropic_tools()inutils.pyby handling bothValidationErrorandInstructorValidationError.InstructorValidationErrorfromcore.exceptionsinutils.py.isinstancecheck to includeInstructorValidationErrorinreask_anthropic_tools().This description was created by
for b113c93. You can customize this summary. It will automatically update as commits are pushed.