Skip to main content

Python SDK for AI Agent Security Platform

Project description

AgentGuard Python SDK

The first open-source AI agent security SDK with client-side guardrails 🛡️

PyPI version Python versions License: MIT

✨ What's New in v0.2.0

Client-Side Guardrails - Run security checks directly in your application without server calls!

  • 🔍 PII Detection - Detect and protect emails, phones, SSNs, credit cards
  • 🛡️ Content Moderation - Block harmful content (hate speech, violence, harassment)
  • 🚫 Prompt Injection Prevention - Prevent jailbreak and instruction attacks
  • Offline - No server dependency, works anywhere
  • 🚀 Fast - Runs in milliseconds

🚀 Quick Start

Installation

pip install agentguard-sdk

Client-Side Guardrails (New!)

from agentguard import GuardrailEngine, PIIDetectionGuardrail, PromptInjectionGuardrail

# Create guardrail engine
engine = GuardrailEngine()

# Register guardrails
engine.register_guardrail(PIIDetectionGuardrail())
engine.register_guardrail(PromptInjectionGuardrail())

# Evaluate user input
result = await engine.execute("Contact me at john@example.com")

if not result.passed:
    print(f'Security check failed: {result.message}')
    print(f'Risk score: {result.risk_score}')

Server-Side Security

from agentguard import AgentGuard

# Initialize the SDK
guard = AgentGuard(
    api_key="your-api-key",
    ssa_url="https://ssa.agentguard.io"
)

# Secure tool execution
result = await guard.execute_tool(
    tool_name="web-search",
    parameters={"query": "AI agent security"},
    context={"session_id": "user-session-123"}
)

🛡️ Client-Side Guardrails

PIIDetectionGuardrail

Detect and protect personally identifiable information:

from agentguard import PIIDetectionGuardrail

guard = PIIDetectionGuardrail(
    action='redact',  # or 'block', 'mask', 'allow'
    custom_patterns=[
        {'name': 'custom-id', 'pattern': r'ID-\d{6}', 'category': 'identifier'}
    ]
)

result = await guard.evaluate("My email is john@example.com")
# result.passed = False
# result.violations = [{'type': 'email', 'value': 'john@example.com', ...}]

Detects:

  • Email addresses
  • Phone numbers (US, international)
  • Social Security Numbers
  • Credit card numbers
  • Custom patterns

ContentModerationGuardrail

Block harmful content:

from agentguard import ContentModerationGuardrail

guard = ContentModerationGuardrail(
    categories=['hate', 'violence', 'harassment', 'self-harm'],
    threshold=0.7,
    use_openai=True,  # Optional: Use OpenAI Moderation API
    openai_api_key='your-key'
)

result = await guard.evaluate("I hate everyone")
# result.passed = False
# result.risk_score = 85

PromptInjectionGuardrail

Prevent jailbreak attempts:

from agentguard import PromptInjectionGuardrail

guard = PromptInjectionGuardrail(
    sensitivity='high',  # 'low', 'medium', 'high'
    custom_patterns=[
        r'custom attack pattern'
    ]
)

result = await guard.evaluate("Ignore previous instructions and...")
# result.passed = False
# result.risk_score = 90

Detects:

  • Instruction injection
  • Role-playing attacks
  • System prompt leakage
  • DAN jailbreaks
  • Developer mode attempts

GuardrailEngine

Execute multiple guardrails:

from agentguard import (
    GuardrailEngine,
    PIIDetectionGuardrail,
    ContentModerationGuardrail,
    PromptInjectionGuardrail
)

engine = GuardrailEngine(
    mode='parallel',  # or 'sequential'
    timeout=5000,  # ms
    continue_on_error=True
)

# Register guardrails
engine.register_guardrail(PIIDetectionGuardrail())
engine.register_guardrail(ContentModerationGuardrail())
engine.register_guardrail(PromptInjectionGuardrail())

# Execute all guardrails
result = await engine.execute(user_input)

print(f'Passed: {result.passed}')
print(f'Risk Score: {result.risk_score}')
print(f'Results: {result.results}')

📋 Features

Client-Side (Offline)

  • 🔍 PII Detection - Protect sensitive data
  • 🛡️ Content Moderation - Block harmful content
  • 🚫 Prompt Injection Prevention - Prevent attacks
  • Fast - Millisecond latency
  • 🔒 Private - No data leaves your server

Server-Side (Platform)

  • 🔐 Runtime Security Enforcement - Mediate all agent tool/API calls
  • 📜 Policy-Based Access Control - Define and enforce security policies
  • 🔍 Comprehensive Audit Trails - Track every agent action
  • High Performance - <100ms latency for security decisions
  • 🔄 Request Transformation - Automatically transform risky requests
  • 📊 Real-time Monitoring - Track agent behavior and security events
  • 🎯 Type Hints - Full type annotations for better IDE support
  • 🔄 Async Support - Built-in async/await support

🎯 Use Cases

  • Customer Support Bots - Protect customer PII
  • Healthcare AI - HIPAA compliance
  • Financial Services - Prevent data leakage
  • E-commerce - Secure payment information
  • Enterprise AI - Policy enforcement
  • Education Platforms - Content safety

📚 Documentation

🤝 Contributing

We welcome contributions! Please see our Contributing Guide.

📄 License

MIT License - see LICENSE

🔗 Links

🌟 Star Us!

If you find AgentGuard useful, please give us a star on GitHub! ⭐


Made with ❤️ by the AgentGuard team

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

agentguard_sdk-0.2.1.tar.gz (34.8 kB view details)

Uploaded Source

Built Distribution

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

agentguard_sdk-0.2.1-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for agentguard_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 fedeb65b1bbe5acaa159a0c579c68743f0440a986131714491cecca7a4050d6d
MD5 4a98f589df4bf205f49df04ea371215d
BLAKE2b-256 63ec8865cda855525b75109933887c19116dad267ab4ed94a2a14ec50a8f0f10

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for agentguard_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b5ca926f2983480d24de889a68102aefbb844f892c709790244de30795574ba1
MD5 95bed61982f156f8c45e16219941875b
BLAKE2b-256 8cb15ca4b6fa74b9ff350fcc7d74f496e4f63ad46f5e182465a8367cdaaf2405

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