Repository navigation
fix(retry): let IncompleteOutputException propagate without wrapping - #2280
Merged
jxnl-oai merged 1 commit intoMay 10, 2026
Merged
Conversation
Previously IncompleteOutputException was caught by the generic `except Exception` handler inside the tenacity retry loop and eventually wrapped in InstructorRetryException, making direct `except IncompleteOutputException` catch blocks impossible. Fix: detect IncompleteOutputException in both retry_sync and retry_async before tenacity can wrap it — store it and break out of the tenacity loop cleanly, then re-raise after the loop. Adds 4 regression tests covering sync/async and max_retries=0/N. Fixes 567-labs#2273 Built by Rudrendu Paul, developed with Claude Code
Contributor
|
The issue still persists for |
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.
Motivation and Context
Closes #2273
When an LLM returns a truncated response (e.g.
finish_reason=length), instructor raisesIncompleteOutputException. The documented usage pattern is:However, this catch block never fires.
IncompleteOutputExceptionfalls into the genericexcept Exceptionhandler inside the tenacity retry loop, and after retries are exhausted it gets wrapped inInstructorRetryException. Users must catchInstructorRetryExceptionand inspect its.last_attemptto find the original exception — an undocumented workaround that defeats the purpose of a named exception type.What changes
In both
retry_syncandretry_async:IncompleteOutputExceptionin theexcept Exceptionhandler before tenacity's retry logic runsbreakout of the tenacity loop cleanly (tenacity never sees the exception)The change is minimal: 4 new lines in the exception handler of each function, 2 variable initializations, 2 post-loop raises.
Tests
Added
tests/test_incomplete_output_exception.pywith 4 tests:InstructorRetryExceptionmax_retries=0, API called exactly onceAll existing retry and hooks tests continue to pass.