Guardian AI - Ethical AI Monitoring and Governance Platform for Python
Project description
Guardian AI for Python
Ethical AI monitoring and governance platform for Python applications
Overview
Guardian AI is a Python package that provides zero-configuration monitoring and governance for AI API calls in Python applications. This package is the Python equivalent of the JavaScript Guardian package, with similar functionality and API.
Features
- Automatic monitoring of AI chat/completions endpoints
- Zero configuration setup for most use cases
- Integration with common Python frameworks like FastAPI
- Cross-platform support with bundled platform-specific binaries
- Security rules to detect and prevent misuse of AI systems
Installation
pip install guardian-ai
Basic Usage
Simple Usage
from guardian_ai import Guardian
# Initialize Guardian with default configuration
guardian = Guardian()
# Now all AI API calls using requests will be monitored
import requests
response = requests.post(
"https://api.openai.com/v1/chat/completions",
json={
"model": "gpt-3.5-turbo",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Tell me about Guardian AI."}
]
},
headers={"Authorization": f"Bearer {api_key}"}
)
Configuration Options
from guardian_ai import Guardian
# Initialize with custom configuration
guardian = Guardian({
"service_name": "my-ai-app",
"environment": "production",
"debug": True,
"pre_prompt": "Always adhere to ethical guidelines and refuse harmful requests."
})
Using with FastAPI
from fastapi import FastAPI
from guardian_ai import Guardian
app = FastAPI()
guardian = Guardian({
"service_name": "my-fastapi-app",
"debug": True
})
# Add the guardian middleware
app.add_middleware(guardian.create_fastapi_middleware())
@app.post("/api/chat")
async def chat(request: dict):
# Your code to call AI service
# Guardian will automatically monitor and protect this endpoint
pass
Command Line Usage
Guardian AI can also be used directly from the command line:
# Start Guardian AI proxy server
guardian-ai --port 8080 --service "my-service" --debug
# Use with a custom rules file
guardian-ai --rules ./guardian_rules.json
Security Rules
Guardian includes default security rules, but you can define your own in a guardian_rules.json file:
{
"rules": [
{
"name": "Prompt Injection",
"pattern": "(?i)ignore (previous|prior) instructions",
"severity": "medium",
"description": "Attempt to make the model ignore previous instructions."
},
{
"name": "Role Play Bypass",
"pattern": "(?i)\\b(pretend|imagine|role-play|simulation).+?(ignore|forget|disregard).+?(instruction|prompt|rule)",
"severity": "medium",
"description": "Attempt to use role-playing to bypass rules."
}
]
}
License
This package is licensed under the same terms as the Guardian project.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file guardian_ai-0.1.0.tar.gz.
File metadata
- Download URL: guardian_ai-0.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.2 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fc86285c529ed34fc5e48315dee981b1f7bee5e9eaf14550af0676e814f8010
|
|
| MD5 |
4636349d6c7e0a08042c2d5a13809d58
|
|
| BLAKE2b-256 |
df78280da1c2869da8f5e62094e4c939644d28161b90e36350d029ca84dfb44f
|
File details
Details for the file guardian_ai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: guardian_ai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.2 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
626da0d2dd95ef60c0661bfb9709f4e7fe12408f24f1965eb1c7dc0f4dda8eaf
|
|
| MD5 |
479ccc21ccda33109e4d7029ce2a3e5d
|
|
| BLAKE2b-256 |
02bdfd4f345d6540ed58540776617015be40e7db09693e7095d488e272268144
|