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(decisions): answer 400 on a malformed provider_specific_header instead of dropping it (#46619)
Mateo Wang56dad9077d06
diff --git a/litellm/decisions/call.py b/litellm/decisions/call.pyindex 0c54422eb68..5fa2ae88f4b 100644--- a/litellm/decisions/call.py+++ b/litellm/decisions/call.py@@ -387,20 +387,13 @@ def _provider_ir_request(return supported-def _provider_specific_header(- value: object,-) -> ProviderSpecificHeader | tuple[ProviderSpecificHeader, ...] | None:- try:- return _PROVIDER_SPECIFIC_HEADER_ADAPTER.validate_python(value)- except ValidationError:- return None--def _outbound_headers(extra_headers: Mapping[str, str] | None, custom_llm_provider: str, kwargs: Mapping[str, object]) -> Mapping[str, str]:forwarded: Final = ProviderSpecificHeaderUtils.get_provider_specific_headers(- provider_specific_header=_provider_specific_header(kwargs.get("provider_specific_header")),+ provider_specific_header=_PROVIDER_SPECIFIC_HEADER_ADAPTER.validate_python(+ kwargs.get("provider_specific_header")+ ),custom_llm_provider=custom_llm_provider,)return MappingProxyType({**(extra_headers or {}), **forwarded})diff --git a/tests/unit/systemone/test_main.py b/tests/unit/systemone/test_main.pyindex 82bb3d666cc..05a9850a221 100644--- a/tests/unit/systemone/test_main.py+++ b/tests/unit/systemone/test_main.py@@ -411,19 +411,20 @@ async def test_typesafe_answers_box_questions_it_cannot_take_as_refusals_under_d]-def test_a_malformed_provider_specific_header_is_ignored(respx_mock: respx.MockRouter) -> None:+def test_a_malformed_provider_specific_header_answers_400_before_http(respx_mock: respx.MockRouter) -> None:route: Final = respx_mock.post(_TYPESAFE_URL).respond(json=_SYSTEMONE_RESPONSE)- response: Final = litellm.systemone(- model="typesafe/jev-1.14.0",- state=_STATE,- questions=_SYSTEMONE_QUESTIONS,- api_key="caller-key",- provider_specific_header={"custom_llm_provider": "typesafe", "extra_headers": "not a header map"},- )+ with pytest.raises(litellm.BadRequestError, match="Invalid Decisions request") as caught:+ litellm.systemone(+ model="typesafe/jev-1.14.0",+ state=_STATE,+ questions=_SYSTEMONE_QUESTIONS,+ api_key="caller-key",+ provider_specific_header={"custom_llm_provider": "typesafe", "extra_headers": "not a header map"},+ )- assert isinstance(response, DecisionsResponse)- assert not [name for name in route.calls.last.request.headers if name.startswith("typesafe-danger-zone-")]+ assert caught.value.status_code == 400+ assert not route.called@pytest.mark.asyncio