diff --git a/src/openai/_base_client.py b/src/openai/_base_client.py index 3fe669259f..11c311f688 100644 --- a/src/openai/_base_client.py +++ b/src/openai/_base_client.py @@ -67,6 +67,16 @@ AsyncAPIResponse, extract_response_type, ) +from pydantic import ValidationError + +def _parse_response(self, response_format, response): + try: + return response_format.model_validate(response) + except ValidationError as e: + raise ValueError( + f"Failed to parse response into {getattr(response_format, '__name__', str(response_format))}: {e}" + ) from e + from ._constants import ( DEFAULT_TIMEOUT, MAX_RETRY_DELAY,