Skip to content

feat: Add Brazilian Portuguese detection and Brazilian PII - #3

Open
johngrandson wants to merge 3 commits into
North-Shore-AI:mainfrom
johngrandson:feat/pt-br-localization
Open

feat: Add Brazilian Portuguese detection and Brazilian PII#3
johngrandson wants to merge 3 commits into
North-Shore-AI:mainfrom
johngrandson:feat/pt-br-localization

Conversation

@johngrandson

Copy link
Copy Markdown

Adds Brazilian-Portuguese support behind a new LlmGuard.Config :languages option (default [:en], so existing behavior is byte-for-byte unchanged).

What

  • PT-BR detection patterns (one of the README's "areas seeking help"): Portuguese prompt-injection and jailbreak phrasings.
  • Brazilian PII: CPF, CNPJ (check-digit validated), CEP, phone — gated by the same :languages option.
  • Locale registry (LlmGuard.Locale behaviour + LlmGuard.Locales): adding a language is one module plus one registry entry, with no detector changes. English is the always-on base; locale packs add patterns on top.
  • Fix: PII detection and redaction now keep byte-aligned offsets on UTF-8 input (Regex :index is byte-based), so accented text no longer shifts or drops matches.

Notes

  • Zero new runtime dependencies — CPF/CNPJ validation is inline (LlmGuard.Utils.BrValidation).
  • Backward compatible: default [:en] runs exactly as before.
  • Tests pass; mix format and mix compile --warnings-as-errors are clean; CHANGELOG updated under [Unreleased].

Happy to adjust naming or scope to fit the roadmap.

Make detectors locale-aware via a small registry. A new Config `languages` option (default `[:en]`, so existing behavior is unchanged) selects locale packs that add patterns on top of the English base.

- Locale behaviour + registry (LlmGuard.Locale, LlmGuard.Locales): adding a language is one module plus one registry entry, no detector changes.
- PT-BR prompt-injection and jailbreak patterns (LlmGuard.Locales.PtBr).
- Brazilian PII (CPF, CNPJ, CEP, phone) with inline check-digit validation (LlmGuard.Utils.BrValidation), gated behind the same option.
- Keep PII byte offsets aligned on UTF-8 input (Regex :index is byte-based, so slice on bytes) so accented text no longer misaligns detection or redaction.

The option threads through the pipeline to each detector and the result-cache key, and the CrucibleIR stage adapter forwards it.
Add the `languages` option and Brazilian PII to the README (Configuration + Detected Threats) and an Unreleased CHANGELOG entry.
…stem prompt'

PT injection slipped through two gaps:
- instruction-override patterns only allowed 'todas as'/'as' between the
  verb and the noun, so a possessive ('esqueça SUAS instruções anteriores')
  did not match
- system-extraction only matched 'prompt do sistema', missing the borrowed
  English term 'system prompt' commonly used by PT speakers

Widen the optional article group to include possessives and add a
'system prompt' alternation. Benign correction phrases (esquece/ignora/
desconsidera o que falei) remain unmatched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant