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

๐Ÿ” 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)

๐Ÿ•ต๏ธโ€โ™‚๏ธ Enterprise Observability & Audit

FinGuard features GuardTrace, a forensic-grade audit engine designed for SOC2 compliance and incident response. Every safety decision is fully reconstructable, without logging raw PII.

1. Multi-Backend Logging

Out-of-the-box support for:

  • NDJSON File Logging: Built for easy ingestion into Splunk, DataDog, and ElasticSearch.
  • Langfuse: Hierarchical session traces + visual violation scoring (pip install finguard[observability]).
  • OpenTelemetry: Native OTEL spans and metrics for enterprise APM (pip install finguard[observability]).
# policy.yaml
audit:
  backend: "langfuse"       # "memory" | "file" | "langfuse" | "otel"
  emit_traces: true
  redact_input: true        # Logs SHA-256 fingerprint instead of raw text
  include_metadata_keys: ["session_id", "user_id"] # Safe tracking

2. Agentic Backtracking

If FinGuard blocks an agent's tool call or prompt, it raises a structured FinGuardViolation containing the exact GuardTrace. Your agent can catch this, inspect the violation, and self-correct its plan instead of crashing:

from finguard.exceptions import FinGuardViolation

try:
    response = await banking_assistant("Process transfer for 1234-5678-9012-3456")
except FinGuardViolation as e:
    failed_scanners = [s.scanner for s in e.trace.input_scanners if s.triggered]
    if "presidio_pii" in failed_scanners:
        print("Self-correcting: removing PII and retrying...")

๐Ÿงฉ 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
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

โš–๏ธ 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.1.tar.gz (185.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.1-py3-none-any.whl (38.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: finguard-0.4.1.tar.gz
  • Upload date:
  • Size: 185.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.1.tar.gz
Algorithm Hash digest
SHA256 271d218bcf2becd8eac0d8ab603aa1189cc88cdd36d9d4757a29a35bc521104e
MD5 08fcfdccb1dbac43464492cd4dee6de3
BLAKE2b-256 c48a94e4847bb83cf4684c6e7b42bd892263dfa0469b1d9242968bfb9fffc2e5

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: finguard-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 38.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 62f8644bf4edb579d0a6e2a7b37ffae374108fc6b39143d5ce9aa8b8dc8293c4
MD5 1709d9c15e69f67997cee902d713a50c
BLAKE2b-256 d0c034934c035cc9b08ba37344b6db4486cad163cb9b22669fdda3483624be18

See more details on using hashes here.

Provenance

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