ComplaintFlow

Connecting

ComplaintFlow

An AI pipeline that triages real consumer complaints about US banks and lenders.

A fine-tuned model classifies each complaint by product and issue, an LLM summarises it and rates its urgency, and complaints the model is unsure about go to a person for review. Everything below is running live.

Built by Hasnain Naqvi · GitHub · LinkedIn

Live pipeline

Complaints moving through the pipeline as they arrive: classified, summarised, and sent to a person when the classifier is unsure.

Try it

Send a complaint of your own, or a real one from the CFPB database, and follow it through the pipeline. Each visitor can send 10 an hour.

What you send appears on the Live page for everyone, so leave out names, account numbers and anything else personal.

Once you send a complaint, it appears here and updates as it is classified and summarised, usually within a few seconds.

How it works

Each complaint passes through Kafka from one worker to the next, so every step can fail, retry or be scaled on its own.

  1. Intake

    Complaints come from the Try it box or from the demo feed, which sends a real CFPB complaint every 10 seconds. A FastAPI service saves each one to PostgreSQL, publishes it to the Kafka topic complaints.raw and replies straight away.

  2. Classification

    A ModernBERT model, fine-tuned on 97,407 past complaints, picks one of the 85 product and issue pairs that consumers chose when filing. It runs as an ONNX model on the CPU and answers in a fraction of a second.

  3. Review

    When the model is less than 30% confident, the complaint goes to a person, who confirms or corrects it on the Review page. That threshold comes from the chart in Results: it sends about 7% of complaints to review and makes the answers kept more accurate.

  4. Summary and urgency

    Separately, an LLM (GPT-6 Luna) writes a short summary and rates the urgency. It is capped at 500 calls a day, and text it has seen before reuses its earlier summary, so classification never waits for it.

  5. Reliability

    A message that fails is retried after 5 seconds, 30 seconds and 2 minutes, then set aside on a dead-letter topic. A worker stopped mid-run picks up where it left off without losing or repeating a complaint, which an integration test checks.

  6. Live updates

    Each step announces itself on Kafka, and the API streams those events to this page with Server-Sent Events. That is how the feed above fills in.

Built with

  • Python
  • FastAPI
  • Kafka
  • PostgreSQL
  • ONNX Runtime
  • OpenAI
  • Docker
  • Next.js
  • TypeScript
  • Tailwind CSS

Results

How the classifier compares with the other approaches tried, how the confidence threshold was chosen, and what the pipeline has handled so far.

Approaches compared

Each approach chose a product and an issue for the same held-out CFPB complaints, which none of them saw while being built.

Choosing the confidence threshold

Answers below the threshold go to a person instead of being decided automatically. Raising it makes the answers kept more accurate, at the cost of more complaints to review.

Pipeline so far

Every complaint the live pipeline has handled, including the demo feed. Today means since midnight UTC, when the daily LLM limit resets.

About

ComplaintFlow is a personal project by Hasnain Naqvi. It shows a complete backend system with machine learning at its core: event streaming, workers that recover from failure, a model trained and evaluated on real data, and a person in the loop for the cases the model is unsure about.

The complaints are real, from the Consumer Financial Protection Bureau's public Consumer Complaint Database: those received from January to July 2026 that include the consumer's own account. The CFPB removes names and account numbers before publishing, which is why some text shows XXXX.

Limitations

  • The right answers are the product and issue each consumer picked when filing, so some are wrong or ambiguous, and accuracy is measured against those choices.
  • Summaries and urgency come from the LLM and are not measured; doing so would need complaints labelled by hand.
  • The complaints end in July 2026, so the model has not seen anything newer.
  • It is a demonstration, not a tool for deciding real complaints. Anything sent with Try it appears on this page for everyone.