Guardrails and human review Recommended
Check input before it reaches the model
Run cheap checks on every input before the model call. Limit length, reject empty or off-topic requests and mask personal data the task does not need.
How to do it
Set a maximum input length per feature, such as 4,000 characters, and reject longer input with a clear message. Run fast checks first, such as length, language and rate limit, then slower ones, such as a topic or moderation classifier. Mask card numbers, national ID numbers and similar patterns, as send models only the private data they need requires. A rejected input costs nothing and never reaches the provider.
Example
const MAX_INPUT_CHARS = 4000;
const CARD_NUMBER = /\b(?:\d[ -]?){13,19}\b/g;
export function checkInput(text: string): { ok: true; text: string } | { ok: false; reason: string } {
const trimmed = text.trim();
if (!trimmed) return { ok: false, reason: 'empty' };
if (trimmed.length > MAX_INPUT_CHARS) return { ok: false, reason: 'too_long' };
return { ok: true, text: trimmed.replace(CARD_NUMBER, '[card number removed]') };
}
MAX_INPUT_CHARS = 4000
CARD_NUMBER = re.compile(r"\b(?:\d[ -]?){13,19}\b")
def check_input(text: str) -> tuple[bool, str]:
trimmed = text.strip()
if not trimmed:
return False, "empty"
if len(trimmed) > MAX_INPUT_CHARS:
return False, "too_long"
return True, CARD_NUMBER.sub("[card number removed]", trimmed)
How to check
Unit tests send an input over the limit, an empty input and one with a test card number. The first two get a clear error with no model call. The third reaches the fake provider with the number masked.
For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers ai features playbook: https://agentwranglers.se/playbook/ai-features/guardrails-and-human-review/input-checks.