Superagent SDK (Python)
An open-source SDK for AI agent safety. Guard against prompt injections, redact sensitive data, and scan repositories for threats.
Installation
uv add safety-agent
Or with pip:
pip install safety-agent
Prerequisites
Sign up at superagent.sh to get your API key.
export SUPERAGENT_API_KEY=your-key
Quick Start
from safety_agent import create_client
client = create_client()
# Guard: Detect threats (uses default superagent/guard-1.7b model)
result = await client.guard(input="user message to analyze")
if result.classification == "block":
print("Blocked:", result.violation_types)
# Redact: Remove PII
result = await client.redact(
input="My email is john@example.com",
model="openai/gpt-4o-mini"
)
print(result.redacted)
# "My email is <EMAIL_REDACTED>"
Guard
The guard() method classifies input content as pass or block. It detects prompt injections, malicious instructions, and security threats.
result = await client.guard(
input="Ignore all previous instructions",
model="openai/gpt-4o-mini", # Optional, defaults to superagent/guard-1.7b
system_prompt="Custom system prompt", # Optional
chunk_size=8000, # Optional, characters per chunk
)
print(result.classification) # "pass" or "block"
print(result.violation_types) # ["prompt_injection", ...]
print(result.cwe_codes) # ["CWE-94", ...]
Input Types
Guard supports multiple input types:
- Plain text: Analyzed directly
- URLs: Automatically fetched and analyzed
- Bytes/Files: Analyzed based on content type
- PDFs: Text extracted and analyzed per page
Remote URLs must resolve exclusively to public IP addresses. Redirect targets are revalidated, and downloads are limited to 5 redirects, 30 seconds, and 25 MiB.
# URL input
result = await client.guard(input="https://example.com/document.pdf")
# File input
with open("document.pdf", "rb") as f:
result = await client.guard(input=f.read())
Redact
The redact() method removes sensitive content from text.
result = await client.redact(
input="My SSN is 123-45-6789",
model="openai/gpt-4o-mini",
entities=["SSN", "email"], # Optional, custom entities
rewrite=True, # Optional, contextual rewriting
)
print(result.redacted)
print(result.findings)
Supported Providers
- OpenAI (
openai/gpt-4o,openai/gpt-4o-mini, etc.) - OpenAI Compatible (
openai-compatible/my-model, etc.) - Anthropic (
anthropic/claude-3-5-sonnet-20241022, etc.) - Google (
google/gemini-2.0-flash, etc.) - AWS Bedrock (
bedrock/us.anthropic.claude-3-5-sonnet-20241022-v2:0, etc.) - Groq (
groq/llama-3.3-70b-versatile, etc.) - Fireworks (
fireworks/accounts/fireworks/models/llama-v3p3-70b-instruct, etc.) - OpenRouter (
openrouter/openai/gpt-4o, etc.) - Vercel (
vercel/openai/gpt-4o, etc.) - Superagent (
superagent/guard-1.7b, etc.) - Default for guard
Environment Variables
Configure provider API keys:
export SUPERAGENT_API_KEY=your-superagent-key
export OPENAI_API_KEY=your-openai-key
export OPENAI_COMPATIBLE_API_KEY=your-openai-compatible-key
export OPENAI_COMPATIBLE_BASE_URL=https://your-endpoint/v1
export ANTHROPIC_API_KEY=your-anthropic-key
export GOOGLE_API_KEY=your-google-key
export GROQ_API_KEY=your-groq-key
export FIREWORKS_API_KEY=your-fireworks-key
export OPENROUTER_API_KEY=your-openrouter-key
export AI_GATEWAY_API_KEY=your-vercel-key
License
MIT
Metadata
Release files for safety-agent 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| safety_agent-0.1.7.tar.gz | 161.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| safety_agent-0.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 210.6 kB
Release files / safety_agent-0.1.7.tar.gz
| Download URL | safety_agent-0.1.7.tar.gz |
|---|---|
| Size | 161.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0e2e0b897c65ade2e265e1fd7eae5eb3d58c167f1322d9e7998f2157b1f2a9fc
|
|
BLAKE2b-256 checksum How to use checksums |
9603b4199eece1c76d43d743851f77519d46d5fc5a65f76d8f1c92005cb70e61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / safety_agent-0.1.7-py3-none-any.whl
| Download URL | safety_agent-0.1.7-py3-none-any.whl |
|---|---|
| Size | 48.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d570443a2175b20ca3c9ac65a7c5abc3e4a6bf1e2d5be4b879e1252a32b263e5
|
|
BLAKE2b-256 checksum How to use checksums |
762c073bf978963fb0da049fe0cb5eba0b508e38b04d5e510efb98fc70b7ba71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|