mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-12 08:42:18 +00:00
fix(guardrails): reject invalid UK NINO prefix letters
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
945c802373
commit
5baeebe516
2 changed files with 32 additions and 1 deletions
|
|
@ -628,7 +628,7 @@
|
|||
{
|
||||
"name": "uk_nino",
|
||||
"display_name": "National Insurance Number (UK)",
|
||||
"pattern": "\\b(?!BG|GB|KN|NK|NT|TN|ZZ)[A-CEGHJ-PR-TW-Z]{2}\\s?\\d{2}(?:\\s?\\d{2}){2}\\s?[A-D]\\b",
|
||||
"pattern": "\\b(?!BG|GB|KN|NK|NT|TN|ZZ)[ABCEGHJKLMNOPRSTWXYZ][ABCEGHJKLMNPRSTWXYZ]\\s?\\d{2}(?:\\s?\\d{2}){2}\\s?[A-D]\\b",
|
||||
"category": "UK PII Patterns",
|
||||
"description": "Detects UK National Insurance numbers with valid prefixes and suffixes",
|
||||
"keyword_pattern": "\\b(?:national\\s*insurance\\s*number|national\\s*insurance|NI\\s*number|NI\\s*no\\.?|NINO)\\b",
|
||||
|
|
|
|||
|
|
@ -107,6 +107,37 @@ async def test_invalid_uk_pii_format_passes_unchanged(
|
|||
assert valid_value not in output
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"invalid_prefix",
|
||||
(
|
||||
"DA",
|
||||
"FA",
|
||||
"IA",
|
||||
"QA",
|
||||
"UA",
|
||||
"VA",
|
||||
"AD",
|
||||
"AF",
|
||||
"AI",
|
||||
"AO",
|
||||
"AQ",
|
||||
"AU",
|
||||
"AV",
|
||||
),
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_uk_nino_rejects_disallowed_prefix_letters(invalid_prefix: str) -> None:
|
||||
guardrail: Final = _guardrail_for("uk_nino")
|
||||
text: Final = f"national insurance number: {invalid_prefix}123456A"
|
||||
result: Final = await guardrail.apply_guardrail(
|
||||
inputs={"texts": [text]},
|
||||
request_data={},
|
||||
input_type="request",
|
||||
)
|
||||
|
||||
assert result["texts"][0] == text
|
||||
|
||||
|
||||
def test_uk_policy_templates_reference_available_prebuilt_patterns() -> None:
|
||||
patterns_file: Final = REPO_ROOT / "litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/patterns.json"
|
||||
pattern_names: Final = {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue