The problem
“Pinpoint the accurate source to each finding with the exact URL.” The requirement, word for word, from the design brief.
Lornell Real Estate’s brokers call property owners. When the owner is an LLC or a trust, someone has to find the person behind it and a way to reach them. The firm had been using Google’s Gemini model for that research.
The answers looked useful: a phone number, an email, a note that confidence was “high”. But the model graded itself, and its sources came back as one flat list for the whole answer, so nobody could tell which link proved which number. The prompt asked the model to check the state’s corporate and deed registries; nothing made it do so. Results went straight into the CRM.
That output feeds outbound calls. A wrong number means a broker phoning a stranger about a building they don’t own, and a bad record that sits in the CRM until someone notices.
What I built
A four-stage pipeline with a review queue at the end.
- Find the real people first. Before any AI call, the owner is classified. An LLC or corporation is looked up in the state’s Corporations Division. A trust or estate has its trustee or executor parsed from the name. An individual is taken as is.
- Research with receipts. Gemini runs grounded web research aimed at those named people. Every finding must include the exact URL where it was found.
- Score in code. The code sets confidence by counting independent websites that agree. Toll-free numbers are dropped.
- Stage, don’t write. Results land in a review queue, where a person approves or rejects them, singly or in bulk.
Every result is cached with a shelf life that fits the fact: corporate records keep for 180 days, contact details for 30. In the app, paid lookups start from a click, never on page load. Everyday work runs on the faster Gemini Flash model; the slower Pro model is kept for deep research.
Diagram: Owner record, then A (registry, trustee or self), a cache check, B (grounded research with a URL per finding), C (code-computed confidence), D (staged row), then human approval, then the CRM.
The hard parts
The model can’t grade its own work.
A language model will call a number it half-remembers “high confidence”, so the model no longer gets a vote. Each finding must carry its source URL. The code groups identical findings and counts how many different websites back each one. Two or more independent sites make it high. A single authoritative source, such as a state filing or a deed, makes it medium. Anything else is low.
Under the hood
- The Gemini call uses a
responseJsonSchemawithsourceUrlrequired on every finding. Gemini can’t enforce URL format, so a Zod parse rejects malformed URLs after extraction. verify.tsnormalizes phones and emails, groups by value and counts distinct hostnames. Authoritative types: state corporate filing, company website, deed, probate record, skip trace. Numbers the firm already held from a skip-trace vendor or a listing marketplace count as extra corroborating domains.- Eight toll-free prefixes (800, 888, 877, 866, 855, 844, 833, 822) are dropped before scoring. Only mobile lines are marked textable.
- The orchestrator never sets confidence; only
verifyAndScoreFindingsdoes. - Stage A dedupes principals, because the state lists a person once per role. Without it, the research prompt spent its per-subject query budget re-searching one name.
- The registry step handles throttling and bot protection with fallbacks and caches results for 180 days.
A person decides what reaches the CRM.
Five parts of the system used to write straight into the CRM: batch AI research, a skip-trace import, statewide owner research, the deal-sheet generator and the manual save button. All five now stop at a review queue. Each staged row shows what would be written, where it came from and how confident the code is. About 1,403 contacts were already waiting when I added bulk approve and reject.
Under the hood
staged_outputs(migration 108) holds the payload as jsonb,source_refs, a confidence enum and review metadata.promote_staged_outputchecks the row is still pending, upserts the payload into the target table and records the reviewer. Rejection keeps the payload for audit. Migration 109 added set-based bulk versions.- CSV imports and statewide prospecting pulls later joined the same queue, so every route into the contact list passes one gate.
Never pay for the same answer twice.
Paid research is cached and reused. When the cache moved to a more precise key, 1,467 existing entries had to be carried over. I relabelled only the 110 whose property traced to exactly one town and left the 43 ambiguous or unmatched ones alone, because a wrong match is worse than none. Then I filed 110 past deal sheets straight from cache, at no AI cost.
Under the hood
- The key moved from
type|prop_idtotype|town_id|prop_id, because a state property id is not unique across towns. Migration 257 found 1,467 old-format rows and 0 new. Of 153 cached properties, 110 resolve to one town, 23 to several, 20 to none. Only the 110 were rewritten, since for those the old key provably implied the town. Re-running it changes nothing. backfill_deal_sheets.pyrenders withcache_only: a miss prints “not researched” instead of calling Gemini, and a pre-flight guard refuses to file until migration 257 has run. From its docstring: “filing a Springfield deal sheet under a Worcester parcel is worse than filing nothing.”- Shelf life by type: entity and corporate 180 days; zoning, environmental and location 90; financial, tenants and market 60; contact and approach 30; portfolio 1.
- Model tiering: Gemini 3 Flash (preview) for standard extraction, Gemini 3.1 Pro (preview) for grounded deep research, Gemini 2.5 behind a flag.
Results
- 5 of 5 direct-to-CRM write paths now wait for a person. In production.
- Every finding must carry a source URL, and confidence is computed in code. Enforced by the output schema and the scoring module.
- 110 past deal sheets filed at $0, and 43 skipped rather than guessed. Counts from the backfill script and migration 257; filed September 8, 2026.
- value to confirm
- value to confirm
- value to confirm
What’s next
- A published accuracy number. A test set of 15 real owners (5 LLCs or corporations, 4 trusts, 2 estates, 4 individuals) and a scoring script are built. The pass mark: the right person named at least 80% of the time, and a source cited for every finding. Next: hand-check the expected answers, run it against the live system, and publish the result.
- Approvals tied to reviewer roles. The queue decides what reaches the CRM. Next: record every approval against a named reviewer’s role.
- Mobile numbers from a licensed source. Personal mobiles are rarely on the public web, and the design leaves a slot for a paid provider. Next: choose one, with a compliance check on how the numbers may be used.
Stack
Gemini 3 Flash and 3.1 Pro with Google Search grounding · TypeScript and Zod · Next.js 16 on Cloudflare Workers · Supabase Postgres · Vitest.
If AI is about to write to your customer records, make it show its work first.
Have a similar problem? Book a call.