style(responses): format the frame guard and give the pass-through guardrail test an enterprise license

This commit is contained in:
mateo-berri 2026-10-29 03:12:15 -07:00
parent dd19b39be2
commit 754225427c
2 changed files with 9 additions and 3 deletions

View file

@ -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")

View file

@ -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"]}
)