ai_guardrails 0.6.0
ai_guardrails: ^0.6.0 copied to clipboard
On-device, provider-agnostic input/output safety for Dart & Flutter AI apps: PII redaction, prompt-injection and secret detection, output validation.
Changelog #
0.6.0 #
- International PII expansion — 6 new locales: Brazil (CPF, CNPJ), Mexico (CURP, RFC), Japan (My Number), South Korea (RRN), Canada (SIN with Luhn validation), Australia (TFN, Medicare). Each with country-specific phone patterns.
- EU country-specific phones — replaced the single generic EU phone regex with dedicated patterns for UK (+44), Germany (+49), France (+33), Italy (+39), and Spain (+34). Reduces false positives on partial matches.
- RTL text verification — verified all scanners produce correct offsets on Arabic and Hebrew text with embedded PII. Redaction preserves RTL structure.
PiiLocaleenum expanded — addedbrazil,mexico,japan,southKorea,canada,australia.fromConfigsupports all locale names.PiiPattern.luhnMinDigits— per-pattern Luhn minimum digit count (default 12 for credit cards, 9 for Canadian SIN).
0.5.0 #
GuardLog— structured, JSON-serializable audit record of every scan. Contains scanner chain results, findings, text hashes (never raw text), and timestamps. Wire to any logging backend viaAiGuard.onScancallback.GuardMetrics— per-run metrics snapshot: total/input/output duration, block status, finding counts, per-scanner breakdown. Wire to dashboards viaAiGuard.onMetricscallback.AiGuard.fromConfig()— build a completeAiGuardfrom aMap<String, dynamic>(JSON). Declare scanner chains, thresholds, and actions without code changes. Deploy policy updates without recompilation. Supports all 13 scanner types.
0.4.0 #
StreamingAiGuard— streaming wrapper for chunked LLM responses. Buffers incoming chunks, splits at configurable boundaries (default: newline), runs output scanners on each segment, yieldsGuardedChunks. Terminates the stream on block. PII rehydration works per-chunk. Input scanning is identical toAiGuard. Scanners see each segment independently — useAiGuardfor full-output scanning (e.g.SchemaValidator) after the stream completes.GroundingScanner— checks whether LLM output is grounded in a provided source context via keyword-overlap heuristic. Extracts content words (non-stop- words), computes overlap ratio, flags text when grounding falls below threshold. Finding type:grounding.unsupported_claim. Default action:warn.StageRun— exposed as public API forStreamingAiGuardand advanced use cases.AiGuard.runInputStage()andAiGuard.runOutputStage()return full stage results including redaction maps.
0.3.0 #
UrlScanner— detects suspicious URLs: IP-literal hosts,data:/javascript:URIs, phishing TLDs (.tk,.buzz,.zip, etc.), URL shorteners, punycode (homograph attacks), and embedded credentials. Configurable categories viaUrlCategoryenum. Runs on input and output.LanguageScanner— script-detection heuristic using Unicode character-class ratios (Latin, Cyrillic, CJK, Devanagari, Arabic, Greek, Hangul, Hiragana, Katakana, Thai). Flags text when the expected-script fraction falls below a threshold. Catches cross-script prompt injection and unexpected language switches.CodeExecutionScanner— detects dangerous patterns in generated code: shell commands (rm -rf,curl|sh,dd,chmod 777), SQL destruction (DROP TABLE,TRUNCATE,DELETE FROM), code injection (eval,exec,os.system,subprocess,Process.start), and filesystem deletion (shutil.rmtree,unlink). Configurable categories viaCodeCategoryenum. Output-stage only.
0.2.0 #
- PII round-trip rehydration —
AiGuard.run()now automatically restores redacted PII in the LLM output. Placeholders like[EMAIL_1]in the model response are replaced with the original values sooutcome.outputreads naturally.outcome.rawOutputpreserves the pre-rehydration text;outcome.piiMapexposes the placeholder→original map for manual control. - Numbered redaction placeholders —
PiiScannernow produces unique tokens per occurrence ([EMAIL_1],[EMAIL_2]) instead of a shared[EMAIL]. Hash-mode placeholders ([EMAIL:a1b2c3]) are unchanged (already unique). ScanResult.redactionMap— any scanner that transforms text can now populate aMap<String, String>of token→original.AiGuardmerges maps across chained scanners.RepetitionScanner— detects degenerate model output (looping / repeated phrases) via word-level n-gram frequency analysis. Configurable n-gram size and threshold; output-stage only.
0.1.0 #
Initial release.
AiGuardorchestrator with chained input/output pipelines: redacting scanners chain (each sees the previous scanner's transformed text) and the pipeline stops at the first scanner that blocks.- Eight scanners:
PiiScanner— PII detection/redaction across US/EU/India locales, with a Luhn check on credit-card matches.SecretScanner— API keys, tokens, and private-key blocks.PromptInjectionScanner— heuristic weighted scoring of injection signals.BannedTopicScanner— word-boundary topic matching.BannedPatternScanner— arbitraryPattern/RegExpmatching.TokenLimitScanner— approximate token-count ceiling.InvisibleTextScanner— zero-width, bidi, soft-hyphen, and tag-char removal.SchemaValidator— minimal JSON-Schema-subset validation of model output.
- Pure Dart, on-device, zero runtime dependencies.