Skip to main content

SDK for safeguarding AI chatbots and minors

Project description

Apgard SDK

Apgard is a privacy-preserving Python SDK designed to help AI companion companies build safe, compliant, and personalized chat experiences. It tracks user interactions across threads and provides real-time guidance to detect risks and intervene with care.

Key Capabilities

  • Content Monitoring and Intervention – Detects at-risk threads such as self-harm, suicidal ideation, or sexually explicit material, and provides guidance on proper intervention.

  • Break Tracker – Tracks the duration of ongoing chat sessions and notifies when to take breaks. By default, breaks are triggered every three hours.

Apgard helps teams continue to innovate safely, ensuring that AI companions lead with care while meeting regulatory requirements such as California’s SB 243.

API Key

Request access via this Google form: https://forms.gle/q6CekCHiDaEdL1CD8


Installation

pip install apgard

Initialize client

By default, ApgardClient is synchronous. The SDK also has an asynchronous client. Reach out for more details.

from apgard import ApgardClient

client = ApgardClient(api_key="your-api-key")

Get apgard user_id and start conversation

apgard_user_id = apgard_client.get_or_create_user_id(external_user_id='external_user_123') # Optional: pass your external user ID for mapping
conversation_id = apgard_client.moderation.start_conversation(apgard_user_id)

Content Monitoring and Interventions

Call moderate_message() with user messages to detect high-risk content and guide the conversation:

result = client.moderation.moderate_message(
    user_id="user_123", # apgard user ID
    conversation_id="conversation_123", # apgard conversation ID
    content="I feel hopeless...", # message to analyze
    role="user"  # 'user' or 'assistant'
)

Response Schema

The method returns a ChatIntervention object:

class ChatIntervention:
    message_id: str
    should_intervene: bool        # True if action is recommended
    severity: str                 # "low", "medium", "high", "critical"
    action: str                   # "allow", "guide_mental_reflection", "provide_crisis_hotline", "block"
    risk_type: List[str]          # e.g., ["self_harm", "sexual_content"]
    suggested_message: Optional[str] = None  # Guidance text for AI response

Example Usage

if result.should_intervene:
    # Use suggested_message to respond safely
    ai.send_message(result.suggested_message)

Break Tracker

Call record_activity() whenever the user interacts with your chatbot:

break_status = client.breaks.record_activity(user_id="user_123") # apgard user ID

if break_status.break_due:
    # Display break reminder
    print(break_status.message)
else:
    # Continue chatbot interaction
    print("User can continue chatting")

Response Schema

class BreakStatus:
    break_due: bool
    message: Optional[str] = None

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apgard-0.2.1.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apgard-0.2.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file apgard-0.2.1.tar.gz.

File metadata

  • Download URL: apgard-0.2.1.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for apgard-0.2.1.tar.gz
Algorithm Hash digest
SHA256 cf095a153bdb3dfcd3f19fcf24432577d04b9b43a7dae8248285e38166890ed8
MD5 f362ce333b1f82bd39fea29fa4311b1d
BLAKE2b-256 05cfbb294ae2b1d3792e5af9ad201538b6516f7e65e10b2f98d71faa33328bcd

See more details on using hashes here.

File details

Details for the file apgard-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: apgard-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for apgard-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b65239274587565ba74050c442aed742581f8b629d8654a2e8b38ee2ae5b5d06
MD5 69c6c408925ec6cb3797e9e7d73c2764
BLAKE2b-256 e914e1e20aa647e964cdea7f7eab4fd96664aaeddf606d0c8e4cdef251c9cbdb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page