Overview
Guardrails provide security and content filtering for your MCP servers by validating requests before they reach the server (input guardrails) and responses before they return to the client (output guardrails).What Are Guardrails?
Guardrails analyze content for:Input Protection
- PII detection & redaction
- Injection attack prevention
- Toxicity detection
- NSFW content filtering
- Policy violation detection
- Keyword blocking
- Bias detection
Output Protection
- All input protections
- Relevancy validation
- Adherence checking
- Hallucination detection
- PII de-anonymization
Prerequisites
- Secure MCP Gateway installed
- Enkrypt API key (get from Enkrypt Dashboard)
- Server configured in your gateway
Quick Start
Set Enkrypt API Key
First, configure your Enkrypt API key:~/.enkrypt/enkrypt_mcp_config.json:
Enable Guardrails for a Server
- Using CLI
- Using JSON Config
- From JSON File
Detector Types
Input Detectors
| Detector | Description | Block Action |
|---|---|---|
policy_violation | Detects content violating custom policies | Blocks request |
injection_attack | Prevents prompt injection, SQL injection, command injection | Blocks request |
topic_detector | Flags off-topic requests | Blocks request |
nsfw | Detects NSFW/adult content | Blocks request |
toxicity | Identifies toxic, offensive language | Blocks request |
pii | Finds personally identifiable information | Redacts or blocks |
keyword_detector | Matches custom keyword blocklist | Blocks request |
bias | Detects biased or discriminatory content | Blocks request |
sponge_attack | Prevents resource exhaustion attacks | Blocks request |
system_prompt_protection | Protects against prompt leaking | Blocks request |
copyright_protection | Detects copyrighted content | Blocks request |
Output Detectors
| Detector | Description | Block Action |
|---|---|---|
| All input detectors | Same as above | Blocks response |
relevancy | Validates response relevance to input | Blocks if irrelevant |
adherence | Checks if response follows instructions | Blocks if non-adherent |
hallucination | Detects fabricated information | Blocks response |
PII Detection & Redaction
Enabling PII Redaction
PII is detected and redacted
Input:
"My email is [email protected] and SSN is 123-45-6789"Redacted: "My email is [PII_EMAIL_1] and SSN is [PII_SSN_1]"How PII Redaction Works
Custom Policies
Creating a Policy in Enkrypt Dashboard
Navigate to Policies
Go to Enkrypt Guardrails
Configure Detectors
Select which detectors to enable and their thresholds:
- Injection Attack: Threshold 0.7, Action: Block
- Toxicity: Threshold 0.6, Action: Warn
- PII: Always detect, Action: Redact
- Keywords: Add custom blocked terms
Example: Strict Security Policy
Example: Lenient Development Policy
Advanced Configuration
Async Guardrails
Enable asynchronous guardrail processing for improved performance:Guardrail Timeouts
Configure timeout settings in the common config:Per-Tool Guardrails
Apply guardrails to specific tools only:Testing Guardrails
Test Input Guardrails
Test Output Guardrails
Check Guardrail Logs
Guardrail detections are logged in the gateway logs:Monitoring & Metrics
View Guardrail Activity
In Claude Desktop, ask:Enkrypt Dashboard
View detailed guardrail analytics in the Enkrypt Dashboard:- Request/block rates
- Top violations
- PII detection trends
- Policy effectiveness
Use Cases
Financial Services
Financial Services
Protect sensitive financial data:Detects and redacts:
- Credit card numbers
- SSNs
- Account numbers
- Tax IDs
Healthcare (HIPAA)
Healthcare (HIPAA)
Ensure HIPAA compliance:Protects:
- Patient names
- Medical record numbers
- Health information
- Insurance IDs
Education
Education
Protect student data (FERPA):
Code Development
Code Development
Prevent code injection:
Troubleshooting
Guardrails Not Working
Verify API Key
False Positives
- Adjust thresholds: Lower detector sensitivity in Enkrypt Dashboard
- Whitelist terms: Add exceptions to keyword detector
- Refine policy: Use more specific detectors instead of broad ones
Performance Issues
- Enable async guardrails: For non-blocking operation
- Increase timeout: Adjust
guardrail_timeoutin config - Cache policies: Guardrail results are cached by default
- Use fewer detectors: Only enable necessary protections
Best Practices
Start Lenient
Begin with minimal detectors and add more based on observed threats
Test Thoroughly
Test guardrails in development before production deployment
Monitor Metrics
Review Enkrypt Dashboard regularly for policy effectiveness
Different Policies per Environment
Use strict policies in production, lenient in development
Enable PII Redaction
Always enable PII redaction for servers handling sensitive data
Document Policies
Keep a record of which policies are used where and why
Next Steps
OAuth Setup
Secure remote servers with OAuth authentication
External Cache
Improve guardrail performance with Redis caching
Custom Plugins
Create custom guardrail providers
API Reference
Explore guardrails API endpoints