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

Installation

# Recommended for standard use
pip install finguard

# REQUIRED for Optimized (ONNX) latency in environments like Google Colab
pip install finguard onnxruntime optimum

# (Optional but Recommended) Pre-fetch models to avoid first-run latency
finguard-download
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

[0.3.1] - 2026-03-28

Added

  • Model Pre-fetching: New finguard-download CLI command and FinGuard.download_models() method to pre-cache all ONNX models. This eliminates the first-run latency hit.
  • CLI Utility: Added [project.scripts] entry for easy environment setup.

[0.3.0] - 2026-03-28

  • Native presidio integration with model packs configuration for faster PII detection and anonymization.
  • 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.4.0.tar.gz (171.6 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.4.0-py3-none-any.whl (34.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for finguard-0.4.0.tar.gz
Algorithm Hash digest
SHA256 ec891d3d3b451a53f3da176169031853085022233da2d912b3bb43880834602b
MD5 f8e962e9390f77666f8969cf1b2d4fca
BLAKE2b-256 4ac91096a2172b13f2cbf4fbf2e7f702f66a6d618a640ba91e67e67b45f85c4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for finguard-0.4.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.4.0-py3-none-any.whl.

File metadata

  • Download URL: finguard-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 34.3 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20c61fafc194fcede6b956237d60cc118ff2c5dd06d99cc519bc438f42ae3529
MD5 0acc6decd1b0088d6dc4ce66e5328add
BLAKE2b-256 7c62de2313a4905c81a927640b698a33b7301a62da6631db7941a40673740caf

See more details on using hashes here.

Provenance

The following attestation bundles were made for finguard-0.4.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