Skip to main content

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

safety_agent-0.1.7.tar.gz (161.8 kB view details)

Uploaded Source

Built Distribution

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

safety_agent-0.1.7-py3-none-any.whl (48.9 kB view details)

Uploaded Python 3

File details

Details for the file safety_agent-0.1.7.tar.gz.

File metadata

  • Download URL: safety_agent-0.1.7.tar.gz
  • Upload date:
  • Size: 161.8 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for safety_agent-0.1.7.tar.gz
Algorithm Hash digest
SHA256 0e2e0b897c65ade2e265e1fd7eae5eb3d58c167f1322d9e7998f2157b1f2a9fc
MD5 ee6d02d5eaf447c66526d7c22740a0de
BLAKE2b-256 9603b4199eece1c76d43d743851f77519d46d5fc5a65f76d8f1c92005cb70e61

See more details on using hashes here.

File details

Details for the file safety_agent-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: safety_agent-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 48.9 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for safety_agent-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 d570443a2175b20ca3c9ac65a7c5abc3e4a6bf1e2d5be4b879e1252a32b263e5
MD5 0112368b0e7702aa4e3a297a20aec7df
BLAKE2b-256 762c073bf978963fb0da049fe0cb5eba0b508e38b04d5e510efb98fc70b7ba71

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page