mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-26 01:12:21 +00:00
fix(oci/chat): catch pydantic ValidationError when parsing OCI responses
Pydantic v2 raises ValidationError (not TypeError) when field validation fails, so malformed OCI completion responses or stream chunks would propagate unhandled out of handle_generic_response, handle_generic_stream_chunk, and handle_cohere_stream_chunk. Widen the except clauses to also catch ValidationError so callers get a clean OCIError.
This commit is contained in:
parent
1c6cd61311
commit
e3ee32e1d9
2 changed files with 6 additions and 3 deletions
|
|
@ -10,6 +10,8 @@ import datetime
|
|||
import json
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import ValidationError
|
||||
|
||||
from litellm.llms.oci.chat.generic import _synthesize_oci_tool_call_id
|
||||
from litellm.llms.oci.common_utils import (
|
||||
OCI_JSON_TO_PYTHON_TYPES,
|
||||
|
|
@ -273,7 +275,7 @@ def handle_cohere_stream_chunk(dict_chunk: dict) -> ModelResponseStream:
|
|||
"""Parse a single Cohere SSE chunk into a LiteLLM ModelResponseStream."""
|
||||
try:
|
||||
typed_chunk = CohereStreamChunk(**dict_chunk)
|
||||
except TypeError as e:
|
||||
except (TypeError, ValidationError) as e:
|
||||
raise OCIError(
|
||||
status_code=500,
|
||||
message=f"Chunk cannot be parsed as CohereStreamChunk: {str(e)}",
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import hashlib
|
|||
from typing import Dict, List, Optional, Union
|
||||
|
||||
import httpx
|
||||
from pydantic import ValidationError
|
||||
|
||||
from litellm.llms.oci.common_utils import (
|
||||
OCIError,
|
||||
|
|
@ -315,7 +316,7 @@ def handle_generic_response(
|
|||
"""Parse a non-streaming GENERIC OCI response into a LiteLLM ModelResponse."""
|
||||
try:
|
||||
completion_response = OCICompletionResponse(**json_data)
|
||||
except TypeError as e:
|
||||
except (TypeError, ValidationError) as e:
|
||||
raise OCIError(
|
||||
message=f"Response cannot be casted to OCICompletionResponse: {str(e)}",
|
||||
status_code=raw_response.status_code,
|
||||
|
|
@ -383,7 +384,7 @@ def handle_generic_stream_chunk(dict_chunk: dict) -> ModelResponseStream:
|
|||
|
||||
try:
|
||||
typed_chunk = OCIStreamChunk(**dict_chunk)
|
||||
except TypeError as e:
|
||||
except (TypeError, ValidationError) as e:
|
||||
raise OCIError(
|
||||
status_code=500,
|
||||
message=f"Chunk cannot be parsed as OCIStreamChunk: {str(e)}",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue