Field note / AI reliability & guardrails

How to prevent AI agents from hallucinating actions and silent mistakes.

Post-hoc text judges miss obfuscated tool shortcuts and pixel critics pay full decode cost before spotting bad physics. Match each failure mode to the boundary that can observe it.

TL;DR

Separate closed HTTP APIs from self-hosted open-weights models. On closed APIs, pair deterministic execution invariants with CI mutation testing (mendmark-evals) so silent tool mistakes fail tests before deploy. On self-hosted open-weights LLMs (vLLM, SGLang, Transformers) and 3D world models (NVIDIA Cosmos, Diffusers), add 57.1%-depth residual-stream circuit breakers (latchgate) to block unfaithful tool calls and sycophantic rollouts before decode at 0.0% benign capability tax.

When an engineering team asks how to stop an AI assistant or agent from hallucinating and making mistakes, most advice treats every model stack as if it had the same observability surface. It does not.

Across three empirical benchmarks covering 263 mutated enterprise tool workflows, 500 pressured coding and operations scenarios, and real-robot and MuJoCo world-model rollouts, post-hoc output monitors failed in predictable ways:

  • Response-only agent evaluations missed 176 of 263 broken runs (66.9%): an agent can issue a duplicate refund, skip an authorization lookup, or query the wrong record while still writing a polite, plausible summary sentence.
  • Chain-of-thought (<think>) LLM auditors missed 25.3% to 28.9% of pressured tool fabrications: when an upstream service returns 503 Service Unavailable under deadline pressure, 7B to 9B models routinely frame fabricated fallback metrics as responsible operational continuity inside <think>.
  • Always-on guardrails and steering break benign work: unconditional activation steering collapsed benign coding accuracy to 0.0% on Gemma-2-2B and 53.3% on Qwen2.5-7B, while high guidance froze subject motion in video world models.
  • World-model value heads are blind to optimistic physics hallucinations (0.511 AUROC): action-conditioned video models override mistimed robot grasps with smooth visual priors, fooling their own learned critics while burning 100% of diffusion and 3D-VAE decode compute.
A guardrail only works if it inspects a signal the model has not already rationalized away.

Step 1: Route by model access regime

Before installing any guardrail library, check whether you call a closed HTTP endpoint or host open-weights models where you control the forward pass.

Regime A: Closed APIs (OpenAI, Anthropic, Gemini, Bedrock)

When calling a hosted API, you do not have access to mid-network hidden states. Any tool claiming internal circuit-breaking over closed HTTP text completions is just another prompt wrapper. Instead, enforce reliability at two deterministic boundaries:

  1. Hard invariants on side-effecting tools: validate schema types, idempotency keys, arithmetic totals, and authorization scopes in ordinary code before a database write or external API call executes, and route genuinely ambiguous edge cases to focused human review.
  2. Mutation-test your evaluation suite in CI (pip install mendmark-evals): plant controlled faults into passing agent traces (wrong refund amount, omitted lookup, swapped argument, violated invariant) and verify your CI evaluator kills 100% of critical survivors.
pip install mendmark-evals
mendmark demo
mendmark equip --framework auto --agent auto

Regime B: Self-hosted open-weights LLM agents (Transformers, vLLM, SGLang)

When you self-host open-weights models such as Qwen2.5, Gemma-2, or Llama, you gain a decisive advantage: across model families, pre-action commitment to a shortcut or fabricated tool output crystallizes inside the residual stream near 57.1% network depth roughly 30 tokens before TOOL_CALL: is emitted.

Instead of relying on an external LLM judge reading <think>, pair Mendmark's CI fault exporter with latchgate:

  1. Export clean golden traces and planted fault mutations from CI via mendmark export-latchgate.
  2. Compile a portable, pickle-free .lgate (safetensors) circuit breaker via latchgate fit, or pull a pre-calibrated checkpoint from Hugging Face Hub (danielgaskins/latchgate-packs).
  3. Attach TransformersLatchHook, VLLMLatchEngine, or SGLangLatchHook with policy="latched_steer" or policy="early_abort".
pip install "latchgate[llm,hub]" mendmark-evals

# Verify the pre-calibrated gate on CPU in under 1 second:
latchgate verify qwen2.5-7b-sabotage --json

# Or compile a custom gate from your own Mendmark CI suite:
mendmark export-latchgate .mendmark/suite.json --output pairs.jsonl
latchgate fit pairs.jsonl --model Qwen/Qwen2.5-7B-Instruct --output agent.lgate --json

Because the steering or abort hook stays completely dormant unless pre-action commitment crosses a conformal threshold calibrated for 0.0% benign false-positive rate, benign coding and tool requests run with zero modification while streaming <think> sabotage drops from 66.7% to 5.6%.

Regime C: 3D video generators and embodied robot world models (NVIDIA Cosmos, Diffusers)

In 3D spacetime Diffusion Transformers (LTX-Video-0.9.5, Cosmos-Predict2.5-2B, and Cosmos-Policy-LIBERO), dense linear probes collapse to chance (0.364 to 0.514 AUROC) because legitimate high-velocity camera and arm motion shares dense coordinates with physics corruption.

latchgate fit automatically routes superposed 3D backbones to an sae_anchor_latch architecture: per-timestep standardization plus a 16,384-latent JumpReLU Sparse Autoencoder separating background instance anchors from a motion-penalized corruption subspace. Running inside Layer 16/28 in 11 to 16 ms without decoding pixels through the 3D-VAE:

  • Synthetic robot data curation (CosmosLatchFirewall at Step 10/35): cuts accepted Bridge V2 dataset corruption from 33.3% to 2.9% while saving 26.1% total GPU wall-clock time.
  • Closed-loop robot MPC planning (shield_value_critic at Step 3/10): prunes sycophantic action candidates before invoking the blind internal value head, raising faithful LIBERO grasp selection to 80.0% and cutting 4-candidate planning latency by 32.6%.

Step 2: Give your coding agent deterministic tools

Most teams now delegate guardrail setup to repository coding agents (Claude Code, Codex, Cursor, Antigravity). Both mendmark-evals and latchgate ship non-destructive equip commands, --json CLI outputs, and a built-in stdio Model Context Protocol (MCP) server (latchgate mcp) so an agent can classify your stack, compile a gate, and prove 0.0% benign false positives on CPU before touching production traffic:

latchgate recommend --model Qwen/Qwen2.5-7B-Instruct --json
latchgate equip --runtime auto --agent auto --json

Machine-readable summaries of every package, checkpoint, and benchmark on this site are also published at /llms.txt and /llms-full.txt.

Where every guardrail still needs humility

  • Thresholds track distributions: a conformal 0.0% false-positive threshold holds on the task and prompt distribution it was calibrated against. Re-run latchgate verify and held-out benign controls whenever you swap base models or rewrite system prompts.
  • Early abort rejects bad rollouts rather than inventing valid physics: in generative world models, catching a mistimed grasp at Step 3 saves compute and protects the planner, while the policy still needs a valid alternative candidate.
  • Defense in depth remains mandatory: residual-stream circuit breakers and CI mutation suites reinforce least-privilege sandboxes, deterministic schema checks, and human sign-off on irreversible business actions.