Production Case Study · AI Automation · MCP · FastAPI

D2C AI Employee
E-Commerce Margin Leak Detection Agent

A guardrail-gated AI agent with 8 FastMCP tools connecting Shopify, Razorpay, Shiprocket, and Meta Ads. Uses anti-hallucination SQL execution to deliver source-traceable business analytics — so every answer can be verified.

8
FastMCP tools integrated
4
Data sources connected
0%
Hallucinated data (guardrailed)
SQL
Source-traceable answers
D2C AI Employee — E-Commerce AI Agent live application screenshot
System Design

Guardrail-Gated AI with Anti-Hallucination SQL

D2C AI Employee connects your business data sources through structured MCP tools and enforces guardrails at every LLM output — ensuring every business insight is backed by real, queryable data.

🛡️

Guardrail-Gated LLM

Every LLM response passes through validation guardrails. The agent cannot return a business metric it hasn't retrieved from a real data source. Hallucination of sales figures, margins, or KPIs is structurally prevented.

🔧

8 FastMCP Tool Integrations

8 custom MCP tools connect to Shopify (orders, products, inventory), Razorpay (payments, refunds), Shiprocket (logistics, COD), and Meta Ads (ad spend, ROAS). Each tool returns structured, typed data.

🗄️

Anti-Hallucination SQL Execution

Business questions trigger SQL query generation against Supabase/PostgreSQL. The query executes against real data, and the result — not the LLM's guess — becomes the answer. Every figure is source-traceable.

📉

Margin Leak Detection

Correlates revenue (Shopify), payments (Razorpay), shipping costs (Shiprocket), and ad spend (Meta Ads) to identify where gross margin is being eroded — through returns, excessive discounts, or high logistics cost.

⚡

FastAPI + LangChain Backend

Python FastAPI backend handles authentication, session management, and LangChain agent orchestration. Real-time streaming responses via Server-Sent Events. Deployed and production-ready.

🖥️

React + TypeScript Frontend

Clean dashboard built with React and TypeScript. Merchants interact with the AI agent through a chat interface and view analytics cards sourced from real integrated data.

The 8 FastMCP Tool Integrations

TOOL 01

Shopify Orders

Retrieves order volume, AOV, and revenue by date range

TOOL 02

Shopify Products

Product performance, SKU-level margins, and inventory data

TOOL 03

Razorpay Payments

Payment success rates, refund analysis, and net collected

TOOL 04

Razorpay Refunds

Refund volume trends and SKU-level return analysis

TOOL 05

Shiprocket Logistics

Shipping cost per order, delivery performance, COD data

TOOL 06

Shiprocket COD

Cash-on-delivery remittance and pending reconciliation

TOOL 07

Meta Ads Spend

Ad spend by campaign, ROAS calculation, cost per acquisition

TOOL 08

SQL Analytics

Cross-source queries against Supabase for margin analysis

Technology Stack

FastMCP LangChain Supabase Python FastAPI React TypeScript PostgreSQL Shopify API Razorpay API Shiprocket API Meta Marketing API

Technical Questions

What is an AI agent for e-commerce analytics?
An AI agent for e-commerce connects to your business data sources — Shopify orders, payment processors, logistics providers, and ad platforms — and lets you ask natural language business questions. D2C AI Employee goes further by enforcing guardrails: every answer it gives is backed by real SQL query results, not LLM guesses about your business metrics.
What is anti-hallucination SQL execution?
Anti-hallucination SQL execution means the agent cannot make up data. When you ask "What was my margin on Shopify orders last month?", the agent generates a SQL query, executes it against your real Supabase database, and returns the verified result. Every figure is source-traceable — you can see exactly which query produced which number. This prevents the common LLM problem of generating confident but incorrect business metrics.
How does the guardrail system work?
Guardrails are validation layers that intercept LLM outputs before they reach the user. In D2C AI Employee, if the LLM attempts to state a metric without calling the appropriate MCP tool first, the guardrail blocks the response and forces a tool call. This ensures all business data claims are substantiated by actual data retrieval, not language model inference.
What is margin leak detection in e-commerce?
Margin leak detection identifies where revenue is being silently eroded between gross sales and net profit. Common leaks include excessive Meta Ads spend that isn't offset by sales lift, high Shiprocket logistics costs on low-margin orders, Razorpay refunds that haven't been reconciled against Shopify orders, and discount stacking. D2C AI Employee correlates all four data sources to surface these patterns automatically.

Need an AI agent connected to your business tools?

Sanskar Agrawal builds guardrail-gated AI agents with custom MCP tool integrations for e-commerce, SaaS, and business analytics. Based in Indore, India — available globally.