Skip to main content

FinGuard โ€” Open-source LLM safety layer for financial AI

Project description

FinGuard ๐Ÿ›ก๏ธ

The LLM Safety Orchestration Layer for Financial AI.

FinGuard is a modular, plug-and-play guardrail framework built for fintech teams. It wraps any LLM with a tiered safety pipeline covering PII redaction, prompt injection detection, regulatory compliance, and financial fraud signals โ€” all configurable via simple YAML policies.

Open In Colab


โšก Quick Start

from finguard import FinGuard

guard = FinGuard(policy="retail_banking")

@guard.wrap
async def banking_assistant(prompt: str) -> str:
    return await llm.generate(prompt)

# PAN card in prompt is automatically blocked
response = await banking_assistant("My PAN is ABCDE1234F, reset my password")

๐Ÿ—๏ธ Tiered Safety Architecture

FinGuard uses a three-tier pipeline โ€” each tier adds safety depth at the cost of latency. Pick the tier that fits your use case.

Tier Policy Avg Latency What It Covers
Tier 1 โ€” Fast Lane fast_lane ~35ms Regex PII (PAN, Aadhaar, IFSC, UPI), PMLA
Tier 2 โ€” Standard retail_banking, default ~55ms Tier 1 + Native Presidio NER + Injection AI
Tier 3 โ€” Full Stack high_security, wealth_advisor ~180ms Tier 2 + Topic Banning + Compliance Phrases

Benchmarks measured on CPU (ONNX runtime, no GPU). Mock LLM latency excluded.


๐Ÿ“‹ Policy Catalog

FinGuard ships with 5 ready-to-use policies. Load by name:

guard = FinGuard(policy="high_security")
Policy Use Case Tier
default Balanced starting point for any financial bot 2
fast_lane High-throughput systems: IVR, SMS bots, dashboards 1
retail_banking Branch chatbots, net banking, UPI assistants 2
wealth_advisor Robo-advisors, portfolio managers (SEBI compliance) 3
high_security Fraud ops, compliance officers, internal audit tools 3

All policies ship with injection.threshold: 1.0 โ€” only absolute certainty triggers a block.


๐Ÿ” What Gets Protected

PII โ€” Finance Base (Always Active)

Native Presidio entities with context-awareness and checksum validation:

Entity ID Detection
Credit Card CREDIT_CARD Pattern + Luhn checksum
IBAN IBAN_CODE Pattern + checksum
PAN Card IN_PAN Pattern + context
Aadhaar IN_AADHAAR Pattern + Verhoeff checksum
IFSC Code IN_IFSC Custom pattern + context
UPI/VPA IN_VPA Custom pattern + context
Email / Phone EMAIL_ADDRESS, PHONE_NUMBER Pattern

Optional Locale Packs

pii:
  locale_packs: ["IN_EXTENDED"]  # Adds Voter ID, Passport, Vehicle Reg
  # locale_packs: ["US"]         # Adds SSN, Driver License
  # locale_packs: ["GLOBAL"]     # Adds IP, URL, Location

Fraud & Compliance

  • PMLA Scanner โ€” flags high-value transfers (>โ‚น50,000) with transfer keywords
  • Compliance Phrases โ€” enforces SEBI/RBI-style disclaimers on investment advice
  • Numerical Hallucination โ€” validates AI-stated figures against prompt context
  • Topic Banning โ€” blocks off-domain queries (crypto, medical, illegal lending)

๐Ÿงฉ Architecture

Prompt โ†’ [Tier 1: Regex Fast-Path] โ†’ [Tier 2: Presidio NER + ONNX AI] โ†’ [Tier 3: Compliance] โ†’ LLM โ†’ Output Guard โ†’ Response
  • Singleton model cache โ€” ONNX models loaded once per process, shared across all guards
  • Whitelist-only PII registry โ€” only finance-relevant recognizers are active; no BTC/SSN overhead
  • Per-component latency โ€” every GuardResult exposes component_latencies for observability

๐Ÿ“Š Benchmarking

uv run benchmark.py

Sample output:

โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  BENCHMARK SUMMARY
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  Tier                                     Avg      Min      Max
  Tier 1 โ€“ Fast Lane  (Regex)            35.0ms   30.5ms   36.9ms
  Tier 2 โ€“ Retail     (NER+AI)           54.7ms   47.3ms   65.4ms
  Tier 3 โ€“ High Sec   (Full)            181.0ms  149.2ms  277.3ms
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

๐Ÿ“ Project Structure

finguard/
โ”œโ”€โ”€ pii/                   # Native Presidio PII engine
โ”‚   โ”œโ”€โ”€ engine.py          # FinGuardPIIEngine singleton
โ”‚   โ”œโ”€โ”€ profiles.py        # Finance base + locale packs
โ”‚   โ””โ”€โ”€ recognizers.py     # Custom recognizers (IFSC, VPA, Demat)
โ”œโ”€โ”€ validators/            # Domain-specific validators
โ”‚   โ”œโ”€โ”€ financial.py       # Fast-path regex + PMLA scanner
โ”‚   โ”œโ”€โ”€ compliance.py      # Disclaimer enforcement
โ”‚   โ””โ”€โ”€ numerical.py       # Hallucination detection
โ”œโ”€โ”€ policies/              # YAML policy catalog
โ”‚   โ”œโ”€โ”€ default.yaml
โ”‚   โ”œโ”€โ”€ fast_lane.yaml
โ”‚   โ”œโ”€โ”€ retail_banking.yaml
โ”‚   โ”œโ”€โ”€ wealth_advisor.yaml
โ”‚   โ””โ”€โ”€ high_security.yaml
โ”œโ”€โ”€ core.py                # FinGuard main class
โ”œโ”€โ”€ router.py              # Scanner factory + model cache
โ””โ”€โ”€ config.py              # Pydantic policy models

โš–๏ธ License

MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

finguard-0.3.0.tar.gz (117.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

finguard-0.3.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file finguard-0.3.0.tar.gz.

File metadata

  • Download URL: finguard-0.3.0.tar.gz
  • Upload date:
  • Size: 117.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for finguard-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b3670c7422d9b85c0c89ec226d65c96f4522372cbf2f9efc95b3b4969afbe294
MD5 61f4df44b6a37ae1c5b1ef0e7a7a030b
BLAKE2b-256 3123333c68cfd9d5b98b4d1d456a16dc51b5b806c7726d07c924c073039e2617

See more details on using hashes here.

Provenance

The following attestation bundles were made for finguard-0.3.0.tar.gz:

Publisher: python-publish.yml on suryanshgupta9933/FinGuard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file finguard-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: finguard-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for finguard-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f0a604cbfe5ae0a916133035920bd32d60b27cde57f405c8ce2793b4f0590229
MD5 1c1b5f9a8fa103c33c12a16d06a34237
BLAKE2b-256 db2c6b7a691c6045ad9c2af540f890fc04ec94deb4c66db113e2cd8e1542cfbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for finguard-0.3.0-py3-none-any.whl:

Publisher: python-publish.yml on suryanshgupta9933/FinGuard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page