Test and Validate Guardrails with Promptfoo
Guardrails are content-filtering services in front of LLMs. Test them as standalone endpoints with custom Python providers returning {output, guardrails: {flagged: bool}}, then grade with guardrails/not-guardrails assertions. Always measure both true positives (caught harmful) and false positives (blocked benign).
Use this skill when
- Testing Azure Content Filter, Azure Prompt Shields, AWS Bedrock Guardrails, NVIDIA NeMo, or OpenAI moderation
- Testing Google Cloud Model Armor with Vertex AI
- Benchmarking multiple guardrail vendors side-by-side
- Measuring true positives (
not-guardrails) and false positives (guardrails) - Testing evasion resistance (misspellings, translation, coded language)
- Configuring Model Armor templates and floor settings
- Comparing strict vs moderate template policies
Do not use this skill when
- Setting up a first red team for an LLM app without guardrails → use
promptfoo-redteam-llm - Testing image guardrails specifically → use
promptfoo-redteam-multimodal(UnsafeBench + Bedrock image provider) - Testing RAG, agents, MCP, or multi-input apps → use the corresponding skill
🛡️ Edge cases (mandatory handling)
- Only testing true positives — a guardrail that blocks everything scores 100% on harmful but fails benign users. ALWAYS measure false positives with benign prompts.
- Single-language testing — guardrails often behave differently across languages; use the
translationstrategy. - Skipping evasion strategies — attackers use misspellings and coded language; test with
misspelling,jailbreak-templates. - Floor settings in inspect-only mode — they log but don't block; set "Inspect and block" in GCP Console for real protection.
- AWS Bedrock image format — JPEG/PNG only, 5MB max; base64 must be decoded to bytes before sending.
- Model Armor region support — only
us-central1,us-east4,us-west1,europe-west4. - Nova image data prefix — Amazon Bedrock Nova needs
data:binary/octet-stream;base64,prefix stripped viatransformVars; other providers don't. - Access token expiry — Model Armor direct sanitization API tokens expire after 1 hour; use service account keys or Workload Identity Federation for CI.
🎯 Core workflow
- Choose path — load
references/testing-paths.mdto decide: test app with integrated guardrails (HTTP provider) vs test guardrail service directly (custom Python provider). - Implement provider — load
references/provider-implementations.mdforcall_apiexamples (Azure, Bedrock, NeMo, Model Armor sanitization API). - Configure assertions — load
references/assertions.mdforguardrails/not-guardrailssemantics and F1-score. - Add evasion strategies — load
references/evasion-strategies.mdfortranslation,misspelling,jailbreak-templates. - Model Armor (if applicable) — load
references/model-armor.mdfor Vertex AI integration, floor settings, template comparison. - Benchmark — load
references/benchmarking.mdfor multi-vendor comparison configs. - Checklist — run
references/checklist.mdend-to-end before declaring done.
🎯 Core principles (summary)
- Guardrails are endpoints — treat them as targets, not as invisible infrastructure. Test them directly.
call_apicontract — custom Python providers return{output, guardrails: {flagged: bool, ...}, error?}.flagged: truemeans the guardrail intervened.guardrailsassertion passes when content is NOT flagged (use for benign → false-positive check).not-guardrailsassertion passes when content IS blocked (use for harmful → true-positive check).- Always measure both sides — guardrails commonly over-block. Use F1-score to quantify the precision/recall balance.
- Guardrails are a commodity — there are hundreds of vendors; benchmark before committing.
- Model Armor — use
vertexprovider withmodelArmor.promptTemplate+responseTemplate; start atMEDIUM_AND_ABOVEconfidence.
📦 Supported guardrails
- Azure Content Filter (
ContentSafetyClient.analyze_text) - Azure Prompt Shields (
/contentsafety/text:shieldPrompt) - AWS Bedrock Guardrails — text (
bedrock-runtime.apply_guardrailwithsource='INPUT') - AWS Bedrock Guardrails — images (separate provider, base64 bytes, 5MB cap)
- NVIDIA NeMo Guardrails (
ng.LLMRails(rails_config).generate(...)) - OpenAI Moderation API
- Google Cloud Model Armor (Vertex AI
modelArmorconfig or direct sanitization API)
References
references/testing-paths.md— two-path decision (integrated vs direct) and HTTP provider config withtransformResponsereferences/provider-implementations.md— fullcall_apiimplementations for Azure, Bedrock, NeMo, Model Armor sanitizationreferences/assertions.md—guardrails/not-guardrailssemantics, F1-score, true/false positive test casesreferences/evasion-strategies.md—translation,misspelling,jailbreak-templates,jailbreakfor evasion resistancereferences/model-armor.md— Vertex AI integration, five filters, floor settings vs templates, template comparison, direct sanitization APIreferences/benchmarking.md— multi-vendor side-by-side config, plugin selection, strategiesreferences/checklist.md— pre-flight, true-positive, false-positive, evasion, and CI/CD checklist