# An AI-written radar daily note where the code owns the numbers and the model only writes the sentences

> /radar now has a daily note written by a local Gemma 3. Small models invent numbers, so the code computes every figure, the model only phrases it, and the output is checked for stray numbers.

- Date: 2026-11-27
- Topics: AI, Radar, Next.js
- Chinese original: https://kbs0830.com/blog/radar-ai-daily-report-numbers-by-code

My [home radar](/radar) (in Chinese) picks up a hundred or two hundred aircraft a day, and the page originally had only numbers and charts. I wanted to add a daily note: two or three sentences saying how many aircraft were received yesterday, the busiest hour, and the most common airline. This is a natural job for a language model, but **a small model cannot be trusted to write numbers**, so I did it the other way round:

**The code computes the numbers, the model only turns them into sentences, and then the code checks them.**

## 1. The code computes the "facts" first

From the radar's daily records, the code works out yesterday's: how many aircraft were received, the most seen at once, the busiest hour, the most common airline and aircraft type, whether there was an unusual type (one marked "rare" in the site's aircraft encyclopedia), the average of the previous 7 days, and the receiver's uptime. These are arranged into a few lines of plain text, and that is the only data the model can use.

## 2. The model only writes

The prompt is short: write 2 to 3 sentences based on the facts below, use only the contents and numbers in the facts, do not mention location, distance, airports or place names, and no title, preamble or bullet list. Temperature 0.4, no streaming, a single call.

## 3. Check the output

The bad things a model does come in a few fixed kinds, so the checks are fixed too:

- **Numbers**: every run of digits in the note must appear unchanged in the facts. The most common mistake of the model is inventing a "35% more than last week". This check is one line of regular expression
- **Location**: the radar is at my home, and the page deliberately does not show its location, distance or coverage. The daily note is the same: words like "nearby", "airport" or "south" send it back. One small trap: an airline's name may itself contain a place name (Japan Airlines, Tigerair Taiwan), so the names in the facts have to be removed before checking
- **Format**: an opener like "Sure, here is the daily note", a title, bullet points, too short or too long are all sent back

If it fails, or Ollama is simply off, a fixed-sentence version written by code is used. The page states whether this note was written by AI or by code, so nobody mistakes the template version for AI.

## 4. When to write it

I did not want another scheduled task just for this (changing schedules needs administrator rights, and it is one more thing to maintain). The approach: when someone opens /radar and yesterday's note has not been written yet, one is written with `after()` **after** the response is sent. Only one runs at a time, and after a failure it does not retry for 10 minutes, so the page does not get slower. The cost is that it is triggered by "the first visitor of the day", so the page says so.

## In practice

Yesterday's note was written by Gemma 3 4B and passed verification the first time: 191 aircraft, busiest 8 to 9 a.m., at most 5 at once, 22 A321neo, 9 China Airlines, all matching what the code computed.

Verification only blocks "new numbers appearing"; it cannot block "attaching a number to the wrong thing". For example, if the facts say 22 is an aircraft type and 9 is an airline, and the model writes them swapped, the check cannot see it. That is the ceiling of this approach. The mitigation is to keep the facts as short as possible, one thing per line, and so far I have not seen it get one wrong.

---

Author: PINGWEI LI (李秉威, Li Ping-Wei)
Original page: https://kbs0830.com/en/blog/radar-ai-daily-report-numbers-by-code
