Skip to main content

Overview

Safety Engine provides content filtering and policy enforcement for AI agents. It controls what goes into agents (user input) and what comes out (agent responses) by applying policies that detect and handle sensitive content.

Why you Should Use Safety Policies

Safety policies are essential for protecting sensitive information and ensuring compliance with your organization’s security and privacy requirements. When you send data to LLM providers, that data may be used for training, stored in logs, or processed in ways that could expose sensitive information. Safety policies act as a critical first line of defense by:
  • Preventing Data Leaks: Stop sensitive information like PII, financial data, or confidential business information from being sent to LLM providers
  • Ensuring Compliance: Meet regulatory requirements (GDPR, HIPAA, etc.) by automatically detecting and handling sensitive content
  • Enforcing Company Policies: Automatically apply your organization’s content safety rules across all agent interactions
  • Maintaining Control: Track and monitor what content is being filtered, giving you visibility into safety policy enforcement
  • LLM-Agnostic Protection: Once created, your policies work with any LLM provider, ensuring consistent safety regardless of the underlying model

Key Features

  • Policy Points: You can use three different points to put your policies
    • User Inputs
    • Agent Outputs
    • Tool Interactions
  • Pre-built Policies: Ready-to-use policies for PII, adult content, hate speech, profanity, etc.
  • Custom Policies: Create your own rules and actions
  • Pre-built Action Types: Block, anonymize, replace, or raise exceptions
  • Multi-language Support: Automatically adapts to user’s language

Example

from upsonic import Agent, Task
from upsonic.safety_engine.policies.pii_policies import PIIAnonymizePolicy

# Create agent with PII anonymization
agent = Agent(
    "openai/gpt-4o",
    user_policy=PIIAnonymizePolicy,  # Prevents data leak to LLM Providers
    debug=True  # Enable debug to see policy application
)

# User input with PII
task = Task(
    description="My email is [email protected] and phone is 555-1234. What are my email and phone?"
)

# Execute - PII will be anonymized in input before sending to LLM
# The policy detects and anonymizes PII, preventing it from reaching LLM providers
result = agent.do(task)
print(result)  # Input PII is anonymized before reaching LLM providers
  • Policy Points - Learn where and when to apply safety policies in your agent
  • Pre-built Policies - Ready-to-use policies for PII, adult content, hate speech, profanity, and more
  • Custom Policy - Create your own safety policies with custom rules and actions
  • Creating Rules - Define custom detection rules for content filtering
  • Creating Actions - Configure actions for policy violations