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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(vector-stores): fall back to annotate when the failure mode is unrecognized
mateo-berrie464e749e00e
diff --git a/litellm/integrations/vector_store_integrations/vector_store_pre_call_hook.py b/litellm/integrations/vector_store_integrations/vector_store_pre_call_hook.pyindex ed125b915b4..274cb496b8f 100644--- a/litellm/integrations/vector_store_integrations/vector_store_pre_call_hook.py+++ b/litellm/integrations/vector_store_integrations/vector_store_pre_call_hook.py@@ -7,8 +7,9 @@ It searches the vector store for relevant context and appends it to the messagesfrom collections.abc import Awaitable, Callable, Mapping, Sequencefrom dataclasses import dataclass-from typing import TYPE_CHECKING, Any, Final, Protocol, cast+from typing import TYPE_CHECKING, Any, Final, Protocol, cast, get_args+from pydantic import TypeAdapter, ValidationErrorfrom typing_extensions import assert_neverimport litellm@@ -22,6 +23,7 @@ from litellm.types.utils import CallTypes, StandardCallbackDynamicParamsfrom litellm.types.vector_stores import (LiteLLM_ManagedVectorStore,VectorStoreSearchFailure,+ VectorStoreSearchFailureMode,VectorStoreSearchResponse,VectorStoreSearchResult,)@@ -34,6 +36,8 @@ else:LiteLLMLoggingObj = AnySEARCH_FAILURES_FIELD: Final = "vector_store_search_failures"+_DEFAULT_FAILURE_MODE: Final[VectorStoreSearchFailureMode] = "annotate"+_FAILURE_MODE_ADAPTER: Final = TypeAdapter(VectorStoreSearchFailureMode)class ProxyRuntime(Protocol):@@ -153,7 +157,7 @@ class VectorStorePreCallHook(CustomLogger):litellm_logging_obj.model_call_details[detail] = valueif augmentation.failures:- match litellm.vector_store_search_failure_mode:+ match _configured_failure_mode():case "error":raise VectorStoreSearchError(failures=augmentation.failures, model=model)case "annotate":@@ -435,3 +439,16 @@ def _requested_vector_store_ids(non_default_params: Mapping[str, object]) -> tupif not isinstance(requested, (list, tuple)):return ()return tuple(str(vector_store_id) for vector_store_id in requested)+++def _configured_failure_mode() -> VectorStoreSearchFailureMode:+ try:+ return _FAILURE_MODE_ADAPTER.validate_python(litellm.vector_store_search_failure_mode)+ except ValidationError:+ verbose_logger.warning(+ "Unsupported vector_store_search_failure_mode=%r, falling back to %r. Supported modes: %s",+ litellm.vector_store_search_failure_mode,+ _DEFAULT_FAILURE_MODE,+ ", ".join(get_args(VectorStoreSearchFailureMode)),+ )+ return _DEFAULT_FAILURE_MODEdiff --git a/tests/test_litellm/integrations/vector_store_integrations/test_vector_store_pre_call_hook.py b/tests/test_litellm/integrations/vector_store_integrations/test_vector_store_pre_call_hook.pyindex 64ee9474e44..eae53becc14 100644--- a/tests/test_litellm/integrations/vector_store_integrations/test_vector_store_pre_call_hook.py+++ b/tests/test_litellm/integrations/vector_store_integrations/test_vector_store_pre_call_hook.py@@ -425,6 +425,36 @@ async def test_error_mode_fails_the_request_instead_of_answering_without_the_knoassert "vs-broken: litellm.BadRequestError: no healthy deployments for vs-broken" in raised.value.message+async def test_a_misspelled_failure_mode_annotates_instead_of_erroring_the_request(+ registry_with: RegisterStores,+ monkeypatch: pytest.MonkeyPatch,+ warnings: list[logging.LogRecord],+) -> None:+ """Regression (LIT-6809): litellm_settings takes any value, so a typo must not become a 500."""+ registry_with("vs-broken")+ monkeypatch.setattr(litellm, "vector_store_search_failure_mode", "erorr")++ logging_obj = FakeLoggingObj({})+ _, messages, _ = await _run_hook(+ VectorStorePreCallHook(+ proxy_runtime=FakeProxyRuntime(router=RecordingRouter(failing_vector_store_ids=frozenset({"vs-broken"})))+ ),+ ["vs-broken"],+ logging_obj,+ )++ assert messages[0]["content"] == "what is litellm?"+ assert logging_obj.model_call_details["vector_store_search_failures"] == (+ {+ "vector_store_id": "vs-broken",+ "custom_llm_provider": "bedrock",+ "error": "litellm.BadRequestError: no healthy deployments for vs-broken",+ },+ )+ assert any("erorr" in record.getMessage() for record in warnings)++@pytest.mark.asyncioasync def test_error_mode_leaves_a_fully_healthy_request_alone(registry_with: RegisterStores,