Chart RS-26 · FN-12 2026-12-02 · 4 min read
Chart lighting

Field note FN-12

Ask your logbook: a database per user, two models, no shared tables

SkyJourney answers questions about your own flights in plain language. A model writes the query, a database that holds only your flights runs it, and a second model is never trusted with a number.

Project · SkyJourney →

In October I shipped “Ask your logbook” in the SkyJourney app. You tap a button on the overview and type a question about your own flights: How many hours have I spent in the air? Have I ever flown on D-AIMA? Which of my flights were diverted? Then a follow-up: And in 2023? Free accounts get one answer a day; premium is unlimited.

The shape

The app talks only to Laravel. Laravel checks who you are and whether you have a question left, then calls one Worker. The Worker does the rest:

  1. Workers AI turns the question into one SQL query.
  2. A Durable Object, one per user, runs it against a copy of that user’s flights.
  3. Workers AI turns the rows into a sentence, if the rows are small enough to phrase.
  4. Code checks every number in that sentence against the rows.

It’s text-to-SQL, nothing fancier, and all the arithmetic happens in SQLite.

From Cloudflare it uses Workers, Durable Objects with SQLite storage and Workers AI. It has AI Gateway wired in and switched off. Queueing and rate limits live in Laravel, which already had them.1

A database per user

The obvious design was a read-only MySQL user and a filter on the user in every query. With a model writing the queries, that means trusting that every single one keeps the filter. I didn’t want the security of the feature to depend on a model remembering a clause.

So each user gets their own SQLite-backed Durable Object, and there is nothing else in that database. A model can write any query it likes, and the worst it can return is the user’s own flights.

Laravel stays the source of truth, and the copy can be thrown away and rebuilt at any time. Its schema does a lot of the model’s work, with views named for what people mean, such as flights actually flown. Keeping the copy in step with Laravel is covered in the note on what stays at the edge.

Workers AI, twice

One model writes the SQL and a second phrases the answer. Models don’t all reply in the same shape, and that caused a quiet bug: one returned a different format, and the Worker read the answer as empty. Nothing failed. Every answer silently became a template, which was correct, just flat. The safety net worked so well it hid the bug.

The SQL model sees the question, today’s date and a description of the schema. It never sees a row. The answer model sees rows only when the result is small. Anything bigger gets a template answer and a table in the app. Follow-ups send the last few questions back with the SQL that answered them.

What the prompt can’t fix, code does

The most useful lesson was about prompts. Stern wording backfires: a strict rule against one view made the model refuse plain questions. When a mistake is mechanical and the prompt can’t fix it reliably, I correct it in code.

The clearest case is time. The model’s sense of “now” is older than today, so it treats recent years as the future and looks for last year’s flights among the upcoming ones. The prompt now states the current year calmly, and code catches what slips through by moving those queries to flights already flown.

Other mechanical fixes went into the data rather than the prompt:

  • Units. Miles and nautical miles are converted in SQL, not by the model, so the converted number is in the rows and passes the number check below.
  • Money. Fares come in mixed currencies, and a shared ticket’s fare is typed on every leg. The copy converts with the rates Laravel sends on each question and counts a repeated fare once, so an answer about spending agrees with the stats screen on the same day.

The model is never trusted with a number

The answer prompt tells the model never to calculate, add up, convert or round anything itself. Rules aren’t enough, so after the model writes its sentence, the Worker checks it. Every number must appear in the rows, in the question, or be the row count. One unbacked number and the user gets a template sentence instead.

Empty results taught a smaller lesson. The template “No flights match that” read as if the app hadn’t understood the question. Empty results now go to the model, which says “No, you haven’t flown to Germany.”

The model-written SQL is also bounded. A guard accepts a single read query, and the object caps the size of every result. The guard is for predictability; the per-user database is the security.

Built on Cloudflare

Cloudflare products Workers, Durable Objects (SQLite), Workers AI

Request
clearance