Talk about your project

leobranding.net@gmail.com
We reply within 24 hours

How to Verify AI Generated Content Before It Reaches a Pull Request

To verify AI generated content, put a code gate and reviewer agents between the draft and the pull request, then check the checks. This is how I run it.

A draft written by an AI agent looks finished long before it is correct. The prose is smooth, the code compiles, the tone is steady. That is the problem. Smooth output hides errors from a tired human reader, so the human should not be the first line of defence. The first line should be a set of gates that fail loudly and cheaply.

The system described here runs LEO Branding's own work: a weekly batch that writes blog posts for this site. No client project is involved, and I make no claim about results for anyone else. What I can offer is a concrete design, the trade-offs I accepted, and a few defects that review caught in my own rules.

Start with a code gate that must pass before any pull request opens

Many teams ask a model to check a model. That has a place, and I use it further down. But the first check should be plain code, because code does not get persuaded.

In the content repository, a verify command has to exit cleanly before a pull request opens. The repository's agent instructions require that command to exit cleanly before a pull request opens.

What does the gate check? Two things matter most for written content.

The first is banned wording. The post gate scans the body and the SEO text for phrases the business has decided never to publish. One example is a phrase that implies work for a paying customer. A model told to avoid a phrase will sometimes paraphrase its way around it, which is why the gate holds a list of exact strings and reviewers hold the judgment about paraphrase.

The second is numbers. The gate flags any number written in digits that no measured fact backs. A model produces "reduces review time by a large share" with the same ease as a true sentence. A rule that says "a number needs a fact with a measurement behind it" turns a fuzzy editorial worry into a yes or no.

The gate costs something. It rejects some honest numbers because nobody has recorded the measurement yet. It rejects good sentences that happen to include a banned string. A post goes back for a rewrite, and a rewrite costs time and tokens. I accept that cost, since a late discovery of an invented figure is far more expensive than an early rejection.

Some practical advice if you build a similar gate:

  • Keep it deterministic. No model calls inside it. If the gate can be fooled by rephrasing the prompt, it is a reviewer, not a gate.
  • Make it fast enough to run after every draft, not only before the pull request.
  • Print the failing rule and the offending text. The agent then knows exactly which rule failed and which text to change.
  • Check every text surface, not only the body. Titles, descriptions and tags travel to the public page too.

Make reviewer agents return structured findings, not opinions

A code gate cannot judge whether a claim is fair, whether an argument holds, or whether a page promises something the business cannot deliver. That is where a review agent earns its place.

The failure mode of review agents is the paragraph of opinion. "This reads well, though perhaps the tone could be warmer." Nothing can act on that. A pipeline cannot count it, route it, or block on it.

So each reviewer in my pipeline returns exactly one JSON object, and that object must match a findings schema. The batch skill then assembles those objects into a review file for each post. Four reviewers look at each post, each with a narrow job, and a human reads the assembled result rather than four free-form essays.

Structure gives you two things.

A finding can be machine-checked. When every reviewer must return one object that matches the findings schema, a program can check the shape of each finding instead of a person skimming prose.

A finding can block. A schema can carry a severity and a verdict, which makes blocking on a serious finding possible without anyone reading prose to decide.

The cost is rigidity. A schema cannot hold a subtle point that does not fit its fields. I accept that, because subtle points are what the human reader is for. The structured layer is meant to remove the routine problems so the human sees the remaining ones.

Guard the checker itself: hashed inputs, redaction and no shell

A gate is only as honest as its inputs. If the agent that writes the post can also edit the gate, the banned list, or the facts it is checked against, then the check proves nothing. The agent does not need bad intent. It only needs a task that is easier to finish by loosening a rule.

I treat the checker as something to protect, in three ways.

Hash the gate's inputs

A guard command hashes the gate's own inputs: the facts, the strategy files, the tools, the agent roles and the build configuration. It runs before the gate and again before the pull request. If anything drifted in between, the batch stops.

This is meant for the quiet case. Suppose a writer agent "fixed" a failing check by editing the check: that would change the hash, and the batch would stop. The cost is friction, because any change to the gate's inputs in the middle of a batch stops it, including a change I make on purpose. That friction is the point.

Redact before anything is published

A redaction filter scans every fact and every published tag for network addresses, host names and key patterns. A hit stops the batch. Facts are the raw material for the posts, so a leak in a fact becomes a leak on a public page. Scanning at the source, and again on the tags that ship, closes both doors.

Pattern-based redaction has limits. It finds what it has patterns for. A secret in an unusual shape slips through, and a harmless string that resembles a key gets flagged. I would rather chase an occasional false alarm than publish a real one.

Give the agents no shell

No agent in the content pipeline has a shell. The orchestrator can run git and GitHub commands, but its settings carry deny rules that block the dangerous ones.

This is the least glamorous measure and probably the strongest. A review agent that reads untrusted text, such as a draft, a fact, or the contents of a page, can be steered by that text. If the agent also has a shell, steering becomes command execution. Without a shell, the worst a manipulated agent can do is return a bad finding or write a bad file, and both of those land in front of the gate and a human.

The trade-off is capability. Agents cannot run a test, install a tool, or poke at a problem themselves. Everything they need has to be handed to them as files or provided by the code around them. That makes the pipeline more work to build, and it makes each agent's blast radius small and easy to describe.

Let review audit your rules: contradictions and re-read gaps it found

The last step is the one teams skip. Once you have gates and reviewers, you also need evidence that the rules themselves are sound. The most useful evidence I have found is the review process itself, because it exposes defects in the rules, not only in the content.

A contradiction between roles

In one batch, both posts were held. The funnel reviewer asked for a link to the contact page, since a post that ends without a next step has a hole. But the writer role and the link-reviewer role both forbade that link. Each agent followed its instructions correctly, and the result was a deadlock.

No amount of better writing would have fixed it. The defect was in the rules. The fix allowed exactly one contact link across the roles, and every role now agrees on it. The lesson is general: when several agents hold separate rule sets, those sets can contradict, and the first symptom can be a held post rather than an error message. If the same post is held for a reason that no draft can satisfy, look at the rules.

A gap where a snapshot stood in for a read

The second finding came from my publishing flow, in the change that handles scheduled posts. Review found that an error status was being patched from a list snapshot, without re-reading the page first. A snapshot can be stale. Deciding on stale data is how a status ends up wrong. The fix moved that decision to the detail read, where the page is read fresh.

A useful question for any value that drives a state change is where it comes from and how old it is. That question is worth giving to any reviewer who looks at code that changes state.

Test that two copies of a rule really agree

One more check belongs in the set. When the same rule exists in two places, such as a validator in a client and another in a server, they drift. A notion-test gate test addresses this directly. It compares the regex source of the client and server publish-at validators, and it runs both over one shared set of boundary cases.

That does two jobs. The source comparison catches a change made to one side only. The shared cases catch the harder situation where the sources differ in form but the behavior has diverged. The cost is a test that must be updated whenever the rule changes on purpose, and I treat that as a useful reminder, not a nuisance.

A routine for checking your own checks

Here is the short version you can apply this week.

  1. Put a deterministic gate in front of every pull request, covering banned wording and unmeasured numbers.
  2. Require each reviewer to return one object that fits a schema.
  3. Hash the gate's inputs, and stop on drift.
  4. Scan facts and published metadata for secrets and hosts.
  5. Remove shells from agents, and deny dangerous commands in the orchestrator.
  6. When a post is held for a reason no draft can fix, read the rules, not the post.
  7. Where a rule is duplicated, add a test that compares the copies.

None of this makes AI output correct. The aim is to make errors visible earlier. A human still reads the pull request and decides. The aim is that the human reads a pull request with the routine problems already filtered out, and that the rules doing the filtering have been checked too.

If you want an outside review of your agent setup, see the AI agent audit.

If you ship AI-written content or code and want to talk through which of these gates fit your setup, you can get in touch.