Thursday, July 10, 2025

🧠 The Wisdom of Rules: Building Dadoji for Explainable Fraud Detection

A tribute to Dadoji Konddev — the strategic mind behind structure, just like our rule engine.

🛕 Inspired by Dadoji Konddev

Dadoji Konddev, the mentor and guardian of young Shivaji Maharaj, wasn't just a caretaker — he was a visionary. He laid the foundations of discipline, systems, and early strategies that made the idea of Swarajya possible.

In the Fraud-Free Swarajya project, our rule engine is named dadoji in his honor — a system that brings stability, structure, and wisdom to our fraud detection stack.


❓ Why Rules When We Have AI?

This question is at the heart of explainable AI systems.

AI (like our tanaji module) is great at detecting patterns — even ones you can't explicitly define. But there are scenarios where hard rules are:

  • Easier to explain
  • Legally required (compliance)
  • Faster to execute
  • Safer to override AI mistakes

Rules bring clarity and confidence, especially for edge cases.


🧩 When Do We Use Rules?

Here are some real-world fraud detection scenarios where rules are powerful:

Rule Name Condition Action
HighAmountRule Amount > 10,000 Mark as HIGH risk
RiskyLocationRule Location in [“risky”, “banned_country”] Raise risk level
FrequentTxnRule Too many txns from same user in 1 min Flag as suspicious
BlacklistedCardRule Card ends with known fraud pattern Auto-reject
VIPBypassRule User is admin/VIP Adjust recommendation

🧠 AI + Rules Together = Smarter Detection

Capability AI (Tanaji) Rules Engine (Dadoji)
Learns over time ✅ Yes ❌ No
Deterministic ❌ Not always ✅ Always
Transparent ⚠️ Depends ✅ Fully explainable
Override AI ❌ No ✅ Yes
Business control ⚠️ Harder ✅ Business-friendly
“Let AI detect the unknown. Let rules defend the known.”

⚙️ How It Works in Code

Every rule implements a common interface:

public interface FraudRule {
    boolean apply(TransactionRequest txn);
    String getExplanation();
    RiskIndicator getRiskIndicator();
}

A sample rule:

public class HighAmountRule implements FraudRule {
    public boolean apply(TransactionRequest txn) {
        return txn.getAmount().compareTo(BigDecimal.valueOf(10000)) > 0;
    }

    public String getExplanation() {
        return "High amount transaction";
    }

    public RiskIndicator getRiskIndicator() {
        return RiskIndicator.HIGH_AMOUNT;
    }
}

🔄 How Tanaji + Dadoji Work Together

  1. sindhudurg receives the transaction
  2. Forwards to tanaji (AI engine)
  3. tanaji returns fraud score and risk factors
  4. Response goes to dadoji
  5. dadoji runs applicable rules
  6. If a rule applies:
    • Explanation is added
    • Risk level may be escalated
    • Recommendation may be overridden
  7. Final response sent back to user

🏹 Real-World Analogy

Tanaji Malusare was the courageous warrior who scaled walls.
Dadoji Konddev was the quiet tactician who taught how forts are built.

We need both — just like fraud detection needs AI for intelligence and rules for discipline.


📜 A Word on Explainability

In banking and fintech, decisions that affect customers (like rejecting a transaction) must be explainable. Dadoji’s rules let us say:

  • “This transaction was rejected because the amount exceeded ₹10,000.”
  • “Risk increased due to login from a risky location.”

These aren’t guesses — they’re policies.


🔮 What’s Next?

  • 🌀 Feedback loop (santaji) — to learn from flagged frauds
  • 🔔 Real-time notification service (SMS, push, email)
  • 🧭 Admin dashboard (ashtapradhan) for rule management
  • 🔐 API Security and compliance

🧠 Takeaway

A rule engine isn’t about replacing AI.
It’s about building trust, consistency, and strategic governance into a system designed to defend.

Our tribute to Dadoji is more than a name — it’s a mindset.


🔗 GitHub

See the code for all rules and architecture:
👉 github.com/pcm1984/fraud-free-swarajya


🇮🇳 Closing Words

“Shivaji Maharaj won battles not only through might, but through systems.
We too must build software that’s both brave and wise.”

“Marathi Paaul Padte Pudhe…”

No comments:

Post a Comment