Where we let AI in
Lots of grocery products aren’t in any nutrition database, or they’re in one with only partial data. So we added an ability in FreshLedger to let users photograph the label and other relevant pieces of data present on a product’s packaging. That’s not risk-free. Change never is. A wrong number here goes straight into someone’s nutrition data, skewing the overall results. So we decided up front exactly where the AI is to be trusted in this flow.
First, a person checks the scanned text of the label before any AI sees it. Then the AI does what it’s good at: turning messy and unstructured OCR text into clean, structured data. The AI doesn’t get the last word. Plain rules in the code check its work.
- Do the numbers it used actually appear on the label?
- Do the calories roughly add up from protein, carbs and fat?
- Is anything physically impossible, like more sugar than total carbs?
Anything that fails goes back to a person. And the AI’s own confidence score never counts as a pass.
“That’s two human steps. Why?” That’s a fair thing to question. For now and for this flow, this works. However, if volume grows, the first step is the one to automate: AI reads the photo, and our own verification steps check that reading before anything gets structured. The final human review stays, because that’s where the judgment is.
Predictable checks around an unpredictable AI
AI’s answer is non-deterministic, which can have real consequences for live systems. The problem can then spiral as a small chain-link of non-determinism can then create a chain reaction of unpredictable ramifications as that AI output becomes mutated inputs as it flows deeper and deeper into said systems. In a world where agentic integrations can process inputs faster than a human can process its outputs, there’s a strong need for guardrails and circuit breakers that put a hard pause on any output that doesn’t fit within a defined structured set of criteria.
Having said that, unpredictable output that doesn’t fit that criteria shouldn’t always be taken as trash. Sometimes the criteria is too small a box to fit the different possibilities that are valid for a given system. These possibilities need to be evaluated as well, but in a controlled environment. As more details arise, there may be needs to adjust that box and its set of deterministic tests.
Software development isn’t about preventing change, but rather building guarded flexibilities that allow continued servicing to the end-user, all the while learning and improvements are taking place.
Under the hood
The flow, step by step
Scan a barcode
│
▼
Found in a nutrition database, with a complete label? ── yes ──▶ Graded
│ no
▼
User photographs the barcode, nutrition panel and ingredients
│
▼
PERSON Admin runs OCR on the photos and checks the text
│
▼
AI Reads the checked text into a structured, per-serving label
│
▼
CODE Converts to per 100 g or 100 ml and normalizes units
│
▼
CODE Runs the checks ───── pass ─────▶ Scored
│ fail
▼
PERSON Admin corrects the values, or marks the label unscoreableWhen the admin corrects a label, they enter what’s printed on the package, and the same math runs. The softer checks aren’t re-run on a person’s input: human judgment supersedes. Every record notes whether it was structured by the AI or by a person.
What the AI does, and what it never does
If the AI can’t produce a clean reading, the label goes to a person rather than guessing its way to a score.
The checks
Strict checks. Any one failure sends the label to a person.
Soft checks. These flag a label when they fire (at launch, a single soft flag is enough).