Production Security Mindset
LLM Production Security
: The practices and controls required to safely operate LLM-powered applications in production, protecting against adversarial input, data leakage, excessive costs, and system compromise.
Production LLM security differs from development:
- Real attackers, not theoretical threats
- User data at risk
- Financial impact from abuse
- Compliance requirements
Best Practice 1: Secure Architecture
Principle of Least Privilege
| |
Isolation Layers
| |
Best Practice 2: Input Handling
Comprehensive Validation
| |
Sanitization Pipeline
| |
Best Practice 3: Output Handling
PII Detection and Redaction
| |
Response Validation
| |
Best Practice 4: Access Control
API Key Management
| |
Rate Limiting
| |
Best Practice 5: Monitoring
Comprehensive Logging
| |
Alerting Rules
| |
Best Practice 6: Cost Controls
| |
Security Checklist
Production LLM Security Checklist
Pre-deployment security verification
Input Validation
- Maximum input length enforced
- Injection patterns detected and blocked
- Hidden characters stripped
- Context limits enforced
Prompt Security
- System prompt hardened against override
- User content clearly delimited
- No secrets in prompts
Output Security
- PII detection and redaction active
- Response validation implemented
- No raw error messages to users
Access Control
- API key rotation configured
- Rate limiting per user
- Role-based permissions
Monitoring
- All requests logged
- Security events alerted
- Cost tracking active
FAQ
How often should API keys be rotated?
Every 90 days for standard access, every 30 days for high-privilege access. Implement key rotation before deployment.
What's a reasonable rate limit?
Depends on use case. Start conservative (10-20 requests/minute), monitor actual usage, and adjust. Always have per-user and global limits.
Should I log full prompts and responses?
Log metadata (length, hash) but not full content to avoid storing PII. Keep full logs only for security investigations with appropriate access controls.
How do I handle LLM provider outages?
Implement circuit breakers, have fallback responses for critical paths, and monitor provider status. Consider multi-provider setups for high-availability requirements.
Conclusion
Key Takeaways
- Least privilege: LLM should have minimal permissions
- Isolate LLM from direct data access and actions
- Validate all inputs with length limits and injection detection
- Filter outputs for PII and validate format
- Implement API key management with rotation
- Rate limit per user and globally
- Log comprehensively, alert on anomalies
- Control costs with budgets and monitoring