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
Merge branch 'litellm_internal_staging' of https://github.com/BerriAI/litellm into litellm_fix_search_results_with_guardrails
mateo-berrifcbeb2e6a928
diff --cc tests/test_litellm/test_utils.pyindex 209d80df3e2,a7fa6ac5568..fabfa0c31d8--- a/tests/test_litellm/test_utils.py+++ b/tests/test_litellm/test_utils.py@@@ -5768,85 -5767,31 +5768,115 @@@ class TestHuggingFaceConfigFetchassert request_timeout["read"] == HF_CONFIG_FETCH_TIMEOUT_SECONDS+async def test_success_deployment_hook_chains_past_callback_returning_response(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """Regression (LIT-5863): the dispatcher must run every callback, chaining each non-None+ result into the next call, instead of returning at the first callback answering non-None.+ A guardrail answering with the unmodified response used to starve every callback after it."""+ from litellm.types.utils import ModelResponse++ original = ModelResponse()+ replacement = ModelResponse()++ class PassthroughLogger(CustomLogger):+ async def async_post_call_success_deployment_hook(self, request_data, response, call_type):+ return response++ class ReplacingLogger(CustomLogger):+ def __init__(self) -> None:+ super().__init__()+ self.seen: list = []++ async def async_post_call_success_deployment_hook(self, request_data, response, call_type):+ self.seen.append(response)+ return replacement++ class ObservingLogger(CustomLogger):+ def __init__(self) -> None:+ super().__init__()+ self.seen: list = []++ async def async_post_call_success_deployment_hook(self, request_data, response, call_type):+ self.seen.append(response)+ return None++ replacer = ReplacingLogger()+ observer = ObservingLogger()+ monkeypatch.setattr(litellm, "callbacks", [PassthroughLogger(), replacer, observer])++ result = await async_post_call_success_deployment_hook(+ request_data={}, response=original, call_type=CallTypes.acompletion+ )++ assert replacer.seen == [original]+ assert observer.seen == [replacement]+ assert result is replacement+++async def test_registered_guardrail_does_not_starve_vector_store_search_results(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """Regression (LIT-5863): with any guardrail registered ahead of the lazily-appended+ VectorStorePreCallHook, /v1/chat/completions responses lost+ provider_specific_fields["search_results"] because the guardrail answered the unmodified+ response and the dispatcher stopped there."""+ from types import SimpleNamespace++ from litellm.integrations.custom_guardrail import CustomGuardrail+ from litellm.integrations.vector_store_integrations.vector_store_pre_call_hook import (+ VectorStorePreCallHook,+ )+ from litellm.types.utils import ModelResponse++ search_results: Final = [{"search_query": "coolant", "data": [{"content": [{"text": "Cryoline-9", "type": "text"}]}]}]+ logging_obj = SimpleNamespace(model_call_details={"search_results": search_results})+ response = ModelResponse(choices=[{"message": {"role": "assistant", "content": "Cryoline-9"}}])++ monkeypatch.setattr(+ litellm,+ "callbacks",+ [CustomGuardrail(guardrail_name="dummy-guardrail"), VectorStorePreCallHook()],+ )++ result = await async_post_call_success_deployment_hook(+ request_data={"litellm_logging_obj": logging_obj},+ response=response,+ call_type=CallTypes.acompletion,+ )++ provider_fields = result.choices[0].message.provider_specific_fields+ assert provider_fields is not None+ assert provider_fields["search_results"] == search_results+++++ class TestIsVisionExplicitlyDisabled:+ """github_copilot and chatgpt run an OAuth device flow inside get_llm_provider; the+ explicit-disable lookup must adopt the declared prefix instead of resolving it, exactly+ as _supports_factory does, or a capability check on a copilot deployment blocks routing+ on a device-code prompt."""++ @pytest.mark.parametrize("model", ["github_copilot/gpt-4o", "chatgpt/gpt-5"])+ def test_never_resolves_an_authenticating_prefix(self, model, monkeypatch):+ from litellm.utils import is_vision_explicitly_disabled++ lookups: list = []++ def _record(*args, **kwargs):+ lookups.append((args, kwargs))+ raise RuntimeError("provider resolution must not run for an authenticating provider")++ monkeypatch.setattr(litellm, "get_llm_provider", _record)++ assert is_vision_explicitly_disabled(model) is False+ assert lookups == []++ def test_explicit_false_detected_and_absent_reads_enabled(self):+ from litellm.utils import is_vision_explicitly_disabled++ assert (+ is_vision_explicitly_disabled("fireworks_ai/accounts/fireworks/models/deepseek-v4-flash-0731") is True+ )+ assert is_vision_explicitly_disabled("anthropic/claude-sonnet-4-5") is False