Inspiration

What it does

How we built it

Challenges we ran into## Inspiration

Subscription software companies lose an estimated 9% of recurring revenue to involuntary churn—expired credit cards, temporary processing declines, and billing fatigue. In the SaaS economy, this represents over $48B in lost revenue annually.

The conventional response has been passive, automated dunning emails ("Action Required: Update your billing info"). These emails suffer from abysmal open rates (typically <15%) and high latency, allowing customers to disengage and churn by accident.

Yet when businesses attempt to deploy conversational AI chatbots to handle billing negotiations in real time, they face severe financial and regulatory hazards:

  1. Price & Discount Hallucinations: Unconstrained LLMs can invent arbitrary discounts, echo customer bids (e.g., agreeing to a "$10 lifetime" price on an enterprise account), or promise free service.

  2. Premature Status Commitments: Generative models often assert that an account has been paused or renewed before any underlying transaction or database state change has occurred.

  3. Regulatory & Dispute Exposure: LLMs routinely fail to detect chargeback threats, legal keywords, or dispute claims, attempting to negotiate pricing instead of immediately handing off the customer to compliance personnel.

We built ChurnRescue AI to solve this dilemma: an agent that provides human warmth, conversational empathy, and real-time retention right inside the app, backed by a strictly deterministic financial guardrail engine where the LLM is physically prohibited from controlling the ledger.

What It Does

ChurnRescue AI intercepts failed renewals at the point of experience, guiding at-risk subscribers through automated resolution with mathematical guardrails and instant checkout:

• Separation of Concerns (Empathy vs. Authority): Google Cloud Vertex AI (Gemini) handles customer intent classification, conversational tone, and objection handling. All pricing, discount math, state transitions, and payment authorizations are governed deterministically in code.

• Deterministic Concession Ladder: Low-usage subscribers (Usage <60%) transition step-by-step through a bounded concession ladder:

Step 0: 20% off → Step 1: 35% off → Step 2 (Floor): 50% maximum

For example, an at-risk subscriber on a $25.00/month plan is offered $20.00, counters at $16.25, and clamps strictly at the $12.50 policy floor. Even if the subscriber repeatedly demands $10.00, the model is mathematically barred from offering it.

• High-Usage Protection (≥60%): Subscribers with high resource utilization (e.g., Enterprise accounts at 85% capacity) are blocked from discounts by rule:

Utilization ≥60% → Concession = 0%

They are routed to a full-price retry (e.g., $150.00) or a plan downgrade.

• Two-Step Explicit Pause Protection: When a subscriber asks to pause their plan, the agent creates a pending offer and returns nextStep: "confirm_pause". It informs the customer that the pause has not yet been processed and requires an explicit click on the Confirm Pause button before modifying the database.

• Autonomous Keyword Escalation: Compliance keywords such as chargeback, dispute, fraud, lawyer, or human immediately abort automated discounting and escalate the subscriber to the Needs a Human supervisor queue with severity ranking: High, Medium, or Low.

• Instant Native PayPal Sandbox Checkout: Features native PayPal Checkout v6 SDK and Orders v2 Sandbox integration. Upon terms acceptance, an active PayPal button appears in chat. Clicking it triggers the native modal sheet, captures the exact verified amount, and atomically restores the subscriber's account to healthy.

• Zero-PII Telemetry Dashboard: A live operations dashboard providing real-time recovery metrics, daily trend lines, intervention mix breakdowns, and audit trails without exposing customer PII or raw secrets.

How We Built It

ChurnRescue AI is engineered as an enterprise-grade full-stack application:

• Agent Orchestration & State Machine: Built using LangGraph with a 4-node deterministic pipeline:

  1. classify_intent: Vertex AI classifies the customer message into discrete intents: accept, counter_price, pause, dispute, question, and decline.

  2. propose_recovery_action: Computes candidate actions based strictly on customer usage, active step, and policy constraints.

  3. apply_guardrails: Evaluates the proposal against hard business rules. If the model or proposed price exceeds policy boundaries, it clamps the offer to the deterministic formula or escalates to a human supervisor.

  4. generate_message: Formulates the conversational response. Outgoing text is scanned by a regex-based currency auditor (checkMessageAmounts); any hallucinated price or premature commitment is replaced with an approved deterministic template.

• Large Language Model: Google Cloud Vertex AI running Gemini for low latency and structured Zod schema output. The structured schema purposefully omits price and discount fields so the model is structurally incapable of proposing money.

• Payments & Billing:

  • PayPal Checkout JS SDK v6 (@paypal/react-paypal-js) for in-chat payment execution.
  • PayPal Orders v2 REST API (Sandbox) for server-side order creation and capture.
  • PayPal-Request-Id header enforcement for payment idempotency.
  • Pre-capture order verification confirming amount, currency (USD), and order state before capture.

• Frontend & Dashboard: Built with Next.js 16 (App Router), React 19, and Tailwind CSS. Features both Dark Mode and Light Mode, a slide-over Customer Decision Timeline Drawer, and an evaluator walkthrough bar.

• Persistence & Security:

  • SQLite WAL mode (better-sqlite3) with atomic conditional order claims (D4 mutation defense).
  • Containerized via multi-stage Docker build on Debian node:22-bookworm-slim.
  • Deployed to Google Cloud Run with a dedicated, least-privilege service account (roles/aiplatform.user) and Google Secret Manager integration.
  • Zero user-managed keys or credentials in source control.

Challenges We Faced

1. Eliminating LLM Price Hallucinations Deterministically

Prompt engineering alone is insufficient for financial compliance. Even heavily instructed models occasionally echo customer proposals (e.g., "Sure, I can do $10").

We solved this by removing financial parameters from the model's output schema entirely and adding deterministic reply validation that intercepts output before it reaches the customer.

2. Race Conditions & Double-Billing Defense (D4)

Under concurrent browser requests or double-clicks, a customer could trigger duplicate PayPal orders.

We implemented an atomic conditional SQL transaction:

UPDATE offers SET paypal_order_id = 'CLAIMING:' || ? WHERE id = ? AND paypal_order_id IS NULL;

Combined with an automatic 5-minute lease expiration, this guarantees idempotent order creation under load.

3. Conversational Edge Cases (E1–E5)

Real customer interactions surface complex conversational turns. We wrote rigorous regression tests ensuring:

• Billing questions asked at the discount floor do not alter active discounts (E2).

• Explicit rejections transition offers to declined without forcing checkout (E3).

• Verbal chat acceptance preserves pending offer IDs without triggering premature capture (E5).

4. Multi-Evaluator Sandbox Isolation

When multiple hackathon judges test the application simultaneously, one judge resetting the environment could break another's active flow.

We implemented an isolated per-customer reset endpoint (POST /api/demo/reset-customer) and locked the global database reset behind HOSTED_DEMO=1, returning HTTP 403.

What We Learned

• The Ledger Belongs to Code, Not Prompts: The most robust architecture for fintech AI is not end-to-end prompting, but a strict separation where the LLM is treated as a natural language interface, while business rules, state machines, and payment authorizations are enforced by deterministic code.

• PayPal SDK v6 Capabilities: Integrating the latest PayPal Checkout SDK with server-side Orders v2 verification unlocks a seamless checkout experience directly inside a live chat UI.

• Rigorous Automated Mutation Verification: Beyond standard unit testing, running code mutation experiments—such as testing that breaking atomic locks or altering price verification causes immediate test failures—is essential before deploying financial agents.

What's Next for ChurnRescue AI

• Proactive Churn Prediction: Analyzing in-app usage anomalies to trigger recovery interventions before the customer's renewal card declines.

• Multi-Currency & Regional Parity: Supporting dynamic currency conversion and localized purchasing power pricing ladders across Europe, APAC, and the Americas.

• Webhook-Driven Automated Retries: Integrating real-time subscription lifecycle webhooks for continuous automated dunning synchronization.

Accomplishments that we're proud of

What we learned

What's next for ChurnRescue AI

Built With

Share this project:

Updates

Submission history