Teriyaki

Your AI grades its own homework. Here's how we stopped it

Teriyaki6 min read

Validating AI-generated code has a common flaw: it is often done by the same AI that wrote it. Picture a student who writes the exam, takes it, and then grades it. Top marks, every time. In this article we look at why it happens, how we prevent it in Teriyaki, and the mistake we made along the way.

The pattern goes like this. The same model reads the request, writes the code, writes the tests, runs them and reports back: all green. It is not lying; it is doing exactly what it was asked. The trouble is that code and tests come from the same understanding of the requirement. If that understanding is wrong, they are wrong together, and they agree with each other perfectly.

A green test suite written by whoever built the software tells you only one thing: the code does what its author thought it should do. It does not tell you it does what you need.

Three ways AI-written tests fail

The shared blind spot. Say the AI reads "invoices older than 90 days" as "older than 3 months". Code and tests both use months. Everything passes. In February it breaks.

Teaching to the test. When an agent can see the tests and is asked to make them pass, the shortest path is sometimes to make those tests pass instead of solving the problem. A special case here, a hard-coded value there.

Moving the goalposts. An agent that can edit the tests can also weaken them. A lowered threshold, a check removed, a failing case deleted "because it was flaky".

None of these needs a model acting in bad faith. It is what happens when the judge and the contestant are the same person. A practical guide to acceptance testing is in How to test an app written by AI.

Separate the builder from the judge

In Teriyaki, the AI software factory we build at Hoplo, the rule is simple: the builder never decides the verdict. In practice it works like this.

  1. A person confirms the cases before any code exists. From the specifications, the factory proposes test cases in readable form: inputs, expected results, why each one matters. The Builder, the person at the company who describes the process, confirms them. They are the definition of "correct", agreed before the builder starts: the software must be correct on the confirmed requirements, and if the process changes, it gets improved.
  2. The cases are split into two groups. Some go to the builder, so it knows what a good result looks like. Others are hidden acceptance cases: the builder never sees them.
  3. A separate validator runs everything. Once the build is done, a validator the builder does not control runs all the confirmed cases, visible and hidden, against the generated software. The result shows how many passed, hidden ones included.
  4. Tampering is a failure, not a shortcut. If the builder edits or removes a protected test, the release is blocked. If a hidden case ends up in the delivered software, the release is blocked.
  5. Only people with permission publish. Passing the tests makes a version releasable; it does not publish it. Only someone with permission publishes it, under rules the company sets. Only then do the people who use the apps use it for their work.

How we got here, with dates, is in the fifth episode of the chronicle.

Testing the tester

You cannot trust a validator you have never seen fail. That is why we plant defects on purpose and check that each one gets caught: a failing hidden case, a threshold quietly lowered in the code that only a hidden case reveals, a hidden case slipped into the delivered software. Each one must block the release.

The mistake we made: an unfair exam

Hidden tests have their own way of going wrong, and we fell for it.

A generation that was correct by any reasonable reading got failed. Two hidden scenarios expected a platform warning with specific wording. The specifications never mentioned that warning. The builder had no way to know. We had written an exam with questions that were not on the syllabus.

The fix became a rule: everything a hidden test checks must follow from something written in the specifications. The builder may not see the question, but it must have studied the topic. Today the platform checks this when it proposes the cases: if a hidden scenario looks for something the specifications do not mention, the proposal goes back, with the reason, to be fixed before the build, not after.

Hidden tests exist to catch whoever took shortcuts. They must never punish whoever followed the specifications.

Tests written by the same AI Hidden tests and a separate validator
Who defines "correct" the AI that builds a person at the company, before the code
Who sees the tests the builder, all of them the builder, only some
Who gives the verdict the builder a validator the builder does not control
Tests edited or removed go unnoticed block the release

Five rules to apply tomorrow, with or without us

  1. Write down what "correct" means before generating anything, and have someone at the company confirm it.
  2. Keep some tests away from the AI that writes the code. A few are enough to catch anyone who only studies for the test.
  3. Run validation somewhere the builder cannot touch, and treat any edited or deleted test as a failure.
  4. Every hidden check must trace back to the specifications. If you cannot point to the sentence it comes from, it is not a fair test.
  5. Keep a person at the release gate. Tests say it works. A person says it is ready.

This is one of the stations on the line we described in What an AI software factory is. If you want to see how Teriyaki works, start here.

Frequently asked questions

Why shouldn't the AI that writes the code also write the tests?

Because the tests share the same assumptions as the code. If the requirement was misunderstood, code and tests agree with each other and are both wrong.

What are hidden test cases?

Cases confirmed by a person but never shown to the AI that builds the software. Only a separate validator runs them, so the builder cannot tailor the code to them.

Do hidden tests replace human review?

No. Tests show that the software works on the cases that matter. Whether it is ready for release is still decided by a person.

Let's start with one process.
In 30 minutes we'll know if it fits.

Book a demo