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(websearch): stop leaking interception control fields to providers (#36480)
Yassin Kortamd0c65f83f12b
diff --git a/litellm/types/utils.py b/litellm/types/utils.pyindex 8c7664257df..74311d59d8e 100644--- a/litellm/types/utils.py+++ b/litellm/types/utils.py@@ -3385,6 +3385,8 @@ agentic_loop_internal_litellm_params: Final = ["_code_interpreter_interception_sandbox_key","_code_interpreter_interception_session_scoped","_code_interpreter_interception_converted_stream",+ "_websearch_interception_emit_native_blocks",+ "_websearch_interception_converted_stream",]# Proxy-owned callback credentials, stamped from admin-configured team/key callbackdiff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.pyindex 048d7c8f3cc..ed5a9f1dd63 100644--- a/tests/test_litellm/test_utils.py+++ b/tests/test_litellm/test_utils.py@@ -29,6 +29,7 @@ from litellm.types.utils import (StreamingChoices,Usage,)+from litellm.types.utils import all_litellm_paramsfrom litellm.utils import (ProviderConfigManager,TextCompletionStreamWrapper,@@ -36,6 +37,7 @@ from litellm.utils import (_is_streaming_request,get_api_key,get_llm_provider,+ get_non_default_completion_params,get_optional_params_image_gen,get_prompt_cache_min_tokens,is_cached_message,@@ -5254,3 +5256,33 @@ def test_function_setup_failure_log_line_shows_outer_not_doomed_ids(monkeypatch)verbose_logger.removeHandler(cap)trace_id_var.set("")session_id_var.set("")+++WEBSEARCH_INTERNAL_CONTROL_FIELDS = (+ "_websearch_interception_emit_native_blocks",+ "_websearch_interception_converted_stream",+)+++def test_websearch_interception_control_fields_never_reach_the_provider():+ """The web-search interception hooks stamp these onto kwargs to carry state+ across the agentic loop. Anything the param builder does not recognize is+ swept into the provider request, and a provider that validates its body+ rejects the whole call: Bedrock Converse answers+ `_websearch_interception_emit_native_blocks: Extra inputs are not permitted`+ with a 400, so enabling interception breaks every request it touches.++ Their code-interpreter counterparts are already registered; these were not.+ """+ kwargs = {+ "a_real_provider_specific_param": 1,+ **{field: True for field in WEBSEARCH_INTERNAL_CONTROL_FIELDS},+ }++ non_default = get_non_default_completion_params(kwargs)++ assert non_default == {"a_real_provider_specific_param": 1}, (+ "web-search interception control fields leaked into the provider params: "+ f"{sorted(set(non_default) - {'a_real_provider_specific_param'})}"+ )+ assert set(WEBSEARCH_INTERNAL_CONTROL_FIELDS) <= set(all_litellm_params)