Inspiration

It started with a dinner bill.

A family member came home after a celebration dinner and casually mentioned the restaurant had charged a "service charge." I looked it up and found out the Central Consumer Protection Authority had banned mandatory service charges in India back in August 2022. The restaurant had collected it anyway. So had hundreds of others, for years after the ban.

That moment stuck with me. Not because of the Rs. 150, but because of the gap it revealed: India has strong consumer protection laws. Almost nobody knows how to use them.

The same problem exists in hospitals. Patients receive bills with columns labelled "disallowed" or "not payable" and pay them anyway because the document is designed to confuse, not inform. Insurance settlement sheets list amounts the insurer rejected, and hospitals quietly collect them from patients who don't know the difference.

I wanted to build something that closes that gap.


How I Built It

BillGuard is a full-stack web application built in Python (FastAPI) with a plain HTML + Tailwind CSS frontend. No React, no build tools, just something that works immediately for anyone with a browser.

The core pipeline:

  1. Image preprocessing -- Pillow boosts contrast (1.6x) and sharpness (2.5x) before the image ever reaches the AI, making OCR dramatically more reliable on low-quality phone photos
  2. Gemini Vision API -- sends the preprocessed bill image with a detailed prompt encoding Indian consumer law (CCPA 2022, GST Act, Legal Metrology Act, NPPA drug pricing, Clinical Establishments Act)
  3. Server-side validation -- Gemini's math is never trusted. The backend independently sums billed_amount - fair_amount across all flagged items to compute the true overcharge
  4. Scam Map -- every analysis auto-extracts the business name and address, geocodes it via OpenStreetMap Nominatim, and pins it to a crowd-sourced Leaflet.js map showing risk levels across India

The model fallback chain (gemini-2.5-flash-lite -> gemini-2.5-flash -> gemini-2.0-flash -> gemini-2.0-flash-lite) ensures the app never goes down due to quota limits on a single model.


Challenges

Getting the AI to be consistently aggressive, but not wrong. Early versions of BillGuard would flag Dineout discount lines (negative values) as violations, and mark the correct 18% GST on platform convenience fees as illegal. The fix was not more AI, it was better rules. I wrote dedicated rule sets for each bill type (hospital, restaurant, online order) with explicit disambiguation logic for edge cases like TPA insurance documents and cover charge waivers.

Geocoding garbled OCR output. Gemini would sometimes return addresses like "PERUNGUDICHENNAI" -- city names merged with street names due to OCR artifacts. Standard geocoders return nothing for these. I built a smart fallback system that detects known Indian city names concatenated with surrounding text, inserts spaces, strips PIN codes, and tries progressively simpler address variants until one resolves.

Making the output actionable, not just informative. Knowing you were overcharged is not enough. BillGuard tells you the exact text to say to the manager, the specific helpline to call (1915, National Consumer Helpline), and which form to file. That last mile -- from "here is the problem" to "here is what to do right now" -- took as much thought as the detection itself.


What I Learned

  • Rules beat vibes. A well-written rule prompt outperforms a vague "detect fraud" instruction every time. Specificity is the difference between a useful flag and a false positive.
  • Server-side math matters. LLMs confidently produce wrong arithmetic. Never let the model compute financial totals that affect user decisions.
  • The map is the product. Individual bill analysis is useful. A map showing that the same restaurant has been flagged 23 times -- that creates accountability at scale.

What's Next

  • Mobile app with live camera scanning at the restaurant table
  • WhatsApp bot: forward a bill photo, receive a fraud report
  • Pharmacy bill scanning against DPCO-controlled drug prices
  • Vernacular support: Hindi, Tamil, Telugu
  • Regulatory dashboard for CCPA and state health departments

Every Indian deserves to know if they are being cheated before they leave the table.

Share this project:

Updates