chore: satisfy the LIT001 mutable-annotation gate

The config-model pattern lists become Sequence[str], which the guardrail
already accepted and which generates an identical JSON schema. The remaining
four are fixed by CustomGuardrail's own signatures, so they carry a
mutable-ok reason instead. Comments are kept short enough that ruff format
leaves them on the annotation line, which is where the gate reads them.

Signed-off-by: pjdurden <prajjwalchittori1@gmail.com>
This commit is contained in:
pjdurden 2026-08-20 22:02:40 -05:00
parent a24aedd783
commit 8a0d4c568c
No known key found for this signature in database
3 changed files with 10 additions and 8 deletions

View file

@ -1,5 +1,6 @@
"""Built-in Sensitive Data Routing guardrail: reroutes sensitive prompts to an on-premise model."""
from collections.abc import Sequence
from typing import TYPE_CHECKING, Final
from litellm.types.guardrails import GuardrailEventHooks, Mode, SupportedGuardrailIntegrations
@ -14,8 +15,8 @@ if TYPE_CHECKING:
def _to_event_hook(
mode: str | list[str] | Mode | None,
) -> GuardrailEventHooks | list[GuardrailEventHooks] | Mode | None:
mode: str | Sequence[str] | Mode | None,
) -> GuardrailEventHooks | list[GuardrailEventHooks] | Mode | None: # mutable-ok: base type
if mode is None or isinstance(mode, Mode):
return mode
if isinstance(mode, str):

View file

@ -80,7 +80,7 @@ class SensitiveDataRoutingGuardrail(CustomGuardrail):
keywords: Sequence[str] | None = None,
sticky_session: bool = True,
session_ttl_seconds: int = DEFAULT_SESSION_TTL_SECONDS,
event_hook: GuardrailEventHooks | list[GuardrailEventHooks] | None = None,
event_hook: GuardrailEventHooks | list[GuardrailEventHooks] | None = None, # mutable-ok: base type
default_on: bool = False,
) -> None:
if not on_premise_model:
@ -105,7 +105,7 @@ class SensitiveDataRoutingGuardrail(CustomGuardrail):
self.session_ttl_seconds = session_ttl_seconds
@classmethod
def get_supported_event_hooks(cls) -> list[GuardrailEventHooks]:
def get_supported_event_hooks(cls) -> list[GuardrailEventHooks]: # mutable-ok: base type
return [GuardrailEventHooks.pre_call]
@staticmethod
@ -122,7 +122,7 @@ class SensitiveDataRoutingGuardrail(CustomGuardrail):
async def apply_guardrail(
self,
inputs: GenericGuardrailAPIInputs,
request_data: dict,
request_data: dict, # mutable-ok: proxy request body, owned by the caller
input_type: Literal["request", "response"],
logging_obj: Optional["LiteLLMLoggingObj"] = None,
) -> GenericGuardrailAPIInputs:

View file

@ -1,5 +1,6 @@
"""Types for the built-in Sensitive Data Routing guardrail."""
from collections.abc import Sequence
from typing import Final
from pydantic import Field
@ -16,15 +17,15 @@ class SensitiveDataRoutingGuardrailConfigModel(GuardrailConfigModel):
default=None,
description="Model group (from model_list) to route the request to when sensitive data is detected.",
)
prebuilt_patterns: list[str] | None = Field(
prebuilt_patterns: Sequence[str] | None = Field(
default=None,
description="Prebuilt pattern names to match (e.g. us_ssn, credit_card, email).",
)
regex_patterns: list[str] | None = Field(
regex_patterns: Sequence[str] | None = Field(
default=None,
description="Custom regular expressions; a match in any message reroutes the request.",
)
keywords: list[str] | None = Field(
keywords: Sequence[str] | None = Field(
default=None,
description="Case-insensitive keywords; a match in any message reroutes the request.",
)