pattern

Guardrail

A deterministic check applied to a model's input or output, enforcing rules that cannot be left to the model itself.

safetyllmvalidation

The premise is that a model instructed not to do something will usually comply, and "usually" is not a control. Guardrails are the code around the model that enforces what actually matters.

Input side: prompt-injection detection, PII redaction before the request leaves your boundary, topic and scope restriction, and rate limiting per user.

Output side: schema validation (reject anything not matching the expected structure rather than attempting to parse it), grounding checks that the claims are supported by retrieved sources, policy checks for prohibited content, and PII scanning before the response is returned or logged.

Two design points. Guardrails should fail closed for consequential paths — if the validator errors, do not return the unvalidated output. And they belong in the AI gateway rather than in each application, so the policy is uniform and can be updated in one place.