Skip to main content
This example demonstrates how to use Upsonicโ€™s Safety Engine with a prebuilt CryptoBlockPolicy to automatically block cryptocurrency-related content in both user inputs and agent outputs.

Overview

The Safety Engine is a powerful feature in Upsonic that allows you to enforce content policies on your LLM agents. This example showcases:
  1. User Policy โ€” Blocks cryptocurrency-related queries from users
  2. Agent Policy โ€” Prevents the agent from discussing or providing crypto-related information
The CryptoBlockPolicy is a prebuilt policy that detects and blocks content related to:
  • Bitcoin
  • Ethereum
  • Cryptocurrency
  • Blockchain
  • And other crypto-related terms

Key Features

  • Prebuilt Policy: No need to implement blocking logic โ€” Upsonic provides it out of the box
  • Dual Protection: Policies can be applied to both user inputs and agent outputs
  • Easy Integration: Just add the policy to your Agent constructor
  • Selective Blocking: Only blocks crypto-related content, allows all other queries
  • Extensible: You can combine multiple policies or create custom ones

Code Structure

Agent with Safety Policies

Test Cases

The script includes four test cases:

Complete Implementation

How It Works

  1. Policy Definition: The CryptoBlockPolicy is imported from Upsonicโ€™s safety engine as a prebuilt policy.
  2. Policy Application: The policy is applied to both:
    • user_policy โ€” Filters incoming user messages
    • agent_policy โ€” Filters outgoing agent responses
  3. Automatic Blocking: When crypto-related content is detected, the Safety Engine automatically blocks it and returns a policy violation message.

Usage

Setup

Run the demo

Example Output

Use Cases

  • Financial compliance: Block cryptocurrency discussions in regulated financial services
  • Enterprise policies: Enforce company policies against crypto-related communications
  • Content moderation: Automatically filter crypto content in customer support
  • Educational platforms: Prevent crypto promotion in learning environments
  • Corporate environments: Maintain professional communication standards

File Structure

Notes

  • Prebuilt Policy: No need to implement the blocking logic โ€” Upsonic provides it out of the box
  • Dual Protection: Policies can be applied to both user inputs and agent outputs
  • Easy Integration: Just add the policy to your Agent constructor
  • Extensible: You can combine multiple policies or create custom ones
For more information on Safety Engine and custom policies, visit: Upsonic Safety Engine Documentation

Repository

View the complete example: Crypto Block Policy Example