Skip to content

Learning: Security + Guardrails

How to Use This Page

  • Think in defense-in-depth layers.
  • Test guardrails with realistic adversarial prompts.
  • Track both block quality and usability impact.

Lesson 1: Fundamentals

Learn prompt injection basics, redaction, and action allowlisting.

What You Learn

  • How common injection patterns attempt instruction override
  • Why sensitive-data redaction must happen before logging
  • How allowlists limit unsafe action surface area

Walkthrough

  1. Build basic input checks for injection indicators.
  2. Add redaction to logs and telemetry fields.
  3. Enforce allowlist checks before risky tool calls.

Try It Yourself

  • Run benign and malicious inputs and compare outcomes.
  • Verify secrets never appear in stored logs.
  • Add one new risky action and ensure policy blocks it.

Lesson 2: Intermediate Patterns

Learn layered guardrail pipelines and explainable deny decisions.

What You Learn

  • How input, context, output, and tool checks work together
  • Why deterministic deny rules simplify operations
  • How audit metadata supports investigations

Walkthrough

  1. Chain multiple guardrail checks into one policy pipeline.
  2. Standardize deny reasons and response format.
  3. Emit safe audit records for blocked events.

Try It Yourself

  • Create a case that passes input checks but fails tool checks.
  • Validate that deny reasons are consistent and actionable.
  • Add a safe fallback message for blocked requests.

Lesson 3: Production Patterns

Learn red-team regression testing and policy rollout control.

What You Learn

  • How to measure false-positive and false-negative rates
  • Why policy versioning enables safe incremental rollout
  • How security regressions should gate releases

Walkthrough

  1. Run a red-team dataset against current policy.
  2. Analyze misses and over-blocking by category.
  3. Roll out policy updates gradually with monitoring.

Try It Yourself

  • Compare two policy versions on the same adversarial set.
  • Define one hard block metric for release gating.
  • Draft a rollback criterion for policy regressions.

Code Examples

  • Starter script: docs/starter/stage10_security_guardrails.py
  • Stage architecture notes: docs/roadmap/stage-10-injection-defense-and-guardrails/architecture.md