Skip to content

Commit 2f9c043

Browse files
authored
fix(openai): reask functionality broken in JSON mode since v1.9.0 (#1793)
Since v1.9.0, from this PR: #1549, the reask functionality with JSON mode is broken. Irrespective of whether the underlying error is a `JSONDecodeError` or `ValidationError`, both are being wrapped under `instructor.core.exceptions.ValidationError` Hence in `retry_sync`/`retry_async` of `instructor/core/retry.py`, these wrapped errors are always caught by the generic `Exception` block instead of the specific `(ValidationError, JSONDecodeError)` block, even when those specific exception types should trigger retries with error messages included <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Fixes reask functionality in JSON mode by removing exception wrapping in `_validate_model_from_json()` to allow specific exception handling. > > - **Behavior**: > - Fixes reask functionality in JSON mode by removing exception wrapping in `_validate_model_from_json()` in `function_calls.py`. > - Allows `JSONDecodeError` and `ValidationError` to be caught specifically in `retry_sync`/`retry_async` in `retry.py`. > - **Exceptions**: > - Removes wrapping of exceptions in `instructor.core.exceptions.ValidationError` in `_validate_model_from_json()`. > - **Logging**: > - Retains debug logging for JSON decode and model validation errors in `_validate_model_from_json()`. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=567-labs%2Finstructor&utm_source=github&utm_medium=referral)<sup> for b6a47d9. You can [customize](https://app.ellipsis.dev/567-labs/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
2 parents bc97a48 + 541aa1c commit 2f9c043

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

instructor/processing/function_calls.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,7 @@ def _validate_model_from_json(
9595
raise ValueError(f"Failed to parse JSON: {e}") from e
9696
except Exception as e:
9797
logger.debug(f"Model validation error: {e}")
98-
# Re-raise with more context
99-
from ..core.exceptions import ValidationError as InstructorValidationError
100-
101-
raise InstructorValidationError(
102-
f"Failed to validate model {cls.__name__}: {str(e)}"
103-
) from e
98+
raise
10499

105100

106101
class OpenAISchema(BaseModel):

0 commit comments

Comments
 (0)