Metadata-Version: 2.4
Name: scan5
Version: 0.2.0
Summary: 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.
Home-page: https://github.com/wangai003/scan5
Author: scan5
License: MIT
Project-URL: Homepage, https://github.com/wangai003/scan5
Project-URL: Bug Tracker, https://github.com/wangai003/scan5/issues
Project-URL: Dashboard, https://scan5.vercel.app
Keywords: ai,security,llm,prompt-injection,runtime-security,sast,enforcement,openai,anthropic
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Provides-Extra: openai
Requires-Dist: openai>=1.0.0; extra == "openai"
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.30.0; extra == "anthropic"
Dynamic: home-page
Dynamic: requires-python

# AI Guard Python SDK

Runtime security for LLM applications. Detects prompt injection, unsafe output, and other AI security threats in real-time.

## Quickstart

```bash
pip install scan5-ai-guard
```

```python
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:

```python
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"}],
)
```

```python
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

```python
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](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

```bash
# 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
