Skip to content
All writing

Nov 2026

A build that refuses to publish an unsourced legal answer

How Tama ba 'to? turns its accuracy rules into code, so an answer without a verdict, a scope, or an official source can't reach the site.

Tama ba 'to? answers everyday road questions like "Bawal ba mag-counterflow ang motor kapag traffic?" with a verdict (PWEDE, BAWAL, or DEPENDE) and the law behind it. People may act on what it says. A wrong answer can cost someone a fine, or worse.

So the accuracy rules can't live in a README that someone has to remember. They live in the build. If an answer breaks a rule, the site doesn't deploy.

Every answer is a file with a schema

Each answer is one JSON file in the repo, validated with Zod. A published answer has to have:

  • a verdict, and if the verdict is DEPENDE, the condition it depends on
  • a scope: a nationwide law, or a local rule like the Metro Manila Traffic Code, so a local ordinance is never presented as national
  • at least one legal citation
  • the date it was last verified
  • an English version that matches the Filipino one

Most of these are cross-field rules, so they live in a superRefine:

.superRefine((entry, ctx) => {
  // Drafts are allowed to be incomplete; they are never published
  if (entry.needsVerification) return;

  if (!entry.verdict) {
    ctx.addIssue({
      code: "custom",
      path: ["verdict"],
      message: "Published answer must have a verdict (PWEDE, BAWAL, or DEPENDE).",
    });
  }
  if (entry.verdict === "DEPENDE" && !entry.condition?.trim()) {
    ctx.addIssue({
      code: "custom",
      path: ["condition"],
      message: "Answers with verdict DEPENDE must explain the condition.",
    });
  }
  // ...scope, citations, lastVerified, English version
});

The English check compares counts, not just presence. If the Filipino answer lists two fines and the English one lists one, the build fails, so a translation can't quietly drop a penalty.

Sources must be official

A citation link can't point anywhere. It has to be a government site (*.gov.ph) or a short list of statute repositories, like lawphil.net and the Senate and judiciary libraries:

export function isApprovedPrimarySourceUrl(rawUrl: string): boolean {
  let parsed: URL;
  try {
    parsed = new URL(rawUrl);
  } catch {
    return false;
  }
  if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return false;
  const hostname = parsed.hostname.toLowerCase();
  if (hostname.endsWith(".gov.ph")) return true;
  return APPROVED_PRIMARY_HOSTS.some(
    (allowed) => hostname === allowed || hostname.endsWith(`.${allowed}`),
  );
}

News articles and blogs are useful for finding a law, but they aren't the law. Penalties go through the same check, and each fine carries its own verification date, because fines change more often than the rules behind them.

What a failure looks like

To see it fail, I copied the content to a scratch folder, pointed the counterflow answer's first citation at a news site, and deleted its verification date:

• [content/answers/bawal-ba-mag-counterflow-ang-motor.json] legalBasis.0.sourceUrl:
  Primary source URL must point to an official Philippine government domain (*.gov.ph)
  or approved statutory repository (...). News articles and blogs are not allowed as sources.
• [content/answers/bawal-ba-mag-counterflow-ang-motor.json] lastVerified:
  Published answer must include a lastVerified date (YYYY-MM-DD).
• [content/answers/ano-ang-ibig-sabihin-ng-yellow-box.json] relatedQuestions references
  missing or unpublished answer "bawal-ba-mag-counterflow-ang-motor".
...

Two broken fields produced 14 errors. Once the counterflow answer fails, it's no longer publishable, so every page that links to it fails too: other answers and the road signs that point to it. That's on purpose. A bad answer can't just disappear and leave dead links behind; you see everything it touches.

Drafts can't leak

Research is slow, so an answer can be committed early with needsVerification: true. The schema lets a draft be incomplete, and the loader splits it out:

const publishedAnswers = allAnswers.filter(
  (a): a is PublishedAnswer => !a.needsVerification,
);

Pages, the sitemap, and the search index are all built from publishedAnswers, so a draft never gets a URL, shows up in search, or gets indexed by Google. The type guard helps too: code that renders an answer receives a PublishedAnswer, where the verdict, scope, and verification date are no longer optional.

Where it runs

Validation runs before every build (prebuild in package.json) and as its own step in CI. A tested schema is only half of it: the tests also feed it a complete answer and the broken versions, like an answer with a blog link or a DEPENDE without its condition, and expect each one to fail with the right message.

What the build can't check

The build knows the shape of an answer and where its sources live. It doesn't know whether ₱5,000 is the right fine. That part needs a person reading the law, so the repo also keeps VERIFY.md: one row per fine, with the page of the source where the amount appears and a box to tick by hand.

The split is the point. Code handles everything that can be checked mechanically, every time, so the human review only has to cover what a machine can't.