Tuesday, June 17, 2025

Tanaji: Teaching an AI to Fight Fraud Like a Warrior

 

๐Ÿ”ฅ Introduction

If there's one name in Maratha history that embodies courage under pressure, it’s Tanaji Malusare.

When the Kondhana Fort had to be reclaimed, Tanaji didn’t wait. He scaled the cliffs with a monitor lizard ๐ŸฆŽ, led a night raid, and paid the ultimate price — but won the fort.

In the Fraud-Free Swarajya project, Tanaji is our AI fraud scorer — making fast, high-stakes decisions on every incoming transaction.

Just like the real Tanaji, our AI:

  • Works under uncertainty

  • Evaluates risk on the fly

  • Doesn’t wait for permission to act ๐Ÿš€


๐Ÿง  What Tanaji (the AI) Does

The tanaji module is a Python-based microservice powered by:

FastAPI
scikit-learn for ML
pydantic for validation
uvicorn for async web serving
✅ Logging + formatting with loguru and pythonjsonlogger

It receives a transaction like this:

json

{ "transactionId": "txn001", "userId": "user123", "amount": 5000, "paymentMethod": "risky", "location": "risky" }

Then it returns a fraud score, a risk level, and even an explanation.


๐Ÿงช How It Works Behind the Scenes

  1. Feature Extraction:
    We extract meaningful inputs like:

    • Amount

    • Whether the location or payment method is risky

  2. Model Training:
    We trained a basic RandomForestClassifier on synthetic data to:

    • Classify transactions as fraud or not

    • Assign a confidence score (0 to 1)

  3. Scoring Endpoint:
    Exposed at /score, it predicts and responds in milliseconds.

  4. Logging Everything
    Every request and response is structured, logged, and dockerized.


๐Ÿงฑ Why FastAPI?

Because:

  • It’s async by design

  • Lightning fast (even for ML)

  • Auto-generates Swagger docs

  • Works beautifully inside Docker

  • And let’s be honest: It feels like Spring Boot’s cousin — but cooler with Python ๐Ÿ


๐Ÿ”ฅ Tanaji Trivia Time

Here are some legendary facts about Tanaji Malusare:

  • ๐Ÿ’ฅ He led the assault on Kondhana Fort in 1670 with just a handful of soldiers.

  • ๐ŸฆŽ He used a monitor lizard (ghorpad) to scale the vertical walls of the fort at night.

  • ๐Ÿ’” Though mortally wounded in the battle, his mission succeeded — and Shivaji said:
    "Gad aala, pan Sinh gela." (We got the fort, but lost the lion.)

  • ๐Ÿ—ก️ Kondhana was later renamed Sinhagad in his honor.

Like Tanaji, our AI doesn't hesitate. It detects danger, acts swiftly, and protects the digital kingdom.


⚙️ Sample Response from Tanaji

json

{ "transaction_id": "txn001", "fraud_score": 0.97, "explanation": ["High risk score", "High amount"], "risk_indicators": ["HIGH_AMOUNT"] }

Simple. Actionable. Defensible.


๐Ÿงฐ Dockerizing Tanaji

We packaged Tanaji with a clean Docker setup:

  • uvicorn + FastAPI as entrypoint

  • Exposes port 8000

  • Shared volume for fraud_model.pkl

  • Ready to scale with Docker Compose

dockerfile


CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

๐Ÿง  What Makes This Exciting?

  • You can retrain the model (train_model.py) anytime

  • Logs are structured and Prometheus-ready

  • Pluggable with any orchestrator or microservices platform

  • As the Fraud-Free Swarajya grows, Tanaji will evolve — just like his legacy lives on


๐Ÿงญ What’s Next?

In the next post, we’ll meet dadoji — the rule engine who checks the AI’s decisions using wisdom and business rules.

We’ll also show how AI and logic can work together — just like generals and warriors on a battlefield.

No comments:

Post a Comment