gpt-4o for main responses, while the policy enforcement is powered by OpenAI’s safety-focused gpt-oss-safeguard-20b model via OpenRouter.
Overview
The Safety Engine is a powerful feature in Upsonic that allows you to enforce content policies on your LLM agents. This example showcases:- Dual Model Architecture — Using
gpt-4ofor agent responses andgpt-oss-safeguard-20bfor policy enforcement - OpenRouter Provider — Accessing OpenAI’s safety models through the OpenRouter API
- PII Block Policy LLM — LLM-powered detection and blocking of personal information (emails, phone numbers, SSN, etc.)
- User Policy Feedback — Providing helpful guidance instead of just blocking content
- Feedback Loop — Allowing users to retry with corrected input
PIIBlockPolicy_LLM is a prebuilt policy that uses LLM-powered detection to identify and block content containing:
- Email addresses
- Phone numbers
- Social Security Numbers
- Credit card numbers
- Home addresses
- And other personally identifiable information
Key Features
- Prebuilt Policy: No need to implement PII detection logic — Upsonic provides it out of the box
- Dual Model Setup: Uses
gpt-4ofor high-quality responses andgpt-oss-safeguard-20bfor safety enforcement - LLM-Powered Detection: Policy uses an LLM for contextual understanding of PII, not just pattern matching
- Safety-Focused Model: Policy enforcement uses OpenAI’s gpt-oss-safeguard-20b, specifically designed for safe interactions
- Helpful Feedback: Instead of just blocking, provides guidance on how to rephrase queries
- OpenRouter Provider: Access OpenAI’s safety models through the OpenRouter API
- Easy Integration: Configure the policy’s LLM and add it to your Agent constructor
File Structure
Prerequisites
Set your API keys:Installation
Managing Dependencies
api, streamlit, development
Usage
Option 1: Run Directly
Option 2: Run as API Server
http://localhost:8000. API documentation at /docs.
Example API call:
How It Works
Example Output
Safe query:Complete Implementation
main.py
upsonic_configs.json
Note: The gpt-oss-safeguard-120b variant is not yet available on OpenRouter.
Use Cases
- Customer support: Prevent accidental PII exposure in support conversations
- Healthcare applications: Ensure HIPAA compliance by blocking PHI
- Financial services: Protect sensitive financial information
- Enterprise applications: Enforce data privacy policies
- Public-facing chatbots: Prevent users from sharing personal information
Environment Variables
For more information on Safety Engine and custom policies, visit: Upsonic Safety Engine Documentation

