FLAGSHIP #4 · REGULATED FINTECH & STATUTORY COMPLIANCE ✓ GitHub Actions CI Passing ↗ MIT License · Python

TRACE: FinCEN AML & SAR Compliance Engine

Two-Stage Bank Secrecy Act (BSA) AML Investigation & FinCEN Form 111 SAR Filing Engine with Mandatory HITL Compute Gating & Cryptographic SHA-256 Audit Trails

OpenAIPydantic v2Chain-of-ThoughtReACTHITLSHA-256 AuditPythonGitHub Actions
31 / 31
Automated Compliance Tests
Schema, Citations & Hash Gates
50% Saved
Stage-2 Compute Avoidance
Early HITL Non-Filing Halts
<= 120 w
FinCEN Form 111 Narratives
10 Verified Statutory Filings
SHA-256
Tamper-Evident Audit Trail
AUTH_* + Amendment Lineage
01 · Production Engineering Scorecard

Six-Pillar Production Readiness Matrix

How this system enforces security, observability, fault isolation, unit economics, and automated verification beyond notebook prototypes.

Regulatory Invariants ✓ BSA / FINCEN

Automated rules never self-authorize a SAR: qualifying alerts stay PENDING_REVIEW until an explicit human AUTH_* record is logged.

Statutory Citation Gate ✓ REGEX BOUNDED

Enforces conduct-grounded citations (31 CFR 1020.320, 31 USC 5324, 18 USC 1956), rejecting fabricated or mismatched statutes.

Cryptographic Integrity ✓ SHA-256 SEALED

Seals every filed FinCEN Form 111 JSON/text package with a deterministic SHA-256 verification_checksum and human amendment history.

Substantive Validation ✓ 6-FACTOR GATE

Verifies subject identity, transactional verbs, explicit dates, actual dollar totals (rejecting $10,000-only placeholders), <= 120 words, and qualified language.

Compute & Cost Control ✓ 50% AVOIDED

Positioning the HITL gate between Stage-1 CoT screening and Stage-2 ReACT drafting eliminates 100% of Stage-2 LLM calls on non-escalated alerts.

Fault-Tolerant Parsing ✓ BOUNDED RETRY

Implements schema-guided regeneration on malformed JSON and returns explicit terminal failure contracts rather than fabricating AML classifications.

02 · Architecture & Control Flow

System Topology & Failure-Mode Lifecycles

End-to-end execution graph paired with nominal request flow and adversarial / degraded fault-handling paths.

flowchart LR
    A["Customer + Account + Txn CSVs<br/>(Pydantic v2 Schemas)"] --> B["Stage 1: RiskAnalystAgent<br/>(5-Step CoT · 5 AML Typologies)"]
    B --> C{"Mandatory Officer<br/>HITL Gate"}
    C -- "Dismiss / Defer (50%)" --> D["Immutable JSONL Audit Record<br/>(Zero Stage-2 LLM Spend)"]
    C -- "Authorize SAR" --> E["Stage 2: ComplianceOfficerAgent<br/>(ReACT <=120w + Statutory Allowlist)"]
    E --> F["Filed FinCEN SAR (.json + .txt)<br/>+ SHA-256 Integrity Checksum"]

✓ Nominal Production Request Path

  1. Customer profile, accounts, and transaction ledgers enter Stage-1 RiskAnalystAgent (Chain-of-Thought velocity, sanctions & $10k CTR proximity analysis).
  2. High-risk structuring case (CUST_0018: four sub-$10k cash deposits across 3 branches = $37,536.45) pauses at the Mandatory Compliance Officer HITL Gate.
  3. Officer records AUTH_3AFB9AA2 approval in workflow_integration.jsonl, unlocking Stage-2 ComplianceOfficerAgent (ReACT statutory synthesis).
  4. 6-factor validator confirms 37-word narrative, 31 USC 5324 citation, and exact dollar sum, sealing SAR_20261019_15EED0C0.json with SHA-256.

✕ Adversarial, Policy & Fault-Handling Paths

  • Benign / explained high-value transaction rejected at HITL gate bypasses Stage-2 completely (0 ReACT tokens billed, full decision logged).
  • Draft narrative exceeding 120 words, asserting unqualified criminal intent, or omitting exact transaction sums fails foundation_sar.py validation.
  • Attempt to invoke Stage-2 SAR filing without a matching case_id + customer_id + AUTH_* authorization event raises an immediate integrity error.
  • Post-filing arithmetic correction by Senior BSA Officer appends an immutable amendment_history entry rather than silently overwriting audit state.
03 · Code-Grounded Implementation

Production-Ready Technical Features

Every capability below links directly to the verified source module, policy configuration, or CI workflow in kenseiAmit/trace-aml-sar-compliance-engine.

04 · Engineering Trade-Offs (ADRs)

Why This Architecture Over Naive Prototypes?

Key architectural decisions balancing determinism, latency, cost, privacy, and operational maintainability.

Architectural Decision Naive Prototype Anti-Pattern Production Engineering Choice & Outcome
Two-Stage CoT -> HITL -> ReACT Split vs. End-to-End Auto-SAR Generating SAR narratives automatically for every flagged transaction—wasting tokens on false positives and violating BSA human-review mandates. Hard HITL authorization boundary cuts Stage-2 compute by 50% and guarantees cryptographic AUTH_* accountability before FinCEN Form 111 generation.
Substantive Monetary & Phrasing Gates vs. Length-Only Check Accepting any LLM paragraph under 120 words, even if it cites $10,000 threshold boilerplate or accuses the customer of a crime. Deterministic validator enforcing exact source-transaction dollar totals ($37,536.45) and qualified regulatory phrasing.
Append-Only amendment_history + SHA-256 Checksums Mutating JSON files in place during compliance edits, destroying audit provenance for bank examiners. Explicit amendment records (prior_value, new_value, reason, reviewed_by) paired with SHA-256 checksums.
05 · Verified Execution Evidence

Empirical Telemetry, Dashboards & Runtime Traces

Recorded execution traces, benchmark sweeps, and raw repository JSON artifacts.

Verified Runtime Artifact · trace-aml-sar-compliance-engine · SAR_20261019_15EED0C0
{
  "sar_metadata": {
    "sar_id": "SAR_20261019_15EED0C0",
    "filing_date": "2026-10-19T19:08:45.135570",
    "filing_type": "Suspicious Activity Report (FinCEN Form 111)",
    "ai_generated": true,
    "ai_system": "TRACE Transactional Risk Analysis & Compliance Engine",
    "review_status": "human_approved",
    "verification_checksum": "f9ea02878e85f259adf1e6ce01d35b6242f1c2a6269ccff1214deb9d60a30ba3",
    "authorization_event_id": "AUTH_3AFB9AA2",
    "amendment_history": [
      {
        "amendment_id": "AMD_20261021_20261019",
        "amendment_date": "2026-10-21T18:00:00Z",
        "field": "suspicious_activity.narrative",
        "prior_value": "totaling $39,536.45",
        "new_value": "totaling $37,536.45",
        "reason": "Calculated precise aggregate from identified source transactions: $9,576.59 + $9,530.63 + $9,274.89 + $9,154.34 = $37,536.45",
        "reviewed_by": "Senior BSA Compliance Officer"
      }
    ]
  },
  "subject_information": {
    "customer_name": "Tanya Johnston",
    "customer_id": "CUST_0018",
    "ssn_last_4": "7149",
    "date_of_birth": "2001-10-15",
    "address": "93149 Laura Port, West Amandastad, CA 66818",
    "customer_since": "2019-10-08",
    "risk_rating": "High",
    "occupation": "Therapist, drama",
    "annual_income": 166876
  },
  "suspicious_activity": {
    "classification": "Structuring",
    "risk_level": "High",
    "confidence_score": 0.95,
    "narrative": "Tanya Johnston (CUST_0018) made four consecutive cash deposits below $10,000 at different branches from 2025-07-22 to 2025-07-25. The deposits, totaling $37,536.45, were made at Branch_Westside_Plaza, Branch_Downtown_Main, and Branch_Eastside_Center. This pattern suggests potential structuring to evade BSA reporting.",
    "key_indicators": [
      "High risk rating",
      "Repeated cash deposits under $10,000"
    ],
    "ai_reasoning": "Customer with high risk rating showed a pattern of cash deposits just under $10,000, a common structuring method to evade BSA reporting. No other suspicious activity or counterparty concerns identified."
  },
  "regulatory_compliance": {
    "citations": [
      "31 CFR 1020.320",
      "31 USC 5324",
      "31 CFR 1010.311"
    ],
    "completeness_check": true,
    "narrative_word_count": 37,
    "compliance_status": "approved_by_compliance_officer"
  },
  "accounts_involved": [
    {
      "account_id": "CUST_0018_ACC_1",
      "account_type": "Business_Checking",
      "current_balance": 29518.74,
      "status": "Active"
    },
    {
      "account_id": "CUST_0018_ACC_2",
      "account_type": "Money_Market",
      "current_balance": 70384.37,
      "status": "Closed"
    }
  ],
  "audit_trail": {
    "case_id": "CASE_3AFB9AA2",
    "processing_date": "2026-10-19T19:08:45.135570",
    "ai_agents_used": [
      "RiskAnalyst",
      "ComplianceOfficer"
    ],
    "human_reviewer": "Jane Doe, Senior BSA Compliance Officer",
    "log_reference": "workflow_integration.jsonl",
    "authorization_event_id": "AUTH_3AFB9AA2",
    "authorization_justification": "Approved by compliance officer: multi-branch structuring confirmed with $37,536.45 in cash deposits."
  }
}
06 · Reproduction & Verification Gates

Local Quick Start & Continuous Integration

GitHub Actions (ci.yml) runs 31/31 unit & compliance tests across test_foundation.py, test_risk_analyst.py, and test_compliance_officer.py.

Clone, Seed & Run Verification Suite
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env

# Run all 31 foundation, risk-analyst, and compliance-officer unit tests
pytest tests/ -v
01 · Executive Value Brief

Commercial Thesis & P&L Impact

Financial institutions face a costly AML squeeze: high false-positive alert volumes burn senior investigator hours and LLM tokens, yet Bank Secrecy Act (BSA) rules strictly forbid autonomous Suspicious Activity Report (SAR) filing—and regulatory examiners penalize boilerplated narratives, missing dollar totals, or unverified audit trails. TRACE splits screening (Stage 1) from statutory synthesis (Stage 2) across a mandatory human AUTH_* gate, avoiding 50% of Stage-2 compute while sealing every FinCEN Form 111 draft with SHA-256.

✓ 100% Grounded in Verified Repository Benchmarks ·
02 · Commercial Risk vs. Production Unlock

Why Prototype Pilots Stall — And How This Architecture Unblocks Launch

Translating engineering guardrails, determinism, and cost controls into executive deployment readiness.

✕ Why End-to-End 'Auto-SAR' Bots Create Regulatory Liability

  • Auto-drafting SAR narratives on every flagged alert wastes 50%–85% of expensive reasoning tokens on benign false positives.
  • Unattended SAR generation violates BSA human-accountability mandates and risks unlawful/defamatory criminal accusations.
  • Length-only checks pass defective narratives citing generic '$10,000 threshold' boilerplate instead of actual structured sums ($37,536.45).
  • In-place file edits during compliance review destroy provenance required by OCC / FinCEN examiners.

✓ Commercial Outcomes Delivered by This Architecture

  • 50% Stage-2 LLM compute eliminated in benchmark cohorts by positioning AUTH_* human review prior to ReACT synthesis.
  • Investigators receive structured Stage-1 Chain-of-Thought typology dossiers (structuring, layering, velocity) in seconds.
  • Every approved FinCEN Form 111 narrative passes 6 programmatic substantive checks (31 USC 5324, 31 CFR 1020.320, <= 120 words).
  • Immutable amendment_history + SHA-256 checksums turn compliance audits from manual fire drills into instant hash verification.
03 · 1:1 Feature-to-Value Traceability

Production Feature → Business Value Mapping

Every production engineering feature in kenseiAmit/trace-aml-sar-compliance-engine mapped directly to the commercial risk it eliminates and the measurable value it delivers.

Production Engineering Feature (Source) Business Risk / Bottleneck Eliminated Value Lever Quantified Business Outcome
Two-Stage CoT Risk Triage + ReACT Statutory Synthesis
Senior BSA analysts spending 45–90 minutes manually stitching multi-branch cash ledgers ($37,536.45) into prose. Investigator Leverage Automates typology detection and <= 120-word FinCEN Form 111 narrative drafting across 10 verified statutory cases.
Mandatory Pre-Stage-2 AUTH_* Human Gate
BSA regulatory non-compliance from unreviewed filings AND paying Stage-2 ReACT token costs on non-escalated alerts. FinOps & BSA Compliance 50% Stage-2 compute avoided + **100% cryptographic AUTH_* officer accountability** before narrative generation.
6-Point Substantive FinCEN Form 111 Validator
Defective filings rejected during regulatory exams due to missing Who/What/When/Where/Why, boilerplate amounts, or unqualified accusations. Regulatory Penalty Shield Enforces exact source transaction sums, dates, conduct-matched statutes (31 USC 5324), qualified language, and <= 120 words.
SHA-256 Checksums & Append-Only amendment_history
Audit trail tampering or unlogged post-filing edits triggering MRA / Consent Order findings. Examiner Audit Readiness Every triage, approval, filing, and senior-officer correction is hash-sealed with full prior_value -> new_value lineage.
Bounded Schema Repair Without Risk Fabrication
Malformed LLM JSON crashing overnight alert batches or fallback logic silently inventing risk scores. Batch SLA Reliability Self-heals formatting glitches within strict bounds and halts explicitly on unrecoverable payloads—zero fabricated risk scores.
31-Test Automated BSA Compliance CI Suite
Model/prompt updates introducing subtle statutory citation drift or breaking AUTH_* gating. Continuous Assurance 31/31 automated tests verifying statutory regexes, hash integrity, and HITL gating on every pull request.
04 · End-to-End Value Delivery Chain

Engineering Control → Operational Mechanism → Business Outcome

How architectural invariants convert directly into FinOps margin, SLA speed, and regulatory protection.

flowchart LR
  subgraph Controls["Regulated FinCrime Engineering Controls"]
    T1["Stage-1 CoT Alert Screening"]
    T2["Mandatory Pre-Stage-2 AUTH_* Gate"]
    T3["6-Factor FinCEN Form 111 Validator"]
    T4["SHA-256 Seal + Amendment Lineage"]
  end
  subgraph Mech["Compliance & Cost Mechanism"]
    M1["Correlates Multi-Branch Structuring & Velocity"]
    M2["Drops Cleared Alerts Before ReACT Drafting"]
    M3["Checks Exact USD, Dates, <=120w & Statutes"]
    M4["Appends Immutable Officer Edits & Checksums"]
  end
  subgraph ROI["Bank Compliance & P&L Value"]
    V1["Faster Alert Triage Throughput"]
    V2["50%+ Stage-2 Compute Saved + BSA Duty Split"]
    V3["Zero Boilerplate / Defective SAR Rejections"]
    V4["Turnkey OCC / FinCEN Examination Proof"]
  end
  T1 --> M1 --> V1
  T2 --> M2 --> V2
  T3 --> M3 --> V3
  T4 --> M4 --> V4
05 · Interactive Scale & Unit-Economics Model

BSA Investigation Capacity & Stage-2 Compute Simulator

Models annual Stage-2 ReACT runs avoided on false-positive alerts and senior compliance officer drafting hours reclaimed.

2500
200 alerts/mo 20,000 alerts/mo
50
30 % 90 %
Baseline vs. Production Comparison
Benchmark Formula Basis: Grounded in repo benchmarks: 50% Stage-2 compute avoidance verified on benchmark cohort via pre-Stage-2 AUTH_* gate (foundation_sar.py); escalated SAR drafting time savings modeled at 45 min reclaimed per validated <= 120-word FinCEN Form 111 filing.
06 · Cross-Functional Buyer Alignment

Why Every Enterprise Stakeholder Signs Off

How this single architecture aligns Engineering, Finance, Security, Legal/Compliance, and Business Operations.

BSA / AML Compliance Officer 100% Human `AUTH_*` Control

Eliminates repetitive ledger correlation and first-draft writing while keeping legal filing authority strictly in human hands.

Internal Audit & Examiners SHA-256 + Amendment History

Every SAR package carries cryptographic tamper evidence, exact statutory citations, and non-destructive edit lineage.

Head of FinCrime Ops 50%+ Stage-2 Compute Avoided

False-positive alerts exit cleanly after Stage-1 triage without burning multi-step Stage-2 synthesis compute.

General Counsel Qualified Statutory Phrasing

Automated 6-factor validation blocks accusatory legal conclusions and enforces regulatory-grade objective language.