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(file_search): log when a model-picked vector_store_id is dropped

mateo-berri55a6132b3163
diff --git a/litellm/responses/file_search/emulated_handler.py b/litellm/responses/file_search/emulated_handler.py
index 686d5c37fd0..77539efd090 100644
--- a/litellm/responses/file_search/emulated_handler.py
+++ b/litellm/responses/file_search/emulated_handler.py
@@ -459,6 +459,13 @@ async def _execute_file_search_tool_calls(
queries_from_call = _resolve_queries_from_args(args, input)
vs_id_arg = args.get("vector_store_id")
+ if vs_id_arg is not None and vs_id_arg not in all_vs_ids:
+ verbose_logger.warning(
+ "file_search emulated: model picked vector_store_id='%s' outside the request's vector_store_ids %s; "
+ "searching the request's stores instead",
+ vs_id_arg,
+ all_vs_ids,
+ )
vs_ids_for_call = [cast(str, vs_id_arg)] if vs_id_arg in all_vs_ids else all_vs_ids # cast-ok: request id
queries, results = await _run_vector_searches(
diff --git a/tests/test_litellm/llms/test_file_search_responses.py b/tests/test_litellm/llms/test_file_search_responses.py
index 5ecca664379..0339f07d414 100644
--- a/tests/test_litellm/llms/test_file_search_responses.py
+++ b/tests/test_litellm/llms/test_file_search_responses.py
@@ -12,6 +12,7 @@ Coverage:
"""
import base64
+import logging
from typing import Any, Dict, List, Optional
from importlib import import_module
from unittest.mock import AsyncMock, MagicMock, patch
@@ -938,7 +939,7 @@ class TestEmulatedFileSearchHandler:
)
@pytest.mark.asyncio
- async def test_H16_model_chosen_id_outside_request_is_not_searched(self):
+ async def test_H16_model_chosen_id_outside_request_is_not_searched(self, caplog):
"""Security regression: a vector_store_id the model returns that was not in the
request's file_search tool must never be searched. Per-key authorization only sees
request ids, so honoring an off-schema id leaks stores the key cannot access.
@@ -979,6 +980,7 @@ class TestEmulatedFileSearchHandler:
new=AsyncMock(side_effect=[first_resp, final_resp]),
),
patch("litellm.vector_stores.main.asearch", new=mock_asearch), # test-quality-ok: asserts store searched
+ caplog.at_level(logging.WARNING, logger="LiteLLM"),
):
await aresponses_with_emulated_file_search(
input="What is the launch codeword?",
@@ -992,6 +994,10 @@ class TestEmulatedFileSearchHandler:
"Handler searched the off-schema store the model picked; per-key auth never saw it"
)
assert set(searched_ids) == {"vs_allowed"}
+ dropped_id_warnings = [r for r in caplog.records if "vs_unauthorized" in r.getMessage()]
+ assert len(dropped_id_warnings) == 1, "Expected one warning naming the dropped model-picked id"
+ assert dropped_id_warnings[0].levelno == logging.WARNING
+ assert "vs_allowed" in dropped_id_warnings[0].getMessage()
@pytest.mark.asyncio
async def test_H17_model_chosen_id_within_request_narrows_search(self):