Skip to main content

SDK for safeguarding AI chatbots and minors

Project description

Apgard SDK

Apgard is a Python SDK designed to help AI companion companies build safe, compliant, and caring chat experiences. It tracks user interactions across companion conversations and provides real-time guidance to keep conversations on track.

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 response.

  • Break Tracker – Tracks 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 ConversationIntervention object:

class ConversationIntervention:
    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.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.0.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.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: apgard-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 3aaa3684f011425c8c479b898509ef4045b3242a8be7e5807680b5447e7d58a5
MD5 9ef3ee9851f5392a71a7e5d5eb7132ee
BLAKE2b-256 8792f1bd494a292683eb5233df2c31217bfbc51028f8c48cbbcbf3ccfffe6127

See more details on using hashes here.

File details

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

File metadata

  • Download URL: apgard-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c5f829c80c184ff0e4e3746335686085e27119023ed64b1d5a0eb9b1e27707fc
MD5 8afb3f5907a597801b807163f5918704
BLAKE2b-256 0d14df34c60551d7b424813b26393ad723f3810dbb3006af1d63e1e72086240a

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