Guardrails
Filtrado de entrada/salida
Escrito por Darjus Kazakevic · revisado el
Assume the worst plausible output, and make it safe.
Guardrails assume the model will sometimes produce the worst output its input allows. “Almost always right”, multiplied by production traffic, still means many wrong answers. Guardrails are checks in plain code that make those wrong answers safe.
The key difference is between an instruction and a limit. “Only use SELECT” in a prompt is an instruction, and prompt injection (text written to override your instructions) exists to defeat it. A tool that can run only three named reports is a limit; no input can widen it. Treat every text the model reads as possible instructions: documents, tool results, web pages, memories.
En esencia — A limit written in the prompt is only a request. Only the code around the model can actually stop anything.
Cuándo recurrir a él
Recurre a él cuando
- The agent's actions have real effects: money, messages, data
- Text in the context comes from users, the web or other tenants
- The output is shown to people or drives another system
Reconsidéralo cuando
- A local, read-only, single-user tool over trusted input
- The platform already enforces the same control
- A type or a permission would settle it without a classifier
The layers
- Input checks
- Checks on what enters the context: size limits, rate limits, format checks, and screening of untrusted text. Weak on their own, because hostile text is hard to detect, but they stop easy attempts and cap the cost of the rest.
- Capability limits (Least privilege)
- What the model's tools are able to do at all. This is the only layer that holds under attack, because it does not depend on the model's choices. A tool without delete permission cannot delete.
- Output checks
- Checks on what comes back before it reaches a user or another system: schema, meaning, personal data and secrets. Also escaping: model output that becomes HTML, SQL or a shell command is untrusted input there.
- The tripwire (Kill switch)
- Limits that stop a whole run or feature: spend in one session, error rate, repeated guard trips, a manual switch. It turns a bad afternoon into a bounded incident.
Reglas de diseño
- Enforce limits in code, never in the prompt
- Put each limit where the model cannot reach it: a tool that lacks the power, a check in the dispatcher, a ceiling in a type. Prompt instructions guide the normal case. They are not a control.
- Give each tool the least access that works
- Use a separate credential per tool, read-only where possible, allow-lists over deny-lists, and hard caps on amounts and paths. Many agent incidents start with a permission that was convenient in development.
- Treat everything the model reads as untrusted
- Hostile instructions rarely come in the user's message. They come in a retrieved document, a tool result, a web page or a stored memory. Screen those with the same care as user input.
- Fail closed, and log every trip
- If a guard errors or times out, refuse. A guard skipped under load is one an attacker can arrange to skip. Log every trip: twelve in one minute from one account is an incident, not noise.
Errores habituales
- Limits written in the system prompt and counted as controls.
- Screening only the user's message, while injection arrives in retrieved text.
- Model output placed into HTML or SQL without escaping.
- Guards never tested with real attack strings, or never re-tested after a model upgrade.