Engineering AI Nutrition & Ingredient Intelligence: Conversational State Machines, Data Contracts & Prior-Window Analytics
Unstructured conversational AI pipelines often degrade analytical tables through incomplete free-text writes, JSON-to-SQL schema drift, same-timestamp window overlap, and correlated-feature misinterpretation. AI Nutrition & Ingredient Intelligence addresses these failure modes with designed safeguards: a three-stage LLM Gatekeeper state machine, shared Zod contracts verified at 410/410 row parity against node:sqlite in the synthetic test fixture, tenant-partitioned 1 PRECEDING Medallion windows (Bronze -> Silver -> Gold), and explicit statistical interpretation checks.
1. How are trust boundaries organized across ingestion, orchestration, and BigQuery?
- Zone 1 - Multimodal Client & Webhook Channels: React 19, Vite, and Tailwind CSS v4 SPA alongside a serverless messaging webhook accepting free text, voice transcripts, plate photos, and GTIN-13 barcodes.
- Zone 2 - Serverless Orchestration & Contract Core: Node.js Cloud Functions managing tenant-scoped conversational holds, three-stage Gemini structured routing, OAuth 2.0 FatSecret catalog lookups with token caching, deterministic additive rules, and runtime Zod validation.
- Zone 3 - Governed Analytical Warehouse & ML: Change-stream export into Google BigQuery, three-layer dbt Medallion models (
Bronze -> Silver -> Gold), BigQuery ML (BOOSTED_TREE_CLASSIFIERandARIMA_PLUS), and an optional Semantic Scholar Graph API boundary.

2. How does the three-stage LLM Gatekeeper hold incomplete submissions?
0.1), a zero-temperature Event Extractor (0.0), and a deterministic Taxonomy Auditor holds incomplete composite meals in ephemeral session state before canonical events are written.When status === 'NEEDS_CLARIFICATION' (triggered by missing_gluten_verification, missing_dressing_or_sauce, or missing_prep_state_raw_vs_cooked), the orchestrator stores pending_text in a tenant-scoped session map and prompts once. Resolved food items are checked against deterministic additive classifications grounded in FDA Food Additive standards and Monash FODMAP polyol criteria (distinguishing Sorbitol E420, Maltitol E965, and dairy-derived Lactitol E966 from Erythritol).

3. How do shared Zod contracts and dbt Medallion windows improve reliability?
Zod schemas validate ingestion, Silver, and Gold structures consistently, while Gold SQL models partition by tenant_id and end epoch ranges at 1 PRECEDING, verified across all 410 synthetic fixture records in node:sqlite.WINDOW
w24 AS (
PARTITION BY tenant_id
ORDER BY event_epoch_sec ASC
RANGE BETWEEN 86400 PRECEDING AND 1 PRECEDING
),
w48 AS (
PARTITION BY tenant_id
ORDER BY event_epoch_sec ASC
RANGE BETWEEN 172800 PRECEDING AND 1 PRECEDING
)
4. Why must predictive feature attribution be separated from causal inference, and what tradeoffs shaped the design?
7.29x while boosted stumps assign 85.3% attribution to one feature and 0.0% to the other. These synthetic figures illustrate why model importance is not causal evidence on a real person, and why abs(r) >= 0.35 correlation warnings and uncertainty intervals accompany exploratory outputs.| Architectural Decision | Chosen Design | Tradeoff Accepted | Engineering Rationale |
|---|---|---|---|
| 3-Stage LLM Pipeline | Gatekeeper + Extractor + Taxonomy | ~2 sequential calls on ambiguous logs | Holds incomplete composite entries before Bronze storage |
| Hybrid Additive Lexicon | Deterministic E-numbers + LLM parsing | Requires curating additive rule tables | Consistent Lactitol E966 vs. Erythritol classification |
| Offline Literature Interface | Document contract; block live calls in demo | Contract spec shown instead of live cards | Never fabricates mock academic citations in public code |
seed = 20261114) demonstrate AI orchestration, data engineering contracts, and statistical modeling patterns only. It is not a medical device, clinical diagnostic tool, or causal treatment recommender.Explore the Synthetic Demonstration or Connect With DBMarketer
Contact Database Marketer
Inquire about telemetry audits, modern data stack migrations, enterprise AI agent skills, or fractional principal architecture retainers.