AI engineering glossary · Evals guardrails AI security
What is guardrail?
Guardrail (also called guardrails, AI guardrails): A control placed around a language model to keep its behaviour safe, on-topic and reliable, such as filters on inputs, checks on outputs, permission limits or validation of formats. Guardrails work alongside the model's own training and act as a second line of defence.
Guardrail: an example
A banking assistant has a guardrail that blocks replies giving investment advice and returns a standard message instead.
Guardrail in Python
A short example you can run (Python 3.11). The output below is what it really prints.
import re
def redact_pii(text):
text = re.sub(r"\b[6-9]\d{9}\b", "[PHONE]", text) # Indian mobile numbers
text = re.sub(r"\b[\w.+-]+@[\w-]+\.[\w.]+\b", "[EMAIL]", text)
text = re.sub(r"\b[A-Z]{5}\d{4}[A-Z]\b", "[PAN]", text) # PAN card format
return text
print(redact_pii("Call 9876543210 or mail [email protected], PAN ABCDE1234F"))Output
Call [PHONE] or mail [EMAIL], PAN [PAN]
Related terms
More Evals guardrails AI security terms
- Guardrails AI
- HarmBench
- HELM
- HumanEval
- Improper output handling
- Input guardrail
- Intrinsic hallucination
- ISO/IEC 42001
Where you learn it
Guardrail is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.