AI Guard Python SDK
Runtime security for LLM applications. Detects prompt injection, unsafe output, and other AI security threats in real-time.
Quickstart
pip install scan5-ai-guard
from ai_guard import AIGuardSDK, CapturedRequest, CapturedResponse, ModelMetadata
sdk = AIGuardSDK({"enabled": True})
# Scan a request/response pair
findings = await sdk.scan_request_response(
CapturedRequest(
id="req-123",
url="openai:chat.completions.create",
body={"messages": [{"role": "user", "content": "Hello!"}]},
),
CapturedResponse(
status_code=200,
body={"choices": [{"message": {"content": "Hi there!"}}]},
duration_ms=150,
),
ModelMetadata(
name="gpt-4",
provider="openai",
),
)
for finding in findings:
print(f"[{finding.severity}] {finding.message} (confidence={finding.confidence:.2f})")
Provider Wrappers
Automatically scan OpenAI and Anthropic API calls:
import openai
from ai_guard import AIGuardSDK, wrap_openai_client
sdk = AIGuardSDK()
client = openai.OpenAI()
wrapped = wrap_openai_client(client, sdk)
# All chat completions are scanned automatically
response = wrapped.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Tell me a joke"}],
)
import anthropic
from ai_guard import AIGuardSDK, wrap_anthropic_client
sdk = AIGuardSDK()
client = anthropic.Anthropic()
wrapped = wrap_anthropic_client(client, sdk)
response = wrapped.messages.create(
model="claude-3-opus-20240229",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}],
)
Zero-Config Philosophy
The SDK works out of the box with sensible defaults. Configure via environment variables:
| Variable | Purpose |
|---|---|
AI_GUARD_PLATFORM_URL |
Platform API base URL (default: https://scan5.vercel.app) |
AI_GUARD_RUNTIME_INGEST_SIGNING_KEY |
HMAC key for request signing |
AI_GUARD_WORKSPACE_ID |
Workspace UUID |
AI_GUARD_API_KEY |
Bearer token for authentication |
AI_GUARD_USER_ID |
User ID for bypass-token auth |
AI_GUARD_USER_ROLE |
User role for bypass-token auth |
Configuration
sdk = AIGuardSDK({
"enabled": True,
"evaluation_timeout_ms": 100,
"sample_rate_percent": 100,
"capture_payloads": False,
"environment": "production",
"classifier_threshold": 0.85,
"classifier_enabled": True,
"on_finding": lambda finding: print(f"Finding: {finding}"),
"on_error": lambda error: print(f"Error: {error}"),
})
Dashboard
View findings and manage configuration at https://scan5.vercel.app. Findings are transmitted to the dashboard when AI_GUARD_PLATFORM_URL and AI_GUARD_RUNTIME_INGEST_SIGNING_KEY are configured.
API
AIGuardSDK
| Method | Description |
|---|---|
scan_request_response(request, response, model) |
Scan a request/response pair |
scan_stream_chunk(request, text, model) |
Scan streaming response chunks |
wait_for_transmission(timeout_ms=10000) |
Flush findings to dashboard |
get_diagnostics() |
Transmission health check |
dispose() |
Cleanup resources |
set_enabled(bool) |
Enable/disable at runtime |
is_enabled() |
Check if enabled |
get_stats() |
Runtime statistics |
reset_stats() |
Reset statistics |
Development
# Install in editable mode
pip install -e .
# Install with provider extras
pip install -e ".[openai,anthropic]"
# Build distribution packages
pip install build
python -m build
License
MIT
Metadata
Release files for scan5 0.2.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 | Provenance | Actions |
|---|---|---|---|---|
| scan5-0.2.0.tar.gz | 21.5 kB | Without provenance | Details for scan5-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scan5-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for scan5-0.2.0-py3-none-any.whl |
Total release size: 43.6 kB
Release files / scan5-0.2.0.tar.gz
| Download URL | scan5-0.2.0.tar.gz |
|---|---|
| Size | 21.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
88d836964f0605bb0e80bb3b9dfc8e0dff733d65c02d4f6380c6c09241cecc19
|
|
BLAKE2b-256 checksum How to use checksums |
9cc003ce4a14d44962298e8a6c1554f3d19862d224574e1d685783baaea90d9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / scan5-0.2.0-py3-none-any.whl
| Download URL | scan5-0.2.0-py3-none-any.whl |
|---|---|
| Size | 22.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a3559d05bb7dc5e41daa54e653b3efa96d3bfd6bcead7b2df74112665d43370f
|
|
BLAKE2b-256 checksum How to use checksums |
f1f438984aeffcc17e460713116c43b4a70d98648123e07f9712b5bd2d741a4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for scan5 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.