From cb2ee9ec1fac58cce8be8c6e25c8ca9767dbc1cd Mon Sep 17 00:00:00 2001 From: AlphaRex-pixel Date: Fri, 14 Aug 2026 18:06:28 +0530 Subject: [PATCH] style: apply ruff format --- .../guardrail_hooks/tealtiger/engine.py | 1 + .../guardrail_hooks/tealtiger/patterns.py | 61 ++++++++++++++----- .../guardrail_hooks/tealtiger/tealtiger.py | 9 +-- 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/litellm/proxy/guardrails/guardrail_hooks/tealtiger/engine.py b/litellm/proxy/guardrails/guardrail_hooks/tealtiger/engine.py index 00fccbf33c6..082af5661ac 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/tealtiger/engine.py +++ b/litellm/proxy/guardrails/guardrail_hooks/tealtiger/engine.py @@ -2,6 +2,7 @@ TealEngine: deterministic, dependency-free PII / cost / tool-auth policy evaluation. No network calls in the governance path. """ + from __future__ import annotations import threading diff --git a/litellm/proxy/guardrails/guardrail_hooks/tealtiger/patterns.py b/litellm/proxy/guardrails/guardrail_hooks/tealtiger/patterns.py index f8e48b36803..c386e06bb1d 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/tealtiger/patterns.py +++ b/litellm/proxy/guardrails/guardrail_hooks/tealtiger/patterns.py @@ -10,6 +10,7 @@ the loosest patterns (e.g. generic credit card, generic driver's license). Callers can narrow scope via TealEngine(policies=[{"patterns": [...]}]) instead of "all", or override this module's PII_PATTERNS entirely. """ + import re PII_PATTERNS = { @@ -26,7 +27,6 @@ PII_PATTERNS = { "uk_nino": re.compile(r"\b[A-CEGHJ-PR-TW-Z]{2}\d{6}[A-D]\b"), "date_of_birth": re.compile(r"\b(0[1-9]|1[0-2])[/-](0[1-9]|[12]\d|3[01])[/-](19|20)\d{2}\b"), "vin": re.compile(r"\b[A-HJ-NPR-Z0-9]{17}\b"), - # ---------- financial ---------- "credit_card_visa": re.compile(r"\b4\d{3}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}\b"), "credit_card_mastercard": re.compile(r"\b5[1-5]\d{2}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}\b"), @@ -39,7 +39,6 @@ PII_PATTERNS = { "us_bank_account": re.compile(r"\b\d{8,17}\b"), "bitcoin_address": re.compile(r"\b(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39}\b"), "ethereum_address": re.compile(r"\b0x[a-fA-F0-9]{40}\b"), - # ---------- contact info ---------- "email": re.compile(r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b"), "phone_us": re.compile(r"\b(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b"), @@ -47,14 +46,12 @@ PII_PATTERNS = { "us_zip_plus4": re.compile(r"\b\d{5}-\d{4}\b"), "po_box": re.compile(r"\bP\.?O\.?\s?Box\s?\d+\b", re.IGNORECASE), "lat_long_coordinates": re.compile(r"\b-?\d{1,3}\.\d{3,},\s?-?\d{1,3}\.\d{3,}\b"), - # ---------- network / device identifiers ---------- "ipv4": re.compile(r"\b(?:\d{1,3}\.){3}\d{1,3}\b"), "ipv6": re.compile(r"\b(?:[A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}\b"), "mac_address": re.compile(r"\b(?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}\b"), "imei": re.compile(r"\b\d{15}\b"), "url_with_credentials": re.compile(r"\bhttps?://[^:\s]+:[^@\s]+@[^\s]+\b"), - # ---------- credentials / API keys / secrets ---------- "aws_access_key": re.compile(r"\b(AKIA|ASIA)[0-9A-Z]{16}\b"), "aws_secret_key": re.compile(r"\b(?=.*[A-Za-z])(?=.*\d)(?=.*[+/])[A-Za-z0-9+/]{40}\b"), @@ -79,26 +76,60 @@ def default_patterns() -> dict: PATTERN_CATEGORIES = { "government_id": [ - "ssn", "ssn_no_dash", "itin", "ein", "us_passport", "passport_generic_intl", - "drivers_license_generic", "medicare_id_us", "npi_number", "uk_nino", - "date_of_birth", "vin", + "ssn", + "ssn_no_dash", + "itin", + "ein", + "us_passport", + "passport_generic_intl", + "drivers_license_generic", + "medicare_id_us", + "npi_number", + "uk_nino", + "date_of_birth", + "vin", ], "financial": [ - "credit_card_visa", "credit_card_mastercard", "credit_card_amex", - "credit_card_discover", "credit_card_generic", "iban", "swift_bic", - "us_bank_routing", "us_bank_account", "bitcoin_address", "ethereum_address", + "credit_card_visa", + "credit_card_mastercard", + "credit_card_amex", + "credit_card_discover", + "credit_card_generic", + "iban", + "swift_bic", + "us_bank_routing", + "us_bank_account", + "bitcoin_address", + "ethereum_address", ], "contact": [ - "email", "phone_us", "phone_intl", "us_zip_plus4", "po_box", + "email", + "phone_us", + "phone_intl", + "us_zip_plus4", + "po_box", "lat_long_coordinates", ], "network_device": [ - "ipv4", "ipv6", "mac_address", "imei", "url_with_credentials", + "ipv4", + "ipv6", + "mac_address", + "imei", + "url_with_credentials", ], "credentials": [ - "aws_access_key", "aws_secret_key", "gcp_api_key", "azure_client_secret", - "github_token", "gitlab_token", "slack_token", "stripe_live_key", - "openai_api_key", "jwt", "private_key_pem", "generic_bearer_token", + "aws_access_key", + "aws_secret_key", + "gcp_api_key", + "azure_client_secret", + "github_token", + "gitlab_token", + "slack_token", + "stripe_live_key", + "openai_api_key", + "jwt", + "private_key_pem", + "generic_bearer_token", "basic_auth_header", ], } diff --git a/litellm/proxy/guardrails/guardrail_hooks/tealtiger/tealtiger.py b/litellm/proxy/guardrails/guardrail_hooks/tealtiger/tealtiger.py index 3e1f1d6d69b..6c8dc0e61f0 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/tealtiger/tealtiger.py +++ b/litellm/proxy/guardrails/guardrail_hooks/tealtiger/tealtiger.py @@ -9,6 +9,7 @@ implementation of the same interface. No network calls, no LLM calls, no external API keys required. """ + from typing import TYPE_CHECKING, Final, List, Literal, Optional from litellm.integrations.custom_guardrail import ( @@ -63,13 +64,9 @@ class TealTigerGuardrail(CustomGuardrail): if tool_name and not self.engine.check_tool(tool_name): raise ValueError(f"TealTiger: blocked — TOOL_NOT_ALLOWLISTED ({tool_name})") - over_budget, spent, limit = self.engine.check_budget( - session_id=request_data.get("user") or "default" - ) + over_budget, spent, limit = self.engine.check_budget(session_id=request_data.get("user") or "default") if over_budget: - raise ValueError( - f"TealTiger: blocked — DAILY_BUDGET_EXCEEDED (${spent:.2f} / ${limit:.2f})" - ) + raise ValueError(f"TealTiger: blocked — DAILY_BUDGET_EXCEEDED (${spent:.2f} / ${limit:.2f})") checked_texts: List[str] = [] for text in inputs.get("texts") or []: