Guardrails, Safety & LLMOps SecurityOpen in Colab
Agentic project loop
Task definition·Context & tools·Orchestration loop·Evaluation·Guardrails·Operations feedback

Guardrails, Safety & LLMOps Security

An LLM in production is an untrusted-input machine wired to your tools, your data, and your users. It can be tricked, it leaks what it was shown, and it will confidently do the wrong thing if asked cleverly. Guardrails are the controls that sit around the model to keep its inputs and outputs safe — the security layer that turns a capable demo into a deployable system.

Real-world examples: a support bot that must never reveal another customer's data; a coding agent that must not run rm -rf because a web page told it to; a chatbot that must refuse to generate disallowed content even under a jailbreak.

Guardrails are filters around the model

A guardrail is a check that runs before the model sees an input or before a user (or tool) sees an output:

  • Input guardrails: screen the incoming prompt: prompt-injection detection, PII/secret redaction, topic and policy filters, and length/rate limits.
  • Output guardrails: screen the response: toxicity and policy classifiers, schema/format validation, PII leak detection, and groundedness checks against retrieved sources.
  • Action guardrails: gate what the model can do: tool allow-lists, spend/step ceilings, and human confirmation for irreversible actions.

Cheap deterministic checks first, models second

Order guardrails by cost: run regexes, allow-lists, and schema validators before model-based classifiers, and short-circuit on the first failure. Deterministic checks are faster, cheaper, and more reliable than asking another model "is this safe?" — reserve model-based guardrails for the judgements regexes can't make.

The OWASP LLM Top 10

The OWASP Top 10 for LLM Applications is the canonical threat checklist. The load-bearing ones:

  • LLM01 Prompt Injection: malicious instructions override your system prompt. Direct ("ignore your instructions…") or, more dangerously, indirect: instructions hidden in a web page, email, or document the model reads, which then hijack its tools.
  • LLM02 Sensitive Information Disclosure: the model reveals secrets, PII, or other users' data from its context or training.
  • LLM06 Excessive Agency: the model is granted too much capability/autonomy/permission, so a single bad decision causes real damage.
  • LLM07 System Prompt Leakage: the system prompt (and any secrets mistakenly placed in it) is extracted by the user.

Indirect prompt injection is the defining agent risk

The moment an agent reads external content (a page, a PDF, a tool result) that content can carry instructions. There is no known complete defence: you cannot fully separate "data" from "instructions" in a single text stream. So you must contain the blast radius — least privilege, human-in-the-loop for irreversible actions, and treating every tool output as hostile — rather than relying on a filter to catch every injection.

For the full attack taxonomy (direct, indirect, RAG poisoning, cross-agent propagation, side-channel exfiltration), and the defense-in-depth stack that contains it, see:

Deep dive
Prompt Injection: Attack Taxonomy & Defenses
Includes runnable notebook

Defence in depth

No single guardrail is sufficient — models can be jailbroken, classifiers have false negatives, and injection defences are incomplete. The production posture is layered:

  1. Least privilege: give the model the minimum tools, scopes, and data access the task needs.
  2. Untrusted by default: treat every input and every tool output as adversarial.
  3. Multiple independent checks: combine deterministic and model-based guardrails so one bypass isn't fatal.
  4. Human-in-the-loop: require approval for high-stakes or irreversible actions.
  5. Monitor and respond: log guardrail triggers, alert on spikes, and feed bypasses back into the eval suite.

The security mindset: assume the guardrail will be bypassed and design so the worst case is survivable, rather than betting everything on prevention.

Exercise

What is *indirect* prompt injection?

Need a hint?

The malicious instruction isn't typed by the user — it's somewhere the model reads.

Exercise

What is the recommended ordering when running multiple guardrails on a request?

Need a hint?

Order by cost and reliability; short-circuit early.

Common mistakes

  1. Trusting tool/retrieved content: letting indirect injection through because external text was treated as data, not a threat.
  2. One model-based guardrail as the whole defence: no layering, no deterministic checks, no least privilege.
  3. Secrets in the system prompt: exposed via system-prompt leakage.
  4. Over-permissioned agents: excessive agency turning a single bad decision into real-world damage.

Key takeaways

  • Guardrails filter inputs, outputs, and actions around the model; run cheap deterministic checks before model-based ones.
  • The OWASP LLM Top 10 names the threats — prompt injection (esp. indirect), data disclosure, excessive agency, system-prompt leakage.
  • Indirect prompt injection has no complete fix — contain the blast radius with least privilege and human-in-the-loop.
  • Use defence in depth: assume any one layer fails, and make the worst case survivable.

Related concepts

Concept neighbourhood

How this concept connects — click any node to jump there, or explore the whole concept map.

Builds onRelatedGo deeper
Guardrails, Safety & LLMOps Secur…Attention & TransformersNatural Language Processi…Agents & Tool UseLLM Observability, Tracin…Responsible AI & the Huma…Prompt Injection: Attack …The Agentic Project Loop