BetterInvest’s AI chatbot, built in-house.

An AI analyst for structured-credit data. Ask about assets, collections, repayments and contracts in plain English. Every number comes from a deterministic query, never from the model.

In-house AI Chatbot Assets & Repayments Contract Search

The LLM never produces a number.

A deterministic query layer produces every figure. The model only handles unclear wording and explanations, and a grounding check blocks any figure it invents.

The problem

One question. Several sheets.

The company’s data lives in Google Sheets spread across teams. Answering a simple question like “what is pending for this project?” meant opening several sheets, matching inconsistent names and adding up by hand.

That is slow and error-prone. Leo reads those sheets on a schedule and answers from a single database, with the source and data freshness on every answer.

Architecture

From sheets to a grounded answer.

Google Sheets & Drive→ Ingestion→ PostgreSQL→ Deterministic query layer→ LLM · wording only→ Grounding check→ Answer + source + freshness

Common questions skip the LLM entirely and are answered straight from the query layer.

Results so far · pilot stage

Accurate, fast and cheap to run.

3
live data sources
~1,700
assets in one queryable store
15/15
validation questions matched ground truth
173
data-quality fixes made at source
<1s
for most answers
How it works

Seven layers, built for trust.

Each layer exists to keep the numbers right.

01

IngestionELT pipeline

A registry-driven loader pulls sheets through the Google Sheets and Drive APIs with read-only service-account access and writes to PostgreSQL. It checks a header contract before loading and keeps the last good data when a check fails.

Loads are idempotent, with row-level change history, overrides, duplicate and test-row flags, and daily refresh with freshness tracking. One source has 51 tabs in 8 different header layouts, which the loader maps by column name.

02

Entity resolution

Clients, projects and assets are matched with aliases and fuzzy matching, plus guardrails so “Project 63” is never silently swapped for “Project 62”.

03

Query layerDeterministic

A deterministic router classifies questions and runs parameterised lookups: totals, profiles, comparisons, group-by, overdue and due-soon views. Common questions never reach the LLM, which keeps most answers under a second and the cost near zero.

Parameterised lookups were chosen over free text-to-SQL for safety and accuracy.

04

LLM layerTool-calling

For free-text questions, a tool-calling LLM picks the lookup and explains the result. It launched on an open model, with a move to Claude Haiku and Sonnet planned. Model tiering, token budgets, caching and reasoning-effort limits keep cost predictable.

05

Hallucination control

A numeric grounding check compares every figure in the model’s text with the lookup result and replaces any figure it can’t find. The model never produces a number.

06

Retrieval over contractsFull-text search

About 6,600 contract files are indexed with PostgreSQL full-text search (tsvector with ranked retrieval) and trigram similarity for misspellings. Answers cite the file, the page and a verbatim passage, and say whether a contract matches a funded asset.

Next phase: OCR for scans and an LLM generation step with citations (RAG). Embeddings could be added for hybrid retrieval.

07

Product & security

Conversation scope carries across follow-ups. Charts, Excel export, voice input and pinned client pages all run without any LLM call.

Access is admin-approved with role gating for sensitive modules, a per-user daily cap, and an audit log that stores no data. A status page shows the freshness and health of every source.

What I learned

Three rules I’d build by again.

01

Keep the LLM out of the numbers.

02

Put data contracts at every boundary.

03

Make refresh failures visible and safe.

Stack

What it’s built with.

Next.js React PostgreSQL · Supabase Google Sheets & Drive APIs Tool-calling LLMs Groq Claude Haiku & Sonnet (planned) Tavily search Vercel (planned) Built with Claude Code
Sample chats

See Leo in conversation.

Every answer comes back with its source and how fresh the data is.

Leo
What is pending for Project 63?
₹1.20 Cr is outstanding on Project 63 across 2 tranches. The next repayment of ₹60.0 L is due on 15 Nov 2026.
Source · Repayment trackerRefreshed today, 6:00 AM
And what was disbursed so far?
A total of ₹2.00 Cr has been disbursed on Project 63.
Plain-English lookupFollow-ups keep the project in scope
Leo
Which assets are due in the next 30 days?
3 assets have repayments due by 20 Nov 2026:
Project 12₹40.0 L
Project 41₹25.0 L
Project 63₹60.0 L
Source · Repayment trackerRefreshed today, 6:00 AM
Total due: ₹1.25 Cr. Want this as an Excel export?
Due-soon viewsTables, charts and Excel export
Leo
Find the payment clause in the Project 41 agreement.
Found in the Discounting Agreement, page 7:
“Payment shall be released within 30 days of delivery acceptance.”
Source · Contract libraryMatches a funded asset
Contract searchCites file, page and the exact passage

Illustrative conversations with sample data.

Want to know more about Leo?

Leo is an internal BetterInvest tool. Get in touch and I’ll happily walk you through it.

Get in touch Back to works