feat: Add Brazilian Portuguese detection and Brazilian PII - #3
Open
johngrandson wants to merge 3 commits into
Open
feat: Add Brazilian Portuguese detection and Brazilian PII#3johngrandson wants to merge 3 commits into
johngrandson wants to merge 3 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds Brazilian-Portuguese support behind a new
LlmGuard.Config:languagesoption (default[:en], so existing behavior is byte-for-byte unchanged).What
:languagesoption.LlmGuard.Localebehaviour +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.Regex:indexis byte-based), so accented text no longer shifts or drops matches.Notes
LlmGuard.Utils.BrValidation).[:en]runs exactly as before.mix formatandmix compile --warnings-as-errorsare clean; CHANGELOG updated under[Unreleased].Happy to adjust naming or scope to fit the roadmap.