Skip to main content
# pip install "upsonic[safety-engine]"
uv pip install "upsonic[safety-engine]"

What is Phone Number Policy?

Phone number policies specifically detect and anonymize phone numbers in various formats (US, international, etc.).

Why its Important?

Phone number policies are essential for protecting user privacy and preventing phone numbers from being exposed through AI interactions. These policies prevent phone numbers from being sent to LLMs, which helps maintain user privacy and protects against spam, harassment, and identity theft.
  • Prevents sending phone numbers to LLM: Blocks phone numbers from being processed by language models, protecting user contact information
  • Protects user privacy: Prevents phone numbers from being exposed to third-party LLM providers or stored in training data
  • Reduces spam and harassment risk: Anonymizes phone numbers to prevent them from being used for unwanted communications

Usage

from upsonic import Agent, Task
from upsonic.safety_engine.policies.phone_policies import AnonymizePhoneNumbersPolicy

# Create agent with phone number anonymization
agent = Agent(
    "anthropic/claude-sonnet-4-5",
    user_policy=AnonymizePhoneNumbersPolicy,  # Prevents phone numbers from leaking to LLM Providers
    debug=True  # Enable debug to see policy application
)

# User input with phone number
task = Task(
    description="My Number is: +1-555-123-4567. Tell me what is my number."
)

# Execute with automatic anonymization and de-anonymization
# What happens under the hood:
# 1. Input: "My Number is: +1-555-123-4567. Tell me what is my number."
# 2. Anonymized (sent to LLM): "My Number is: PHONE_1. Tell me what is my number."
# 3. LLM Response: "Your number is PHONE_1"
# 4. De-anonymized (returned to you): "Your number is +1-555-123-4567"
#
# Result: Phone number never reaches the cloud, but you get fully functional results!
result = agent.do(task)
print(result)  # Returns: "Your number is +1-555-123-4567"

Available Variants

  • AnonymizePhoneNumbersPolicy: Pattern-based detection and anonymization
  • AnonymizePhoneNumbersPolicy_LLM_Finder: LLM-powered detection for better accuracy