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
test(vector stores): allow primitive rag depth boundary
user06502d19a7d4
diff --git a/litellm/proxy/rag_endpoints/endpoints.py b/litellm/proxy/rag_endpoints/endpoints.pyindex df774c1d321..498d77f7535 100644--- a/litellm/proxy/rag_endpoints/endpoints.py+++ b/litellm/proxy/rag_endpoints/endpoints.py@@ -39,6 +39,23 @@ def _raise_vector_store_scan_depth_exceeded() -> None:)+def _append_payload_to_scan_stack(+ payload_stack: list[tuple[Any, int]],+ value: Any,+ next_depth: int,+) -> None:+ if isinstance(value, dict):+ if next_depth > DEFAULT_MAX_RECURSE_DEPTH:+ _raise_vector_store_scan_depth_exceeded()+ payload_stack.append((value, next_depth))+ elif isinstance(value, list):+ if next_depth > DEFAULT_MAX_RECURSE_DEPTH:+ if any(isinstance(item, (dict, list)) for item in value):+ _raise_vector_store_scan_depth_exceeded()+ return+ payload_stack.append((value, next_depth))++def _collect_vector_store_ids_from_payload(payload: Any) -> set[str]:vector_store_ids: set[str] = set()payload_stack = [(payload, 0)]@@ -61,15 +78,18 @@ def _collect_vector_store_ids_from_payload(payload: Any) -> set[str]:vector_store_ids.add(value)continueif isinstance(value, (dict, list)):- next_depth = depth + 1- if next_depth > DEFAULT_MAX_RECURSE_DEPTH:- _raise_vector_store_scan_depth_exceeded()- payload_stack.append((value, next_depth))+ _append_payload_to_scan_stack(+ payload_stack=payload_stack,+ value=value,+ next_depth=depth + 1,+ )elif isinstance(current_payload, list):- next_depth = depth + 1- if current_payload and next_depth > DEFAULT_MAX_RECURSE_DEPTH:- _raise_vector_store_scan_depth_exceeded()- payload_stack.extend((item, next_depth) for item in current_payload)+ for item in current_payload:+ _append_payload_to_scan_stack(+ payload_stack=payload_stack,+ value=item,+ next_depth=depth + 1,+ )return vector_store_idsdiff --git a/tests/test_litellm/proxy/vector_store_endpoints/test_vector_store_tenant_guard.py b/tests/test_litellm/proxy/vector_store_endpoints/test_vector_store_tenant_guard.pyindex 0ec94b3337d..48262afd363 100644--- a/tests/test_litellm/proxy/vector_store_endpoints/test_vector_store_tenant_guard.py+++ b/tests/test_litellm/proxy/vector_store_endpoints/test_vector_store_tenant_guard.py@@ -264,6 +264,22 @@ def test_rag_payload_scan_accepts_vector_store_id_at_depth_limit():assert _collect_vector_store_ids_from_payload(payload) == {"vs_at_limit"}+def test_rag_payload_scan_ignores_primitive_list_beyond_depth_limit():+ from litellm.constants import DEFAULT_MAX_RECURSE_DEPTH+ from litellm.proxy.rag_endpoints.endpoints import (+ _collect_vector_store_ids_from_payload,+ )++ payload = {}+ current = payload+ for _ in range(DEFAULT_MAX_RECURSE_DEPTH):+ current["nested"] = {}+ current = current["nested"]+ current["labels"] = ["alpha", "beta"]++ assert _collect_vector_store_ids_from_payload(payload) == set()++@pytest.mark.asyncioasync def test_responses_file_search_denies_other_team_vector_store():from litellm.proxy.common_request_processing import (