Commit Graph
16 Commits
Author SHA1 Message Date
ff8e01d20b feat: Add Canadian PII protection (PIPEDA) (#22951)
* feat: Add Canadian PII protection patterns and PIPEDA-compliant policy template

Adds 6 new Canadian PII regex pattern detectors to patterns.json:
- ca_sin: Social Insurance Number (PIPEDA Privacy Act, Income Tax Act)
- ca_ohip: Ontario Health Insurance Plan Number (PHIPA)
- ca_on_drivers_licence: Ontario driver's licence (HTA, PIPEDA)
- ca_immigration_doc: IRCC immigration docs (UCI, work/study permits, IMM refs)
- ca_bank_account: Canadian bank account routing (transit-institution-account)
- ca_postal_code: Canadian postal code (Canada Post spec)

Adds comprehensive policy template 'canadian-pii-protection' (id: canadian-pii-protection)
with 5 sub-guardrails grouping patterns by data type. All patterns include contextual
keyword matching (English + French keywords where applicable) to reduce false positives.
Complements existing passport_canada pattern.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>

* feat: Add Canadian PII compliance dataset and tests (57 tests)

Adds:
- test_ca_patterns.py: 30 unit tests for regex pattern matching (SIN, OHIP,
  driver's licence, immigration docs, bank account, postal code)
- test_ca_policy_e2e.py: 27 end-to-end tests running the full
  ContentFilterGuardrail pipeline with MASK action — validates detection
  of real PII and pass-through of clean prompts
- canadianPiiCompliancePrompts.ts: 21-prompt compliance dataset for UI
  evaluation, wired into the main compliancePrompts framework

Fixes keyword_pattern alternation ordering in patterns.json — longer
alternatives (e.g. "social insurance number") now precede shorter ones
("social insurance") to avoid excessive gap-word count when the regex
engine selects the shorter match first.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>

* feat: Add University of Toronto FIPPA identifier patterns and tests (36 tests)

Add 3 UofT institutional identifiers (student/employee number, UTORid, TCard)
covered under Ontario FIPPA. Includes pattern definitions, policy template
sub-guardrail, compliance prompts, unit tests, and e2e tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: Correct test assertion bug and inaccurate docstring

Fix test_utorid_masked checking `result` (dict) instead of `output` (string).
Update test_ca_policy_e2e.py docstring to clarify scope vs UofT tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: Address Greptile review feedback

- Tighten ca_postal_code keyword_pattern: replace broad "address" with
  specific compound terms (mailing/street/shipping/home address)
- Add missing "PIPEDA" tag to policy_templates.json for discoverability
- Add us_phone pattern to test_ca_policy_e2e.py setup to match deployed template
- Add phone number e2e test for complete coverage

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: Tighten patterns to reduce false positives and add missing test coverage

- ca_sin: reject leading-zero SINs ([1-9]\d{2}), set allow_word_numbers to false
- ca_immigration_doc: require separators in UCI pattern (prevent bare \d{10} match)
- uoft_utorid: qualify generic keywords (acorn -> acorn login, quercus -> quercus login)
- uoft_tcard: remove generic keywords (student card, id card, library card) that
  overlap with credit card contexts; keep only UofT-specific terms (tcard, campus card)
- Add visa/mastercard/amex/iban patterns to test_ca_policy_e2e.py setup to match
  deployed template; add Visa card masking test
- Add test verifying "student card" no longer triggers TCard redaction

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-06 18:27:31 -08:00
c2c8870d2d Add claims agent guardrails (5 categories + policy template) (#22113)
* Add claims agent guardrails with 243-case eval dataset

5 new category guardrails for healthcare claims agent chatbots:
- claims_fraud_coaching: fraud coaching, exaggeration, document forgery
- claims_phi_disclosure: unauthorized PHI access, bulk data extraction
- claims_prior_auth_gaming: code manipulation, medical necessity misrepresentation
- claims_system_override: system injection, rule bypass, role impersonation
- claims_medical_advice: medical advice (claims-context-aware)

Plus claims_agent_safety.yaml policy template combining all 5.

All 5 eval suites pass at 100% precision/recall/F1 (243 test cases).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add claims agent chatbot safety policy template

Combines the 5 claims guardrails into a single deployable policy template:
fraud coaching, PHI disclosure, prior-auth gaming, system override, and medical advice.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add guardrail benchmark results and UI compliance prompts

Adds benchmark results for claims, discrimination, and content filter guardrails.
Updates UI compliance prompt data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Remove duplicate "file an appeal" exception in claims_prior_auth_gaming.yaml

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Remove unused claims_agent_safety.yaml policy template

The claims-agent-safety template in policy_templates.json references
individual category files in categories/, not this combined file.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 18:09:38 -08:00
Ron ZhongandGitHub 4dcec49070 refactor(policies): update guardrail identifiers for Singapore compliance (#21974) 2026-02-23 20:53:26 -08:00
Ron ZhongandGitHub 73fd5a41e4 feat: Singapore guardrail policies (PDPA + MAS AI Risk Management) (#21948)
* feat: Singapore PDPA PII protection guardrail policy template

Add Singapore Personal Data Protection Act (PDPA) guardrail support:

Regex patterns (patterns.json):
- sg_nric: NRIC/FIN detection ([STFGM] + 7 digits + checksum letter)
- sg_phone: Singapore phone numbers (+65/0065/65 prefix)
- sg_postal_code: 6-digit postal codes (contextual)
- passport_singapore: Passport numbers (E/K + 7 digits, contextual)
- sg_uen: Unique Entity Numbers (3 formats)
- sg_bank_account: Bank account numbers (dash format, contextual)

YAML policy templates (5 sub-guardrails):
- sg_pdpa_personal_identifiers: s.13 Consent
- sg_pdpa_sensitive_data: Advisory Guidelines
- sg_pdpa_do_not_call: Part IX DNC Registry
- sg_pdpa_data_transfer: s.26 overseas transfers
- sg_pdpa_profiling_automated_decisions: Model AI Governance Framework

Policy template entry in policy_templates.json with 9 guardrail definitions
(4 regex-based + 5 YAML conditional keyword matching).

Tests:
- test_sg_patterns.py: regex pattern unit tests
- test_sg_pdpa_guardrails.py: conditional keyword matching tests (100+ cases)

* feat: MAS AI Risk Management Guidelines guardrail policy template

Add Monetary Authority of Singapore (MAS) AI Risk Management Guidelines
guardrail support for financial institutions:

YAML policy templates (5 sub-guardrails):
- sg_mas_fairness_bias: Blocks discriminatory financial AI (credit/loans/insurance by protected attributes)
- sg_mas_transparency_explainability: Blocks opaque/unexplainable AI for consequential financial decisions
- sg_mas_human_oversight: Blocks fully automated financial decisions without human-in-the-loop
- sg_mas_data_governance: Blocks unauthorized sharing/mishandling of financial customer data
- sg_mas_model_security: Blocks adversarial attacks, model poisoning, inversion on financial AI

Policy template entry in policy_templates.json with 5 guardrail definitions.
Aligned with MAS FEAT Principles, Project MindForge, and NIST AI RMF.

Tests:
- test_sg_mas_ai_guardrails.py: conditional keyword matching tests (100+ cases)

* fix: address SG pattern review feedback

- Update NRIC lowercase test for IGNORECASE runtime behavior
- Add keyword context guard to sg_uen pattern to reduce false positives

* docs: clarify MAS AIRM timeline references

- Explicitly mark MAS AIRM as Nov 2025 consultation draft
- Add 2018 qualifier for FEAT principles in MAS policy descriptions
- Update MAS guardrail wording to avoid release-year ambiguity

* chore: commit resolved MAS policy conflicts

* test:

* chore:
2026-02-23 12:08:22 -08:00
Ishaan JaffandGitHub 655973e8c8 feat(ui): show latency overhead for AI-suggested policy templates (#21620)
* feat(policy): add estimated_latency_ms to all policy templates

* feat(policy): add estimated_latency_ms to backup templates

* feat(ui): show latency overhead badge in AI policy suggestions
2026-02-19 15:45:07 -08:00
Ishaan JaffandGitHub 1a5133f229 Competitor guardrails: streaming discovery, variations, pre/post split (#21533)
* fix aviation safety topic filter: remove overly broad exceptions, add cockpit access block words

* fix airline brand protection filter: add identifier words, competitor/ops block words, tighten exceptions

* update policy templates with competitor pre/post guardrails and streaming enrichment

* sync policy_templates_backup.json with policy_templates.json

* add streaming enrichment endpoint, competitor variations, and model selection

* add streaming enrichPolicyTemplate networking function

* rewrite template parameter modal with streaming tags, AI/manual toggle, model selector

* update policies panel to pass enrichment options and show discovered competitors

* show discovered competitors as tags in guardrail selection modal

* use llm_router instead of litellm.acompletion, extract helpers, move constants

* validate competitors list size, cap variation prompt input

* add refinement instruction support for competitor discovery

* add instruction and existingCompetitors params to streaming enrichment

* add refinement input for iterating on competitor list with AI

* emit status events during variation generation so UI shows progress

* add onStatus callback to streaming enrichment

* show status spinner during variation generation, widen modal to 700px

* add tests for competitor enrichment helper functions
2026-02-18 21:39:19 -08:00
Ishaan JaffandGitHub 91fd2b4621 Add aviation and UAE policy templates with tag-based filtering (#21518)
* add aviation and UAE regex patterns (PNR, Skywards, Emirates ID, UAE phone, flight number)

* add aviation safety topics category yaml

* add airline brand protection category yaml

* add UAE cultural sensitivity category yaml

* add UAE anti-discrimination category yaml

* add aviation, UAE, and competitor policy templates + migrate region/type to tags

* sync policy_templates_backup.json

* add /policy/templates/enrich endpoint for LLM competitor discovery

* add enrichPolicyTemplate networking call

* add TemplateParameterModal component

* handle parameterized templates and LLM enrichment in policies index

* replace region/type radio filters with tag sidebar checkboxes
2026-02-18 18:26:24 -08:00
371cabfebd Add MCP Security guardrail to block unregistered MCP servers (#21429)
* Add MCP_SECURITY enum to SupportedGuardrailIntegrations

* Add MCP security guardrail initializer

* Add MCPSecurityGuardrail implementation

* Add MCP Security policy template

* Add Type filter to policy templates UI

* Add unit tests for MCP security guardrail

* fix(lint): remove unused Dict import from mcp_security_guardrail

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Add French language support for EU AI Act Article 5 guardrail (#21427)

* Add French language support for EU AI Act Article 5 template

- Create eu_ai_act_article5_fr.yaml with comprehensive French keywords
- Includes identifier words: concevoir, créer, développer, noter, classer, etc.
- Includes block words: crédit social, comportement social, émotion des employés, etc.
- Includes always-block keywords for explicit prohibited practices
- Includes exceptions for research, compliance, and legitimate use cases
- Catches circumvention attempts with phrase variations

* Add comprehensive tests for French EU AI Act guardrail

- Test 3 critical scenarios: blocked query, circumvention attempt, safe query
- Test edge cases: case-insensitive, mixed language, research exceptions
- All 7 tests passing
- Validates both blocking and allowing behavior

* Fix content filter to support conditional matching without inherit_from

- Enable conditional matching when identifier_words + additional_block_words are present
- Previously required inherit_from, but EU AI Act templates are self-contained
- Fixes Greptile feedback: conditional matching now works as documented

* Add pure conditional matching test for French guardrail

- Test identifier + block word combinations not in always_block_keywords
- Verifies conditional matching works independently
- Addresses Greptile feedback about test coverage gap

* Fix exception word bypass risk in French template

- Replace short words (film, jeu, juste) with context-specific phrases
- Prevents substring matching bypasses (e.g., enjeu matching jeu)
- Add tests for bypass prevention and legitimate game context
- Addresses Greptile security feedback

* Make conditional match assertion more robust

- Use getattr to safely access exception detail field
- Check if detail is dict before calling .get()
- Addresses Greptile feedback about brittle string assertion

* Add French EU AI Act Article 5 policy template to registry

- Add eu-ai-act-article5-fr template for French language support
- Includes French description and guardrail info
- Matches structure of English template

* Address greptile review feedback (greploop iteration 1)

- Use status_code=400 instead of 403 to match guardrail logging convention
- Use prefix stripping instead of split('/')[-1] for robust server name extraction

* remove French EU AI Act template from policy_templates.json

---------

Co-authored-by: Julio Quinteros Pro <jquinter@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-17 21:19:13 -08:00
5b5306a540 feat: split EU AI Act Article 5 into 5 dedicated sub-guardrails per language (#21453)
Break the monolithic EU AI Act Article 5 policy template into 5 focused
sub-guardrails, each covering a specific prohibited practice:

- Art. 5.1(a) — Subliminal Manipulation & Deceptive Techniques
- Art. 5.1(b) — Exploitation of Vulnerabilities (children, elderly, disabled)
- Art. 5.1(c) — Social Scoring Systems
- Art. 5.1(f) — Emotion Recognition in Workplace & Education
- Art. 5.1(d)(g)(h) — Biometric Categorization & Predictive Profiling

Each sub-guardrail has expanded keyword coverage specific to its domain.
Includes both English and French versions (10 total sub-guardrails).
Original monolithic YAML files preserved for backward compatibility.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-17 20:43:25 -08:00
Ishaan Jaffer ecda49e05c fix remplate 2026-02-17 16:45:48 -08:00
Ishaan Jaffer 764b9ba9f8 eu_ai_act_article5_prohibited_practices_fr 2026-02-17 16:27:59 -08:00
Ishaan JaffandGitHub f2480f4f37 Fix EU AI Act template: add missing category_file path (#21424)
The EU AI Act template was missing the category_file path in the guardrail definition, causing the guardrail to fail silently - it would be created in the database but wouldn't load the YAML rules file.

Without the category_file, the guardrail has no actual blocking rules, so prompts like "social credit system" pass through even though they should be blocked.

Adds the category_file path pointing to the eu_ai_act_article5.yaml file so the guardrail can load its rules.

Tested:
- Before fix: "social credit system" → 200 OK (passes through)
- After fix: "social credit system" → 403 blocked (works correctly)
2026-02-17 15:07:23 -08:00
Ishaan JaffandGitHub cea1279afe Add EU AI Act Article 5 template to policy templates UI (#21414)
* Add EU AI Act Article 5 template to policy templates

Adds the EU AI Act Article 5 - Prohibited Practices template to the policy templates JSON that the UI reads from.

The template uses the eu_ai_act_article5_prohibited_practices category that was added in PR #21342. Blocks prompts requesting:
- Social scoring systems
- Emotion recognition in workplace/education
- Biometric categorization for sensitive attributes
- Predictive profiling and manipulation

Shows up in the UI under EU region filter with High complexity.

* Update policy templates backup with EU AI Act template

Syncs the backup file with the main policy_templates.json to include the EU AI Act Article 5 template.
2026-02-17 13:49:52 -08:00
Ishaan JaffGitHubgreptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1a8525d02a Add GDPR Art. 32 EU PII Protection Policy Template (#21340)
* Add 6 new EU PII patterns for GDPR compliance

- fr_nir: French Social Security Number (NIR/INSEE) with validation
- eu_iban_enhanced: Enhanced IBAN detection with specific format
- fr_phone: French phone numbers (+33, 0033, 0 formats)
- eu_vat: EU VAT identification numbers (all 27 member states)
- eu_passport_generic: Generic EU passport format
- fr_postal_code: French postal codes with contextual keywords

* Add GDPR Art. 32 EU PII Protection policy template

- Comprehensive GDPR Article 32 compliance policy
- 4 guardrail groups: National IDs, Financial, Contact Info, Business IDs
- Masks French NIR/INSEE, EU IBANs, French phones, EU VAT numbers
- Includes EU passport numbers and email addresses
- Medium complexity template with indigo icon

* Add comprehensive tests for EU PII patterns

- Test French NIR validation (sex digit, month range)
- Test enhanced IBAN detection (French, German)
- Test French phone number formats
- Test EU VAT numbers
- Test generic EU passport format
- Test French postal code pattern

* Add EU pattern loading and category validation tests

- Verify all 6 EU PII patterns are loaded correctly
- Verify patterns are categorized as 'EU PII Patterns'
- Ensure pattern loading consistency

* Add end-to-end tests for GDPR policy template

- 4 tests for PII that should be masked (NIR, IBAN, phone, VAT)
- 4 tests for text that should pass through (invalid patterns, no PII)
- 1 bonus test for multiple PII types in same message
- All tests verify correct masking behavior

* Add region field to policy templates

- Added region field to all 6 templates (EU, AU, Global)
- Updated both main and backup JSON files
- Enables region-based filtering in UI

* Add region filter to policy templates UI

- Added Radio.Group filter for regions (All, AU, EU, Global)
- Efficient filtering with useMemo hooks
- Clean button-based UI matching existing design
- Defaults missing regions to Global

* Apply suggestion from @greptile-apps[bot]

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Address Greptile review: add contextual guards and negative tests

- Added keyword_pattern to eu_vat (VAT, tax number, fiscal code, etc.)
- Added keyword_pattern to eu_passport_generic (passport, travel document, etc.)
- Added 3 negative unit tests for false positive prevention
- Added 2 E2E tests verifying no masking without keyword context
- All patterns now require contextual keywords to prevent false positives

* address greptile review feedback (greploop iteration 1)

- Remove unused HTTPException import from test file
- Add keyword_pattern to eu_vat for contextual VAT matching
- Add allow_word_numbers: false to eu_passport_generic
- Add negative test cases for EU VAT false positives
- All 5 Greptile comments addressed

* Address Greptile feedback: fix patterns and sync backup

- Fix fr_phone pattern: use negative lookbehind (?<!\d) to prevent false matches in longer digit strings
- Add keyword_pattern to eu_passport_generic to reduce false positives on version strings/SKUs
- Sync policy_templates_backup.json with main file (add GDPR template)
- Add keyword_pattern to eu_vat (was auto-added by formatter)

All pattern tests passing

* address greptile review feedback (greploop iteration 2)

- Update test to document that eu_vat raw pattern is intentionally broad
- Test verifies pattern DOES match common words (by design)
- Documents that keyword_pattern guard prevents false positives in production
- Addresses Greptile's false positive risk concern

* address greptile review feedback (greploop iteration 3)

- Fix test_eu_vat_masked: change gap from 2 words to 1 word (VAT number: FR...)
- This ensures keyword matching works within MAX_KEYWORD_VALUE_GAP_WORDS=1 limit
- fr_phone pattern already works correctly (verified with tests)
- test_pattern_requires_keyword_context already updated in iteration 2

Addresses final issues from Greptile 2/5 review

* fix: remove country-specific passport patterns from GDPR template

- Remove passport_france, passport_germany, passport_netherlands from template
- These patterns lack keyword guards and cause false positives
- Only eu_passport_generic remains (has keyword_pattern guard)
- Sync policy_templates_backup.json with main file
- Update test setup to match template

All 11 E2E tests now passing 

* Update tests/test_litellm/proxy/guardrails/guardrail_hooks/content_filter/test_gdpr_policy_e2e.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Update litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/content_filter.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-02-16 15:28:46 -08:00
Krish DholakiaandGitHub e41ecc7a71 Guardrails - add nsfw policy template, toxic keywords in multiple languages, child safety content filter, json content viewer (#21205)
* fix(content_filter.py): fix filter on toxic keywords

* feat: improve toxic/abusive language detection

* fix: additional improvements to nsfw filters

* feat: more improvements to nsfw filter

* feat(content_filter.json): add new australia specific nsfw content filter

ensure complete coverage for australia nsfw

* fix: cleanup policy templates

* fix(index.tsx): alert notice

* fix(index.tsx): add disclaimer notice

* feat(harmful_child_safety.yaml): new child safety content filter

ensure we catch inappropriate, child-specific content

* feat(policy_templates.json): add child safety and self harm filters

* fix(content_filter.py): improve racial bias filter to use a similar identifier + block word pattern and cover a wider range of ethnicities

* feat(policy_templates.json): add racial bias to nsfw policy template

* feat: add json content viewer
2026-02-14 09:41:55 -08:00
Krish DholakiaandGitHub 24b56a14eb Guardrails - new Policy Templates (pre-configured guardrail combinations for specific use-cases) (#21025)
* feat(patterns.json): add australia specific pii patterns - tax file number, abn, medicare number

Improve PII detection for australian contexts

* feat(patterns.json): add iban + street address pattern detection

* feat: support policy templates on ui

allows admin to enable pre-configured guardrails

helps cover specific use-cases well

* feat: create missing guardrails, working policy templates

* feat: policy_templates.json

support hosted policy templates

allows others to contribute to the policy templates

* docs: document new policy templates

* fix: address greptile feedback

* fix: fix linting error
2026-02-13 11:53:02 -08:00