COCO How-to Guide

Build an AI Fraud Pattern Detector: Open Source, Self-Hosted, Zero Vendor Lock-in

Every fintech and e-commerce team loses millions to fraud that rules-based systems miss. An AI fraud pattern detector catches what static rules can't — but most SaaS options charge per transaction and send your sensitive payment data to their cloud. This guide shows you how to build your own AI fraud pattern detector using Zylos, the open source agent framework, with full data sovereignty, fixed hosting costs, and real-time multi-channel alerting via HxA Connect.

Disclaimer: This guide is for educational and informational purposes only. Fraud detection in production environments involves financial risk and regulatory obligations (PCI DSS, SOC 2, GDPR, FFIEC). The performance metrics cited are based on published research benchmarks and community-reported results — your actual outcomes depend on data quality, model tuning, and operational context. Always validate detection models against your own labeled dataset before relying on them for real-time transaction decisions. Consult qualified compliance and security professionals for your specific regulatory requirements.
TL;DR

What is an AI fraud pattern detector?

An AI fraud pattern detector is a system that automatically analyzes transactions, user behaviors, and system events to identify patterns that indicate fraud — without relying on static rules. Under the hood, it's an LLM-powered agent that performs multi-dimensional analysis: transaction anomalies (velocity checks, amount outliers, geo-inconsistencies), behavioral patterns (login cadence, device fingerprinting, session anomalies), network analysis (mule account detection, collusion rings, coordinated attacks), and contextual reasoning (does this transaction make sense for this user at this time?).

Unlike rules-based systems ("if amount > $10,000 → flag"), a modern AI-powered fraud pattern detector understands context. A $15,000 wire transfer from a corporate treasury account at 2 PM on a Tuesday is normal. The same transfer from a retail account at 3 AM from a new device is fraud. LLM-based detection handles this nuance because it reasons about the full context — user history, device profile, transaction patterns, and external signals — not just threshold values.

The state of the art in 2026 is a layered detection architecture: a fast rules engine catches known fraud patterns (zero LLM cost), ML anomaly detection catches statistical outliers (Isolation Forest, Autoencoder), and the LLM agent investigates the ~10% of cases that are genuinely ambiguous. This hybrid approach delivers 95%+ fraud recall with under 4% false positives — matching enterprise SaaS tools at a fraction of the per-transaction cost.

Why Isolation Forest and Autoencoder for anomaly detection?

Fraud detection presents unique constraints that rule out many ML approaches. Isolation Forest is chosen for the rules-engine layer because it requires no labeled fraud data, handles high-dimensional feature spaces efficiently (O(n log n) training), and is robust to the extreme class imbalance typical in fraud detection (0.1–1% fraudulent transactions). Unlike K-Means or DBSCAN — which assume spherical or density-connected clusters — Isolation Forest makes no assumptions about the shape of normal behavior, making it resilient to the heterogeneous transaction patterns seen across different merchants, geographies, and payment methods.

Autoencoders complement Isolation Forest by learning a compressed representation of normal transaction behavior. The reconstruction error — how poorly the model can reconstruct a given transaction — serves as the anomaly score. A transaction that produces high reconstruction error is structurally different from the training distribution. In benchmarks, this combination (Isolation Forest + Autoencoder ensemble) achieves 92–96% recall on public fraud datasets (IEEE-CIS Fraud Detection, PaySim) — consistent with the 95%+ target cited throughout this guide. For reference, rule-based systems alone typically achieve 60–80% recall on these same benchmarks (source: IEEE-CIS Fraud Detection benchmark, Kaggle 2019; PaySim mobile money fraud dataset, Lopez-Rojas et al. 2016).

How the 0.92 anomaly threshold is calibrated

The anomaly threshold of 0.92 is not arbitrary — it is set at the 92nd percentile of anomaly scores from a clean validation set. This means 8% of transactions trigger deeper investigation: ML re-scoring for ~5%, and LLM investigation for ~3%. The calibration process:

  1. Run the detector in shadow mode on 30 days of historical transactions with known outcomes (confirmed fraud vs. legitimate).
  2. Plot the precision-recall curve at threshold increments of 0.01 from 0.80 to 0.99. The optimal operating point is where the F1 score (harmonic mean of precision and recall) peaks — typically between 0.90 and 0.94 depending on your transaction mix.
  3. Adjust for your risk tolerance: lower thresholds (0.85–0.90) increase recall but generate more false positives (higher operational cost for manual review). Higher thresholds (0.95+) reduce false positives but may miss sophisticated fraud. The default 0.92 balances these trade-offs for the median fintech use case.
Important: These performance figures (95% recall, <4% FPR) are achievable targets validated against public benchmark datasets. Your results depend on feature engineering quality, training data representativeness, and ongoing feedback-loop tuning. Budget 2–4 weeks of shadow-mode operation to calibrate thresholds for your specific transaction profile before enabling auto-blocking.
💳 Transaction Stream Rule Engine Known Patterns / Threshold Checks ~50% cleared ML Anomaly Detection Isolation Forest / Autoencoder ~40% cleared LLM Agent (Zylos) Contextual Reasoning & Investigation ~10% LLM Cleared / Pass Fraud Alert Only the hardest ~10% of transactions reach the LLM. 95%+ fraud recall <4% false positives at a fraction of the SaaS cost.
Layered AI fraud pattern detector architecture: rules → ML anomaly detection → LLM. Only the hardest 10% of transactions reach the LLM for full investigation.

Build vs buy: why self-host your AI fraud pattern detector

The market for AI fraud detection tools is crowded — Feedzai, Darktrace, Sift, SEON, and Trench all promise to catch fraud. But every SaaS option comes with the same three trade-offs:

  1. Per-transaction pricing adds up fast. At $0.10–$5 per screened transaction, a fintech processing 100,000 transactions/month pays $10,000–$500,000/month — before their payment processor fees. A self-hosted AI fraud pattern detector on a $80/month VPS handles the same volume at fixed cost.
  2. Your transaction data leaves your infrastructure. Most SaaS fraud tools require sending raw transaction data to their cloud for analysis. For PCI-compliant environments, fintech, and banking — sharing customer transaction data with third-party SaaS is a compliance nightmare or outright violation.
  3. Fraud patterns are proprietary — your model should be too. SaaS fraud detectors train on pooled data across all their customers. Your proprietary fraud signals become part of their model, benefiting your competitors. With a self-hosted detector, your fraud detection logic is your competitive advantage.

Building your own AI fraud pattern detector with Zylos flips all three: fixed hosting cost regardless of transaction volume, full data sovereignty with zero external data sharing, and proprietary fraud detection logic that stays yours. Plus native multi-channel alerting to any system via HxA Connect's 10+ adapters.

How to build an AI fraud pattern detector with Zylos

Zylos is an open source autonomous AI agent framework with persistent memory, multi-channel communication, and extensible skills. It's the engine that powers the detector. Here's how to build your AI fraud pattern detector in four steps.

1
Set Up Zylos
Clone, install, configure LLM credentials, verify agent is running
2
Define Fraud Taxonomy
Build fraud categories, risk levels, anomaly thresholds, alert routing rules
3
Connect Sources & Alerts
Wire payment APIs + configure HxA Connect channels for real-time alerting
4
Deploy & Tune
Docker deployment, feedback loop tuning, threshold optimization

Step 1: Set up the Zylos agent framework

Start by cloning the Zylos Core repository and installing dependencies. You'll need Node.js ≥ 18 and an API key from your preferred LLM provider (OpenAI, Anthropic, Gemini, or a local model via Ollama). For fraud detection, we recommend a model with strong reasoning capabilities (GPT-4o or Claude Sonnet 4).

# Clone and install
git clone https://github.com/coco-xyz/coco-core.git
cd zylos-core
npm install

# Configure environment
cp .env.example .env
# Edit .env: set LLM_API_KEY, LLM_MODEL (gpt-4o / claude-sonnet-4-6)

# Start the agent
npm start
# Agent running on http://localhost:3456

Verify the agent is alive by sending a test transaction for analysis. If it responds with a risk assessment, you're ready to build the full detection pipeline.

Step 2: Define your fraud detection taxonomy

The fraud taxonomy is the classification system your AI fraud pattern detector uses to categorize every suspicious event. Define it once, and the agent applies it consistently. Here's a production-ready fraud taxonomy you can adapt:

{
  "fraud_taxonomy": {
    "categories": [
      "payment_fraud",
      "account_takeover",
      "promo_abuse",
      "identity_theft",
      "money_laundering",
      "chargeback_fraud",
      "synthetic_identity",
      "affiliate_fraud"
    ],
    "risk_levels": ["critical", "high", "medium", "low"],
    "alert_routing": {
      "payment_fraud":      { "target": "slack",     "channel": "#fraud-critical" },
      "account_takeover":   { "target": "telegram",  "channel": "@secops-alerts" },
      "money_laundering":   { "target": "email",     "recipient": "[email protected]" },
      "chargeback_fraud":   { "target": "jira",      "project": "FRAUD" },
      "promo_abuse":        { "target": "lark",      "group": "risk-ops" },
      "default":            { "target": "hxa-connect", "thread": "fraud-review" }
    },
    "anomaly_threshold": 0.92,
    "velocity_checks": {
      "max_txn_per_hour": 15,
      "max_txn_per_device": 5,
      "max_amount_per_day": 50000
    }
  }
}

The anomaly_threshold is critical: transactions with an anomaly score above 0.92 go directly to the LLM agent for investigation. Below that, they're either auto-cleared (score < 0.5) or routed through the rules engine for known pattern matching. This layered approach keeps LLM costs minimal while maintaining high fraud recall.

Step 3: Connect transaction sources and alert channels

Now wire up where transactions come from and where alerts go to. HxA Connect — COCO's bot-to-bot messaging server — handles the multi-channel alert routing so your AI fraud pattern detector can notify the right team on the right platform in real time.

// In the Zylos agent's skill configuration:
import { HxaConnectClient } from '@coco-xyz/hxa-connect-sdk';

const alerter = new HxaConnectClient({
  url: 'https://your-hxa-server.com',
  token: process.env.HXA_BOT_TOKEN,
  orgId: process.env.HXA_ORG_ID,
});

// Register transaction intake sources
agent.on('transaction.received', async (txn) => {
  // 1. Feature extraction
  const features = await agent.extractFeatures(txn);

  // 2. Anomaly detection
  const anomaly = await agent.detectAnomalies(features);

  // 3. LLM investigation for high-anomaly transactions
  if (anomaly.score >= config.anomaly_threshold) {
    const investigation = await agent.investigate(txn, features, anomaly);

    if (investigation.risk_level === 'critical') {
      await alerter.send(config.alert_routing[investigation.category],
        formatFraudAlert(txn, investigation));
    }
  }
});

HxA Connect supports Slack, Telegram, Email, Jira, Lark, Discord, and custom webhooks out of the box. One integration layer, every alert destination covered — your fraud team gets notified where they actually work.

Pro tip: Start in shadow mode, then go live

This progressive rollout means your fraud team builds trust in the AI fraud pattern detector before it starts blocking real transactions.

Step 4: Deploy, monitor, and tune detection thresholds

Deploy your AI fraud pattern detector with Docker for the simplest production setup:

# Build and run with Docker
docker build -t fraud-detector .
docker run -d -p 3456:3456 \
  -v $(pwd)/data:/app/data \
  -e LLM_API_KEY=$LLM_API_KEY \
  -e HXA_BOT_TOKEN=$HXA_BOT_TOKEN \
  fraud-detector

Monitor detection accuracy through the Zylos agent dashboard. Track three key metrics: fraud recall (what percentage of actual fraud does the system catch?), false positive rate (what percentage of flagged transactions are legitimate?), and time-to-detect (how quickly does the system flag fraud after the transaction occurs?). A well-tuned system reaches 95%+ recall with under 4% false positives within the first month of feedback-loop tuning.

Evaluating your detector: metrics that matter

Beyond the headline numbers, evaluating a fraud detection model requires looking at metrics that account for extreme class imbalance. Here are the metrics to track, why each matters, and how to compute them from your feedback loop:

Metric Formula Target Why it matters
Precision TP / (TP + FP) > 80% Low precision = analysts waste time on false alarms
Recall (TPR) TP / (TP + FN) > 95% Low recall = fraud goes undetected = direct revenue loss
F1 Score 2 × P × R / (P + R) > 0.87 Balanced measure — single number to optimize thresholds against
ROC-AUC Area under ROC curve > 0.95 Measures ranking quality across all thresholds; robust to imbalance
FPR (False Positive Rate) FP / (FP + TN) < 4% Business-facing: what % of good users get incorrectly flagged?
Time-to-Detect (TTD) talert − ttransaction < 30s For real-time blocking, detection latency must be sub-second to seconds
Benchmark reference: The 95% recall / <4% FPR target is consistent with published results on the IEEE-CIS Fraud Detection dataset (Kaggle, 2019) where top-performing ensembles achieve 0.96 AUC. For mobile money fraud, the PaySim dataset (Lopez-Rojas et al., 2016) provides a reproducible baseline — a well-tuned Isolation Forest achieves 0.93 AUC on this benchmark before any LLM layer is added. Your production numbers should exceed these since you have labeled feedback data that public benchmarks lack.

Troubleshooting common issues

Self-hosted fraud detection requires ongoing maintenance. Here are the most common issues and how to resolve them:

Rollback strategy: reverting to rules-only mode

AI fraud pattern detector comparison: Build vs SaaS

Dimension Build (Zylos + HxA Connect) Buy (SaaS Fraud Detector)
Cost at 100,000 txns/month ~$80/month (VPS hosting) $10,000–$500,000/month
Data sovereignty Full — transaction data stays on your infrastructure Vendor-dependent — raw transaction data sent to their cloud
PCI / SOC2 / GDPR compliance You control the infra — compliance is your responsibility Vendor-managed compliance (check their certifications)
Fraud taxonomy customization Full control — model your exact fraud categories and risk logic Limited to vendor's predefined fraud categories
Model ownership Your fraud patterns stay proprietary — competitive advantage Your patterns train a shared model used by competitors
Integration breadth 10+ channels via HxA Connect + custom webhooks + any payment API Limited to vendor-supported payment processors and alert channels
Setup time 2 hours to PoC; 3–5 days to production with ML pipeline 1 hour to connect; 1–2 days to tune thresholds
Model choice Any LLM: GPT-4o, Claude, Gemini, or local (Ollama) Vendor's model only — you can't swap or upgrade
When to buy instead: If your team has zero engineering capacity and processes under 5,000 transactions/month, a SaaS AI fraud detector like SEON or Sift may be the pragmatic starting point. The per-transaction cost at very low volume is manageable. But as volume grows — or if you handle sensitive financial data — the compliance, cost, and data-sovereignty advantages of self-hosting become decisive.

Why open source for your fraud detection pipeline

Choosing an open source fraud pattern detector isn't just about cost — it's about control over the system that protects your revenue. Here's what that means in practice:

Limitations and caveats

No fraud detection system — SaaS or self-hosted — catches everything. Being transparent about what this architecture can and cannot do is essential for setting realistic expectations:

References and further reading

Frequently asked questions

What is an AI fraud pattern detector?
An AI fraud pattern detector is a system that uses large language models and machine learning to automatically identify suspicious patterns in transaction data, user behavior, and system logs. It combines rules engines, anomaly detection algorithms (Isolation Forest, Autoencoder), and LLM reasoning to catch both known fraud types and novel attack vectors — all while running on your own infrastructure.
Why build a fraud detector instead of buying a SaaS?
Building gives you fixed hosting costs instead of per-transaction SaaS fees, full data sovereignty (transaction data never leaves your infrastructure), and proprietary fraud logic that stays yours — not pooled into a shared model. For PCI-compliant environments and fintech, keeping transaction data in-house is often a legal requirement. At 100,000+ transactions/month, the cost advantage of building is overwhelming: ~$80/month vs $10,000+.
How accurate is an open source AI fraud detector compared to SaaS?
The core detection capability comes from the LLM and ML models, not the wrapper. Whether you use GPT-4o via Zylos or via a SaaS tool, the underlying reasoning power is the same. The difference is customization: with Zylos + HxA Connect, you tune anomaly thresholds for your specific transaction mix, define fraud categories that match your business, and control the investigation workflow. A well-tuned self-hosted detector achieves 95%+ fraud recall with under 4% false positives — matching or exceeding SaaS benchmarks.
Can I integrate an AI fraud pattern detector with my existing payment stack?
Yes. Zylos and HxA Connect integrate with any system that exposes an API — Stripe, Adyen, PayPal, Plaid, internal ledger systems, or custom payment processors. Transaction data flows in via webhook or API polling, the agent analyzes patterns and assigns risk scores, and fraud alerts route to Slack, Telegram, email, Jira, or any case management system. HxA Connect handles the multi-channel routing to 10+ platforms out of the box.
How long does it take to build and deploy?
A proof-of-concept AI fraud pattern detector is running in under 2 hours: install Zylos, define your fraud taxonomy, connect one transaction source, and the agent starts flagging suspicious patterns. A production deployment with ML anomaly detection, confidence scoring, multi-channel alerting, and a case management dashboard takes 3–5 days. The bottleneck is defining your fraud taxonomy and tuning detection thresholds — which is risk-domain expertise, not engineering work.

Ready to build your own AI fraud pattern detector?

Zylos is MIT-licensed and free to use. No training data required. Deploy on your own infrastructure.

Get Zylos on GitHub

Also available: HxA Connect for multi-channel alert routing · COCO Labs for documentation & guides

Related articles