How to Test AI Guardrails Before Production

Run candidate validator rules against fixtures or redacted quarantine samples in the dashboard Simulate drawer, with no upstream model call. Gate CI with the CLI.

November 21, 2026

Related templates: Pre-Deploy Validator Gate

Consider an illustrative scenario. On Friday, an engineer tightens required_fields on a refunds agent and saves. The demo payloads pass, so the change looks harmless. Nobody replays last week's failure shapes against the new rule.

On Monday, a share of production responses starts blocking. One upstream model omits a field that older traffic never needed, and the stricter rule now rejects it. Nothing about the model changed. The policy did, and production traffic became its first test run.

That is the gap AI guardrail testing should close. A validator change is a configuration change and deserves pre-merge evidence. Below: how ValGuard's policy simulator diffs a candidate rule pack against the saved one, and where simulation, CI fixtures, and shadow mode each stop proving anything.

Why validator changes break in production

Validators are deterministic. The same output and the same rules produce the same verdict, which is exactly why they can be tested before deploy. The trouble is that most teams test the rule in isolation instead of testing it against real output shapes.

Three failure modes show up again and again.

  • Hand-written examples are too clean. They contain the fields the author expected, so a stricter rule passes them.
  • The saved baseline is assumed. A teammate may have saved a different version overnight.
  • The change is judged by one verdict. A request can stay blocked while a different rule now fires, hiding a real behavior change.

None of these needs an LLM to catch. They need recorded outputs replayed through two versions of the policy, compared rule by rule.

How the policy simulator works

On an agent's validators editor, Simulate sits next to Save. It opens a drawer that replays fixtures through the saved policy and through the unsaved rules in the editor. Both outcomes appear side by side. No upstream model is called, and the saved policy is not changed.

The drawer offers three fixture sources. A template-aware sample for the agent is always available. Pasted output covers one-off cases from logs or a bug report.

Quarantine snapshots appear only after the organization enables quarantine payloads in Settings. Payloads are redacted before they are stored, so replay uses the failure shape rather than the original text. The drawer lists up to 20 recent snapshots for the agent, labeled by error tag.

Behind the drawer, the dashboard forwards the request to the proxy's internal simulate-policy route. That route runs the same validation engine that handles live traffic.

StepWhat the engine does
Load baselineReads the agent's saved validators from the database
Build candidateTurns the editor rows into rule instances; an empty on_fail becomes block
Run both policiesRuns every enabled rule on each fixture, without fail-fast, under the org's plan
Record verdictsReports pass, block, or reask per policy, plus would_enforce and failing rules
CompareMarks a fixture changed when the verdict differs or the failing rules, on_fail values, or messages differ
SummarizeReturns total fixtures, changed fixtures, and how many each policy would enforce on

Two details matter when you read results. Because all rules run without fail-fast, the diff lists every rule that changed, while verdicts still match live traffic. Shadow mode is not applied inside the simulation: for a shadow agent, the drawer says so and shows what enforce would do.

Each failure line carries the rule id and the validator's message, redacted according to the agent's log level. Every simulated decision stays explainable: which rule fired, what verdict it produced, and why.

The proxy caps one simulation at 20 fixtures, 32 KiB per fixture output, 8 KiB per input text, and 64 candidate validators. A run does not count against the monthly validation allowance, because it is a preview rather than production traffic.

Each dashboard run writes an agent.policy_simulated audit event with counts only: fixtures, candidate rules, changed fixtures, both would-enforce totals, and the shadow flag. Fixture text is not written to the audit log.

If you edit rules after a run, the editor notes that rules changed since the last simulation. Save stays available, so the notice is a prompt to re-run rather than a lock.

The desired model: simulate, fixture, shadow, enforce

No single test answers every question. A sound pre-production routine stacks layers, and each layer has a clear limit.

StageQuestion it answersWhat it cannot prove
SimulateDoes the candidate change verdicts on the fixtures I chose?Behavior on shapes you did not pick
CI fixturesDo known-good and known-bad outputs still pass and fail on every change?Live traffic mix or volume
Shadow modeHow often would enforce block real traffic?Whether that rate is acceptable to the business
EnforceIs the team ready to own the block rate?Correctness of checks nobody configured

Shadow mode is the production soak. When an agent is in shadow and a response would have been enforced, the proxy returns the response unblocked. It sets X-VG-Validation-Status: shadow and X-VG-Shadow-Mode: true and records shadow_would_block on the request row.

Requests and responses stay OpenAI-compatible; the shadow signal travels in headers and logs. Individual rules can be disabled, and the agent runs in shadow or enforce, so a new rule never has to go straight to blocking. Deterministic validation and repair come first, and reask stays the last resort.

Practical guidance: a pre-deploy routine

The routine below reuses the same pieces for every agent, so it scales from one policy to hundreds.

  1. Collect fixtures from real failures. Enable quarantine payloads, let a week of failures accumulate, and select recent snapshots in the drawer. Paste in the output from any incident you are investigating.
  2. Simulate the candidate. Edit rules, run Simulate, and read every changed fixture. Expect changes where you intended them and none elsewhere.
  3. Check the baseline. If a diff surprises you, open Policy history on the same editor. It lists the last 20 saved snapshots with added, removed, and changed rules.
  4. Save, then soak. Save the agent and keep it in shadow for a defined window. Watch would-block counts before you flip to enforce.
  5. Lock the cases into CI. Move the fixtures that mattered into your repository so every future change replays them.

For CI, the open-source valguard CLI runs offline, with no ValGuard account and no network calls. valguard check validates one output against a valguard.yaml policy. valguard test runs every JSON fixture in a directory, and each fixture embeds its own policy and expected result.

{
  "name": "refund missing amount blocks",
  "policy": {
    "version": 1,
    "name": "refunds",
    "mode": "enforce",
    "rules": [
      { "id": "valid_format", "params": { "format": "json" }, "on_fail": "block" },
      { "id": "required_fields", "params": { "fields": ["refund_id", "amount"] }, "on_fail": "block" }
    ]
  },
  "output": "{\"refund_id\": \"R-104\"}",
  "expect_blocked": true,
  "expect_failed_rules": ["required_fields"]
}

The example workflow in the repository, docs/examples/valguard-pre-deploy-gate.yml, runs on pull requests that touch the policy or fixtures. It installs the CLI pinned to v0.1.0 and runs valguard test --dir fixtures. The job fails when any fixture misses its expectation, and that failing check is what actually holds the deploy.

Keep one caveat in mind. The CLI evaluates the YAML policy in your repository with the open-source rule set, which is a subset of the hosted catalog. It does not load your hosted agent's saved rules.

To test a hosted agent's configured rules, the test validators in CI tutorial calls POST /internal/test-validators with an agent_slug. On production and staging builds, internal test routes (simulate-policy included) accept only the internal proxy secret. That path fits staging or self-hosted deployments where you control the secret.

Three published playbooks document the human side of the routine. Each one is a small triage graph: an extract step summarizes the situation, and a handoff step routes it to an owner. None of them runs the simulator or blocks a deploy by itself.

  • pre-deploy-validator-gate summarizes a simulator or CI diff. A summary that passes its JSON rules ends at "Gate passed"; anything else goes to a release manager and ends at "Deploy held."
  • shadow-week-new-policy summarizes a shadow week, then ends at "Ready for enforce" or, after owner sign-off, "Extend shadow."
  • fixture-library-from-quarantine catalogs quarantine failure tags and hands off to a validator owner.

Schema drift alerts link to the agent's validators editor, so you can simulate a fix before saving it (how to detect LLM schema drift). The shadow mode rollout tutorial covers the soak step, and validator false positive monitoring covers the weeks after enforce.

What this is not

  • Not proof of production behavior. A clean simulation covers the fixtures you chose. Shadow mode and validation coverage cover live traffic.
  • Not a load test or agent emulator. ValGuard's internal AI agent emulator is a QA harness and is separate from the customer-facing simulator.
  • Not model evaluation. Evals score model quality on sampled inputs, while the simulator scores rule behavior on recorded outputs. See evals vs validation in production.
  • Not a repair step. Malformed output may need automatic repair before validation; the simulator only reports verdicts.
  • Not a compliance certificate. Guardrails enforce configured checks. For evidence that rules ran on a given request, see how to prove AI guardrails actually executed.

Start with one rule change

Pick the next validator change on your list. Before saving it, simulate it against the sample and a few redacted quarantine snapshots. If the diff matches your intent, save, soak in shadow for a week, and move the fixtures that mattered into CI.

The goal is modest and concrete. Production traffic should confirm a policy you already tested, not discover the one you did not.

Product detail: policy simulator · What's new · Tutorial: test policy before production.

Book a technical walkthrough with our team → Start free in shadow mode — no credit card →

Related articles

Shadow Mode Is Not Coverage

Shadow mode shows what would block before enforce. It does not prove every configured validator ran on every request. Use coverage attribution for chain completeness.

How to Measure AI Guardrail Coverage

Measure which production traffic actually ran your full validator chain — not just which rules exist on the agent. Full-chain %, gap lists, CSV export, and shadow vs coverage.

We Built ValGuard Because "It Usually Works" Isn't Good Enough

"It works most of the time" is how quiet production AI failures start. A 99.7% success rate is still ~30 failures a day at 10k requests — most shipped as HTTP 200. Here is the case for a deterministic validation layer: shadow mode first, enforce when the data backs it.