From 754225427c43c0c22ecdd7eaa04f1c629da5da92 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 29 Oct 2026 03:12:15 -0700 Subject: [PATCH] style(responses): format the frame guard and give the pass-through guardrail test an enterprise license --- litellm/proxy/response_api_endpoints/endpoints.py | 9 +++++++-- .../test_passthrough_guardrails.py | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/response_api_endpoints/endpoints.py b/litellm/proxy/response_api_endpoints/endpoints.py index 58272269235..9894ee1035b 100644 --- a/litellm/proxy/response_api_endpoints/endpoints.py +++ b/litellm/proxy/response_api_endpoints/endpoints.py @@ -2137,7 +2137,10 @@ def _responses_ws_frame_guard( # a blocked frame is billed as its own failed request; only the first turn settles the admission reservation rejected_frame_auth: Final = user_api_key_dict.model_copy(update={"budget_reservation": None}) - async def rejection(exception: Exception, data: dict[str, object]) -> ResponsesWsFrameRejection: # mutable-ok: billed + async def rejection( + exception: Exception, + data: dict[str, object], # mutable-ok: billed + ) -> ResponsesWsFrameRejection: await _bill_rejected_frame(rejected_frame_auth, exception, data) proxy_exception: Final = proxy_exception_from_route_error(exception) return ResponsesWsFrameRejection(proxy_exception.message, proxy_exception.provider_specific_fields) @@ -2211,7 +2214,9 @@ def _responses_ws_frame_guard( def _reject_guarded_field_beside_nested_response(frame: Mapping[str, object], nested: object) -> None: """Only the nested ``response`` body runs through the guardrails, so a guarded field beside it would go upstream unguarded""" - stray: Final = next((key for key in _GUARDED_FRAME_FIELDS if key in frame), None) if isinstance(nested, dict) else None + stray: Final = ( + next((key for key in _GUARDED_FRAME_FIELDS if key in frame), None) if isinstance(nested, dict) else None + ) if stray is not None: raise ValueError(f"response.create sends {stray} at the top level next to response; send it inside response") diff --git a/tests/unit/proxy/pass_through_endpoints/test_passthrough_guardrails.py b/tests/unit/proxy/pass_through_endpoints/test_passthrough_guardrails.py index 7ebb82386a8..ddf22b920b5 100644 --- a/tests/unit/proxy/pass_through_endpoints/test_passthrough_guardrails.py +++ b/tests/unit/proxy/pass_through_endpoints/test_passthrough_guardrails.py @@ -74,9 +74,10 @@ class TestPassthroughGuardrailHandlerGetGuardrailNames: class TestPassthroughGuardrailHandlerCollectGuardrails: - def test_inherits_a_key_guardrail_listed_with_settings_by_its_name(self): + def test_inherits_a_key_guardrail_listed_with_settings_by_its_name(self, monkeypatch): from litellm.proxy._types import UserAPIKeyAuth + monkeypatch.setattr("litellm.proxy.proxy_server.premium_user", True) key = UserAPIKeyAuth( api_key="hashed", metadata={"guardrails": [{"pii": {"extra_body": {"threshold": 1}}}, "toxic"]} )