Support Pydantic Validators when using .parsed
#289
Labels
priority: p3
Desirable enhancement or fix. May not be included in next release.
type: feature request
‘Nice-to-have’ improvement, new feature or different behavior or design.
Currently, when using the
.parsed
property to access parsed JSON responses, Pydanticvalidator
functions (and by extension,@field_validator
and@model_validator
decorators) are not executed. Errors likepydantic.ValidationError
andjson.decoder.JSONDecodeError
are silently caught, and the.parsed
attribute returns an empty or null value, rather than raising the expected validation error. This makes it difficult to leverage Pydantic's validation capabilities when working with streaming or potentially malformed responses.Expected Behavior:
When
.parsed
is accessed, and the underlying response data causes apydantic.ValidationError
(because a validator fails), the exception should be raised, just as it would be if constructing the Pydantic model directly with valid data. The same exception handling applies to JSONDecodeError.Example (Illustrative):
Benefits:
The text was updated successfully, but these errors were encountered: