Urgent.News

What's breaking now, across thousands of outlets.

AI

How I Built an Autonomous AI Refund Decision Engine with FastAPI, React, and LiteLLM

Customer returns and refund requests are among the costliest operational friction points for modern e commerce platforms. Traditional solutions force businesses to choose between two undesirable extremes: Rigid rule engines that deny valid edge cases, frustrating loyal shoppers. Naive generative chatbots that can be easily manipulated through prompt injection, promising free money and…

Modern e-commerce platforms regularly encounter costly issues with customer returns and refunds. Traditional methods leave businesses in a tough spot, as rigid rule engines fail to handle nuanced cases, while unguarded generative chatbots can be easily manipulated. To address this challenge, I developed an autonomous AI-driven Customer Support Refund System that strikes a balance between rapid automated decisions and stringent policy checks. This article outlines the platform's architecture and implementation details.

The system follows the Tracer Bullet build strategy, where each development milestone adds a thin, functional layer encompassing the database, backend services, AI decision layer, and user interface. The components include:

1. Frontend: React 18 and TypeScript SPA built with Tailwind, Lucide, and TanStack libraries.

2. Backend: FastAPI REST layer using Python 3.11, Pydantic 2, SQLAlchemy 2 (async with asyncpg), and LiteLLM for AI decision-making.

3. Database: PostgreSQL 16 with normalized relational models for customers, orders, order items, refund claims, LLM providers, and audit logs.

4. Infrastructure: Fully containerized, multi-stage Docker Compose environment with health checks.

The AI decision engine employs a layered pipeline:

1. Fast Path Validation - Enforces time windows, item conditions, final sale tags, and velocity limits.

2. Risk Scoring & History - Calculates lifetime return rates and detects fraud clusters.

3. Structured AI Reasoning - Evaluates nuanced customer testimonies and outputs results in a strict JSON schema.

4. Audit Trail & Disposition - Logs approvals, escalations, and denials with explanations.

The engine produces structured policy outputs, including decision type, confidence score, reasoning summary, policy citations, detected red flags, matched rules, and any anomalies. If an LLM is prompted to ignore return windows or approve high-value claims, the deterministic validation layer flags the anomaly and forces an Escalated state for human review.

The system also features a scoped customer portal with a three-step refund wizard and history dashboard. Customers can select orders and items, input return justifications, and receive transparent verdict cards with confidence percentages and detailed policy reasoning. The portal allows users to inspect claim details, view verbatim customer statements, and examine AI policy evaluations.

When claims exceed velocity thresholds or involve high-value items, the system automatically places them in an Escalated queue for human supervisors to review. Supervisors can assess customer risk scores, inspect AI decisions and explanations, and provide justifications for approved or denied claims.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in AI

Done Is Testimony. Terminal State Is the Grade.

Two things landed in the same week and they are the same argument. Microsoft and Hugging Face published ThinkingBox , a benchmark that grades agents on the backend state and side effects they leave…

More from Monday 5 October →