Skip to main content

AI security scanner and runtime enforcement for LLM applications — detects prompt injection, API key leaks, unsafe output, RAG poisoning, and agent hijacking in code and live traffic.

Project description

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

Project details


Download files

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

Source Distribution

scan5-0.2.0.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

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

scan5-0.2.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file scan5-0.2.0.tar.gz.

File metadata

  • Download URL: scan5-0.2.0.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for scan5-0.2.0.tar.gz
Algorithm Hash digest
SHA256 88d836964f0605bb0e80bb3b9dfc8e0dff733d65c02d4f6380c6c09241cecc19
MD5 1e37b0c18b628bce1fb85493d0a25c21
BLAKE2b-256 9cc003ce4a14d44962298e8a6c1554f3d19862d224574e1d685783baaea90d9f

See more details on using hashes here.

File details

Details for the file scan5-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: scan5-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for scan5-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3559d05bb7dc5e41daa54e653b3efa96d3bfd6bcead7b2df74112665d43370f
MD5 7a0b9e5a30969e612548a3f40f0abb60
BLAKE2b-256 f1f438984aeffcc17e460713116c43b4a70d98648123e07f9712b5bd2d741a4c

See more details on using hashes here.

Supported by

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