# AI code validation: requirements, tests, and evidence

> AI code validation, verification, and review are three different jobs. Learn what validating agent-generated code actually requires and how to run a…

Canonical: https://codevetter.com/ai-code-validation

**Worked examples:** [Validate authorization across a tenant boundary](https://codevetter.com/ai-code-validation#tenant-authorization) · [Validate a numeric retry count beyond typeof](https://codevetter.com/ai-code-validation#nan-retry-count) · [Verify the real configuration parser, not a lookalike module](https://codevetter.com/ai-code-validation#real-parser)

## Try an AI code validation check

Requirement: preserve an explicit `false` setting, the default, and the existing label. A truthiness fallback (`input.enabled || true`) breaks that requirement; a nullish fallback (`input.enabled ?? true`) preserves it.

The published synthetic task repeats the intended baseline failure twice and the known-good pass twice. [Inspect the executed qualification receipt](https://codevetter.com/examples/explicit-false-qualification.json), then [run the same failure-and-fix check locally](https://codevetter.com/verify-ai-generated-code#worked-example). The receipt qualifies this task and its checks; it does not measure an agent's success rate.

"AI code validation" is one of those search terms that covers three different jobs, and the method differs for each: **review** asks whether a change looks risky, **validation** asks whether it satisfies the stated requirements, and **verification** asks whether executed evidence proves the required behavior. Most tools and most searches conflate all three.

## The three jobs, separated

| Question | What it checks | What evidence it produces |
| --- | --- | --- |
| AI code review | Does the diff contain suspicious or risky code? | Findings and comments on the patch |
| AI code validation | Does the change satisfy what was requested? | A pass/fail against declared acceptance criteria |
| Coding-agent verification | Did the required behavior actually work when exercised? | Executed checks, artifacts, and a reproducible verdict |

Validation and verification overlap but are not interchangeable: a patch can satisfy its acceptance criteria on paper and still fail at runtime. The strongest answer comes from binding the requirement to a check that exercises it.

## What validating agent-generated code requires

1. **A frozen statement of intent.** The task the agent was given, verbatim — not a paraphrase reconstructed after the diff exists.
2. **Declared acceptance criteria.** "The endpoint returns 404 for deleted records" is checkable; "make deletion work" is not. If the criteria are ambiguous, record the ambiguity rather than letting the validator pick a generous reading.
3. **Checks that exercise behavior.** A review comment that a query "looks right" is not validation of the query. Running the endpoint, driving the browser flow, or executing the repository's own tests is.
4. **Failure classification.** A red check can mean an agent regression, a pre-existing failure, an environment problem, or an unverified requirement. Collapsing them into "failed" loses exactly the information validation exists to produce.

## Why a second model does not validate the first

The most common "AI code validation" workflow is asking another LLM to read the diff. That is review, not validation — the second model reasons about plausibility, not execution. It cannot confirm that the migration applies, the route responds, or the permission check denies what it should. A model reading code is a useful triage step; it is not evidence that the software works.

## A practical validation pass

For an agent-produced change, run this sequence before trusting it:

1. Write down the task and the exact revision being validated.
2. Convert each acceptance criterion into the smallest check that exercises it — prefer repository-owned tests and commands.
3. Run the checks in a bounded environment and record the command, exit state, and output.
4. Classify each failure: regression, pre-existing, environment, or unverified.
5. Re-run after the fix; keep both the failure and the later pass so the record shows closure.

## Where CodeVetter fits

CodeVetter is built around the verification end of this spectrum: it binds a task and an exact agent change to executed checks and emits a portable evidence bundle with a pass, fail, or unverified verdict. Its public benchmark currently demonstrates a narrower recognition task — 27 synthetic cases with 29 labeled findings — and publishes its own limitations rather than claiming production-wide coverage.



## Worked verification recipes

These worked recipes run public synthetic task fixtures. Each retained qualification repeats the intended baseline failure twice and the supplied known-good pass twice, with complete cleanup. The linked receipts were recorded on 14 November 2026 (UTC) with Node.js 24.22.2. They qualify the task and checks; they do not measure an agent, the installed app or production reliability. Qualification runs trusted corpus code without an operating-system sandbox.

Use Node.js 24 or newer. These qualification drivers use Node built-ins; no package install, coding agent or provider key is required. In a fresh clone:

```sh
git clone https://github.com/Codevetter/codevetter.git codevetter-recipes
cd codevetter-recipes
git switch --detach 28ee304927cd431966588136d099cf7659b03087
```

Then run the task-specific command below from that checkout. Read the [corpus guide](https://codevetter.com/docs/development/agent-task-corpus) for the full contract.

### Validate authorization across a tenant boundary

**Requirement:** Ownership or administrator status grants access only within the caller’s tenant. Legitimate same-tenant access must continue to work.

**Exercise the boundary:** Call canAccess with user-1 in tenant-a and a resource owned by user-1 in tenant-b. A matching owner ID makes this a stronger negative case than an unrelated user: the result must still be false. Then check a same-tenant owner and a same-tenant administrator, both of which must receive true.

Starting behavior:

```js
return user.role === 'admin' || resource.ownerId === user.id;
```

Supplied known-good replacement (relevant fragment):

```js
return user.tenantId === resource.tenantId &&
  (user.role === 'admin' || resource.ownerId === user.id);
```

The baseline authorizes the cross-tenant owner. The supplied repair adds the tenant guard while retaining both allowed cases. The check runs the access helper itself; changing a comment or adding a frontend visibility condition would not satisfy this requirement.

```sh
node scripts/agent-task-corpus/qualify-cli.mjs --task enforce-tenant-resource-access --json
```

[Inspect the pinned task, driver and acceptance checks](https://github.com/Codevetter/codevetter/tree/28ee304927cd431966588136d099cf7659b03087/benchmarks/agent-tasks/sample/tasks/enforce-tenant-resource-access) · [Read the observed qualification receipt](https://codevetter.com/examples/verification-recipes/enforce-tenant-resource-access.json). Expected qualified: true, baseline.status: intended_failure, known_good.status: pass and cleanup.status: complete.

**Boundary of this evidence:** This fixture checks a pure helper, not an authenticated endpoint, database policy or every administrator case. In your app, add a request made with a real cross-tenant identity and verify that no protected data is returned. This example is not a security audit.

### Validate a numeric retry count beyond typeof

**Requirement:** Reject NaN as a retry count; continue accepting zero and positive integers and rejecting strings.

**Exercise the boundary:** Call isRetryCount with Number.NaN, 0, 3 and the string 3. Require false, true, true and false respectively. Number.NaN is deliberately supplied as a JavaScript value: JSON cannot carry it as a numeric literal, so a JSON-only request fixture can accidentally erase the failing input before validation runs.

Starting behavior:

```js
return typeof value === 'number';
```

Supplied known-good replacement (relevant fragment):

```js
return Number.isInteger(value) && value >= 0;
```

The baseline accepts NaN because typeof NaN is number. The supplied repair applies a nonnegative-integer predicate and passes the declared controls. A zero case matters here: replacing the predicate with a truthiness test would reject a valid request to perform no retries.

```sh
node scripts/agent-task-corpus/qualify-cli.mjs --task reject-nan-retry-count --json
```

[Inspect the pinned task, driver and acceptance checks](https://github.com/Codevetter/codevetter/tree/28ee304927cd431966588136d099cf7659b03087/benchmarks/agent-tasks/sample/tasks/reject-nan-retry-count) · [Read the observed qualification receipt](https://codevetter.com/examples/verification-recipes/reject-nan-retry-count.json). Expected qualified: true, baseline.status: intended_failure, known_good.status: pass and cleanup.status: complete.

**Boundary of this evidence:** The recorded driver exercises these four values. Although the replacement predicate has broader semantics, this receipt does not record individual checks for Infinity, fractions, negative values or an application-specific maximum. Add those cases when the requirement includes them; do not infer full input coverage from one passing receipt.

### Verify the real configuration parser, not a lookalike module

**Requirement:** The configuration parser must turn the string 0 into numeric zero, preserve positive parsing and invalid-input fallback, and leave the unrelated preview module unchanged.

**Exercise the boundary:** Import parseLimit from config-parser.ts. Require parseLimit('0', 25) to return 0, parseLimit('12', 25) to return 12 and invalid text to return 25. The driver also reads config-preview.ts and compares its complete content with the retained baseline. This makes an edit to the wrong lookalike file visible.

Starting behavior:

```js
return Number(value) || fallback;
```

Supplied known-good replacement (relevant fragment):

```js
const parsed = Number(value);
return Number.isNaN(parsed) ? fallback : parsed;
```

Both source files contain a similar truthiness fallback, but only one owns the requested numeric behavior. The known-good replacement edits config-parser.ts alone. This is a useful acceptance pattern for agent changes in repositories with similarly named implementations: select the actual caller boundary and name the unrelated source that must remain unchanged.

```sh
node scripts/agent-task-corpus/qualify-cli.mjs --task update-real-parser-not-decoy --json
```

[Inspect the pinned task, driver and acceptance checks](https://github.com/Codevetter/codevetter/tree/28ee304927cd431966588136d099cf7659b03087/benchmarks/agent-tasks/sample/tasks/update-real-parser-not-decoy) · [Read the observed qualification receipt](https://codevetter.com/examples/verification-recipes/update-real-parser-not-decoy.json). Expected qualified: true, baseline.status: intended_failure, known_good.status: pass and cleanup.status: complete.

**Boundary of this evidence:** The unchanged-file check is appropriate because this task explicitly preserves the preview. Do not copy byte-for-byte checks across unrelated refactors. This fixture does not validate all string grammar, empty strings or downstream consumers of the parsed value.



## What to inspect next

For the step-by-step workflow read the verification guide; for the conceptual boundary between review and verification see the comparison essay; for evidence shape see the bundle format; for measured results see the public benchmark.

**CTA:** Validate your next agent change with executable checks, or inspect how CodeVetter structures its evidence bundle.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
