When to reach for it
- Outputs are free-form, so schema validation does not apply.
- A numeric reject/allow boundary is needed.
- Topical drift or low-confidence fabrication must be caught before a response reaches a user.
/pattern/statistical-guardrails/
Quantitative, model-agnostic checks sit between a non-deterministic agent and the user and reject outputs on statistical signals rather than schema or rules: semantic-drift detection (cosine-distance z-score from a safe baseline) and confidence gating (Shannon entropy of token probabilities).
In practiceA medical-information agent runs every generated answer through a cosine-distance drift detector; responses that stray semantically from the safe-answer baseline are flagged and routed to a human reviewer before delivery.
Without itWithout statistical guardrails, an answer that is schema-valid but semantically drifted reaches the user unflagged, because structural validators see nothing wrong and the drift only shows up once a complaint surfaces it.
When to reach for it
When it backfires
The tradeoff
A cheap, model-agnostic safety net is gained against threshold-tuning effort and false positives — a novel-but-correct answer can read as drift, and a confidently-wrong answer can pass the entropy gate.
Outputs outside statistical bounds are flagged.
The z-score baseline was built from last quarter's safe answers. The product's scope expanded, legitimate new topics now read as drift, and the guardrail rejects correct outputs.
Fix · Refresh the baseline corpus as scope changes, and alert on rejection-rate spikes so a drifting threshold is caught before it blocks real traffic.
Low token entropy reads as high confidence, but a fluent hallucination is exactly that — confident and wrong. The statistical gate passes it because confidence is not correctness.
Fix · Never treat low entropy as a truth signal. Pair confidence gating with a grounding or verification check (retrieval, a fact-check tool, or LLM-as-judge) before trusting the output.
Keep going
Search patterns, frameworks, and pages.