diff --git a/litellm/llms/oci/chat/cohere.py b/litellm/llms/oci/chat/cohere.py index dc611c9906c..7805f17c74c 100644 --- a/litellm/llms/oci/chat/cohere.py +++ b/litellm/llms/oci/chat/cohere.py @@ -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)}", diff --git a/litellm/llms/oci/chat/generic.py b/litellm/llms/oci/chat/generic.py index 8ded6c7a546..92b050004dc 100644 --- a/litellm/llms/oci/chat/generic.py +++ b/litellm/llms/oci/chat/generic.py @@ -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)}",