Content Safety and Moderation › When to Use External Moderation Services
AI Agent HandbookAll chapters Content Safety and Moderation › When to Use External Moderation ServicesOne section · Sections in this chapter10 / 13 ↓
Building your own safety system works well for many applications, but sometimes you need more robust solutions. Consider using external moderation services when:
You're handling high volumes: Dedicated moderation services are optimized for speed and scale.
You need specialized detection: Some services specialize in detecting specific types of harmful content (like child safety issues) that require domain expertise.
You want continuous updates: Professional services update their models regularly as new threats emerge.
You need audit trails: Some industries require detailed logs of content moderation decisions.
Popular options include OpenAI's Moderation API, Azure Content Safety, and Perspective API from Google. These can complement your own safety measures:
## Example: Using OpenAI's Moderation API alongside your own safety measures
from openai import OpenAI
openai_client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def check_with_openai_moderation(text):
"""Use OpenAI's moderation API as an additional safety layer"""
response = openai_client.moderations.create(input=text)
result = response.results[0]
if result.flagged:
categories = [
cat for cat, flagged in result.categories.items() if flagged
]
return False, categories
return True, []
## Use it alongside your own checks
def comprehensive_safety_check(text):
# Your own checks
has_sensitive, pattern = assistant.contains_sensitive_patterns(text)
if has_sensitive:
return False, f"Sensitive pattern: {pattern}"
# External moderation
is_safe, categories = check_with_openai_moderation(text)
if not is_safe:
return False, f"Flagged categories: {', '.join(categories)}"
return True, "Safe"This layered approach gives you both customization (your own rules) and robustness (professional moderation).