Dev.to AI ๐Ÿค– Ai ๐Ÿ‘ 0 ๐Ÿ“– 6 min read

Don't let the LLM write the price: how we built estimate-from-a-photo for tradespeople

I'm building Vistobra, an estimate app for people who work alone in the trades: electricians, painters, plumbers, handymen. The main feature sounds simple. You're at the customer's house, you take a photo of the job (or

I'm building Vistobra, an estimate app for people who work alone in the trades: electricians, painters, plumbers, handymen. The main feature sounds simple. You're at the customer's house, you take a photo of the job (or say "three outlets and a ceiling fan"), and you get an estimate with line items, quantities and prices, ready to send.

The tempting way to build this is to send the photo to a vision model and ask for an estimate. It works in a demo. It's also the fastest way to put a made-up number in front of a homeowner, with the tradesperson's name on it.

The prices an LLM writes look plausible, change from run to run, and nobody can tell you where they came from. So we split the job. The model looks at the photo and decides what the job is and how much of it there is. Code decides how much it costs. Here's how that works in practice, with simplified versions of our TypeScript.

1. The model picks from a numbered list

Every trade has a catalog of services, each with a unit and a price range. Before calling the model we build the list the model is allowed to use: first the services this person has already used (with their own prices), then the trade's catalog adjusted for their region. It's capped at 400 lines to keep the cost of each call bounded.

The list goes into the system prompt as plain numbered lines:

0 ยท Replace single outlet (same position) ยท each
1 ยท New outlet or switch point ยท each
2 ยท Breaker panel up to 12 circuits ยท each
...

And the rules are blunt (translated from our prompt, which is written in Portuguese):

- Choose services ONLY from the numbered list below: "n" = the number and "d" = the name exactly as listed.
  Never invent a service outside the list.
- What he SAID wins: if he named the part ("20 A outlet"), pick the line that says that,
  even if a simpler one exists.
- NEVER give a price or a value. The price comes from the app's table.

The response uses structured outputs with a JSON schema, so the shape is guaranteed:

items: { n: number; d: string; qty: number; why: string }[]
questions: { question: string; options: { text: string; recommended: boolean; adds: { n: number; qty: number }[] }[] }[]
forgotten: { n: number; d: string; qty: number; why: string }[]   // "usually goes with it"
marks: { label: string; x: number; y: number; w?: number; h?: number }[]  // boxes on the photo

There is no price field anywhere in the schema. The model can't return one even if it wanted to.

2. Ask for the name too, and trust the name over the number

Early on we hit a quiet bug: the user said "20 A outlet", the model returned the right description but the index of the plain outlet swap next to it. An off-by-one in a list of 400 lines is easy to miss and it changes the price.

The fix was to make the model repeat the service name (d) next to the index (n), and to correct the index from the name on the server:

function fixIndexes<T extends { n?: unknown; d?: unknown }>(list: T[], catalog: { d: string }[]): T[] {
  const norm = (s: unknown) =>
    String(s ?? '').normalize('NFD').replace(/[ฬ€-อฏ]/g, '').toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim();
  return list.map((x) => {
    if (!x.d || norm(catalog[Number(x.n)]?.d) === norm(x.d)) return x;   // index and name agree
    const n = catalog.findIndex((c) => norm(c.d) === norm(x.d));
    return n >= 0 ? { ...x, n } : x;                                      // the name wins
  });
}

It costs a few extra output tokens per item and removed that whole class of errors.

3. Validate everything, drop what doesn't fit

A schema guarantees types, not sense. So the server checks every field before the app sees it:

  • n must be an integer inside the list; anything else is dropped.
  • Quantity must be a finite number above 0 and at most 100,000, rounded to two decimals.
  • At most 30 items, 3 questions, 4 options per question and exactly one recommended option (if the model marks zero or two, the first one becomes the recommendation).
  • Labels and explanations are trimmed to a fixed length.

And one rule that matters more than it looks: if nothing from the catalog survived, no model text is shown at all. The app shows its own fixed message ("I couldn't find a job to estimate in this photo"). The model also returns a flag for "this isn't a construction job" (a selfie, a screenshot, a plate of food), and in that case every list is emptied. Free text from the model only reaches the screen next to real line items.

4. Where the price actually comes from

Once we have line numbers and quantities, pricing is ordinary code:

const price = mine.get(service) ?? tradeTable[service] * regionFactor(trade, region);
  • If the tradesperson has charged for this service before, their own price wins.
  • Otherwise it's the trade's reference price adjusted by a regional factor. The region comes from the location of the photo, or from their profile if the photo has none.
  • Each line also carries a min and max, so the screen can show "typical range in your area" and the person can see when their number is far from it.

Then they review every line. Nothing goes to the customer until they press send.

5. Edits by voice, with a guard on numbers

After the estimate is built, the person can type or say a change: "make it five outlets", "drop the inspection", "I charge 90 each". A second, cheaper model call turns that into operations against the current list:

type Edit = {
  qty: { i: number; qty: number }[];      // change quantity of line i
  remove: number[];                        // remove line i
  add: { n: number; qty: number }[];       // add catalog service n
  price: { i: number; value: number }[];   // set price of line i
  understood: boolean;
};

The interesting part is price. A model asked to "apply the change" will sometimes invent a price, or read a quantity as a price. So a price edit is only accepted if that number literally appears in what the person said:

const said = numbersIn(request);              // handles "90", "1,500.50", "$ 70", "1 500"
const times = (v: number) => said.filter((n) => Math.abs(n - v) < 0.005).length;
const qtys = edit.qty.map((x) => x.qty);

edit.price = edit.price.filter(({ value }) =>
  // said once, it can't be both a quantity and a price ("there are 70 outlets" is not $70);
  // said twice, it can ("5 outlets at 5 dollars")
  times(value) > 0 && (!qtys.includes(value) || times(value) > 1));

If the request wasn't about the estimate, or nothing valid is left after these checks, the app answers "I didn't get that" with its own words instead of whatever the model wrote.

6. Caching keeps it affordable

The system prompt is long: the rules plus up to 400 catalog lines. But it barely changes: it's the same for everyone in the same trade and language who hasn't built their own price list yet, and for any one person it's identical from call to call. So it goes in a cached block. You pay full price for it once, then a fraction on every call that reuses it. The only parts that change per call are the photos and the sentence the person said.

What I'd tell anyone building something similar

  • Let the model do perception and mapping: what's in the photo, how many, which known service it matches. That's what it's good at.
  • Keep anything that ends up on an invoice deterministic and traceable to a table or to the user.
  • Make the model repeat a human-readable label next to every ID, and reconcile on the server.
  • Validate the meaning, not only the types, and have the app speak in its own words when the model's answer doesn't hold up.
  • Treat every number in a free-text edit as suspicious until you can point to where the user said it.

If you've solved the "LLM touches money" problem differently, I'd like to hear how. And if you write estimates for a living, the app is at vistobra.com/us (iPhone and Android, free to start).

Renan, founder of Vistobra

๐Ÿ“ฐ Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.