Portfolio project · October 2026
Case study
Context
On agricultural traceability platforms, client dashboards are usually built by hand in a BI tool. Every new request means BI work, and each number's definition lives inside the datasets. When the same field-season is assessed against several standards (EUDR, ISCC, 45Z), definitions drift apart over time.
I wanted to see how far you can get by letting people ask directly, without losing the ability to audit every number.
What I built
- A semantic layer in YAML: metrics, allowed dimensions, declared joins, value dictionaries and known gaps.
- A planner that doesn't write SQL: it returns a typed plan (metrics, dimensions, filters). If information is missing it asks; if no metric fits it says so.
- A validator and a deterministic compiler that turn the plan into SQL, run under a read-only role with a timeout and a row cap.
- Verified queries for frequent questions, answered without an LLM.
- On every answer: the metric definition, the SQL, the source tables and sample rows (“How was this calculated?”).
How it's tested
A set of 45 questions with expected plans and results, including ambiguous, out-of-scope and injection cases. Each stage is scored separately and CI blocks changes that lower accuracy. Latest run:
| Correct result (answerable questions) | – |
| Refusals and injections handled correctly | – |
| Median latency (with LLM) | – |
| Average cost per question | – |
What's real and what isn't
| Pipeline: router, planner, validator, compiler, read-only executor | Real | Runs in this demo, with a real LLM |
| Per-stage evals, gated in CI | Real | A change that lowers accuracy can't merge |
| Semantic layer | Real | A proposed model; in a real setting it gets validated with each metric's owners |
| Producers, fields, Crop Stories, alerts | Synthetic | Seeded, placed in real departments |
| Land-use change (EUDR) | Simulated | Next step: JRC GFC2020 + MapBiomas |
| MongoDB Atlas as the document source | Real | The ELT extracts from Atlas, flattens and builds the marts |
| Marts on Postgres/PostGIS | Partial | Same SQL; the marts run on DuckDB today |
| Login, multi-tenant, row-level security | Not built | Needed before any client sees it |
The rule I followed
When an eval fails, the fix goes to the semantic layer first (a description, a synonym, an allowed dimension, a new mart), then to the examples, and only last to the prompt. Public benchmarks from dbt Labs and Cube point the same way: with a semantic layer, accuracy depends more on the modeling than on the model.
How I'd take this to a real team is in the implementation plan.