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.
Release files for guardian-ai 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| guardian_ai-0.1.0.tar.gz | 6.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| guardian_ai-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.3 kB
Release files / guardian_ai-0.1.0.tar.gz
| Download URL | guardian_ai-0.1.0.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9fc86285c529ed34fc5e48315dee981b1f7bee5e9eaf14550af0676e814f8010
|
|
BLAKE2b-256 checksum How to use checksums |
df78280da1c2869da8f5e62094e4c939644d28161b90e36350d029ca84dfb44f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.13.2 Darwin/24.3.0
|
Release files / guardian_ai-0.1.0-py3-none-any.whl
| Download URL | guardian_ai-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
626da0d2dd95ef60c0661bfb9709f4e7fe12408f24f1965eb1c7dc0f4dda8eaf
|
|
BLAKE2b-256 checksum How to use checksums |
02bdfd4f345d6540ed58540776617015be40e7db09693e7095d488e272268144
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.13.2 Darwin/24.3.0
|