Don't validate the output. Validate that you were allowed to generate it.
Introduction I run a site that collects overseas viewer comments about individual anime episodes, translates them, and publishes them. It updates automatically every day. There is one failure mode that matters more than all the others: creating a page for an episode that has not aired yet. If the page exists before the broadcast, there are no comments to put on it. But the heading "Episode 8 — overseas reactions" is already live. An empty page is recoverable. What is not recoverable is a pipeline that decides an empty page looks bad and fills it with something plausible. At that point invented sentences are wearing the face of real people. This post is about the check that prevents that, and about the day it actually fired. The overall shape The obvious implementation is arithmetic on dates: Take the air date of episode 1 Assume weekly broadcast Count the weeks elapsed until today Treat every episode up to that number as aired That works for producing candidates, but it is not evidence that anything aired . A skipped week makes the real count lower. So does a recap episode. Calendar arithmetic never observes the broadcast; it only restates an assumption. So I split the pipeline in two: Candidate generation — weekly arithmetic, guessing which episodes are missing. Guessing is fine here. Existence check — does an observation from outside my system exist for this episode? No guessing allowed here. For the existence check I use the per-episode discussion threads on MyAnimeList (a large anime database; MAL from here on). One thread is created per episode after it airs, and the timestamp of the first post in that thread is readable. Viewers post after watching. So that timestamp is external evidence that the broadcast happened. Better still, it lives in exactly the same place I fetch the comments from, so verification costs no additional data source. The core of the implementation The check is a subtraction between what I claim and what the outside world recorded. /** * @