Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(proxy): catch callback metadata validation errors

user1ebb192cbed0
diff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.py
index ceadf823798..635c0d41481 100644
--- a/litellm/proxy/litellm_pre_call_utils.py
+++ b/litellm/proxy/litellm_pre_call_utils.py
@@ -6,6 +6,7 @@ from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
from fastapi import Request
+from pydantic import ValidationError as PydanticValidationError
from starlette.datastructures import Headers
import litellm
@@ -238,7 +239,7 @@ def _get_validated_callback_metadata(
) -> Optional[AddTeamCallback]:
try:
return AddTeamCallback(**item)
- except ValueError as e:
+ except (PydanticValidationError, ValueError) as e:
verbose_proxy_logger.warning(
"Ignoring invalid %s callback metadata: %s",
source,
diff --git a/tests/test_litellm/proxy/test_litellm_pre_call_utils.py b/tests/test_litellm/proxy/test_litellm_pre_call_utils.py
index 543be7948f0..d4319593d60 100644
--- a/tests/test_litellm/proxy/test_litellm_pre_call_utils.py
+++ b/tests/test_litellm/proxy/test_litellm_pre_call_utils.py
@@ -7,6 +7,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from fastapi import Request
+from pydantic import ValidationError as PydanticValidationError
from starlette.datastructures import Headers
import litellm
@@ -1275,7 +1276,7 @@ def test_get_dynamic_logging_metadata_with_arize_team_logging():
def test_add_team_callback_rejects_env_reference():
- with pytest.raises(ValueError) as exc_info:
+ with pytest.raises(PydanticValidationError) as exc_info:
AddTeamCallback(
callback_name="langfuse",
callback_type="success",