LLMOps · Module 04
AI Safety & Guardrails
The risks specific to LLM applications and the layers that contain them: the OWASP LLM Top 10, guardrail architecture and frameworks, defence in depth, and how to test guardrails.
Học xong bạn làm được
- Name the main risks in the OWASP LLM Top 10
- Describe input and output guardrails
- Apply defence in depth to an LLM application
- Test guardrails and keep an audit trail
- Compare NeMo Guardrails, Guardrails AI and LLM-as-judge
Bài học
- The OWASP LLM Top 10 (2025)
Production LLM applications need safety boundaries against harmful outputs, data leaks and unreliable behaviour. The OWASP LLM Top 10 is the reference threat model - prompt injection, sensitive data leakage, supply chain, data and model poisoning, improper output handling, excessive agency, system prompt leakage, vector and embedding weaknesses, misinformation and unbounded consumption.
- Guardrail architecture
Guardrails work at two layers. Input guardrails run before the LLM sees anything - prompt injection detection, PII scrubbing, topic boundaries, rate limits and length limits. Output guardrails run before the answer leaves - toxicity filtering, factuality checks, format validation, PII detection and hallucination flags. A blocked input gets a rejection; a blocked output a safe fallback.
- Guardrail frameworks
NeMo Guardrails (NVIDIA) defines dialog flows and safety rails in the Colang language - input, output, topical, fact-checking and multimodal rails. Guardrails AI composes independent validators such as PIIFilter, ToxicLanguage, ValidJson, RestrictToTopic and DetectSecrets. LLM-as-judge uses a separate model to score each candidate response, calibrated against human labels.
- Defence in depth and a practical implementation
No single guardrail is enough - layering length and rate limits, injection detection, PII scrubbing and topic classification before the model, and factuality, toxicity, PII and format checks after it, means a failure at one layer is caught by the next. A minimal Python wrapper shows the pattern - detect injection, scrub PII, generate, filter toxicity, scrub again - failing closed.
- Guardrail testing, audit relevance and summary
Guardrails are tested like production code - unit, adversarial (red-team), regression and performance tests, with the red-team suite run on every deployment. For auditors, guardrails are a primary control - check PII protection on every path, logged guardrail decisions, least privilege for agents, vendor and supply-chain documentation, and evidence of red-team testing.