Skip to main content

shadow-warden-sdk

Python SDK for the Shadow Warden AI security gateway.

Install

pip install shadow-warden-sdk

Quick start

from shadow_warden import WardenClient

with WardenClient(gateway_url="http://localhost:8001", api_key="sk_...") as warden:
    result = warden.filter("Summarise the contract for client@example.com")
    if result.allowed:
        # safe to forward to your AI model
        ...
    else:
        print("Blocked:", result.risk_level, result.flag_names)

OpenAI wrapper (drop-in)

import openai
from shadow_warden import WardenClient

warden = WardenClient(api_key="sk_warden_...")
client = warden.wrap_openai(openai.OpenAI(api_key="sk-openai-..."))

# Identical to the standard OpenAI API — Warden intercepts transparently
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "..."}],
    raise_on_block=True,    # raises WardenBlockedError if blocked
)

Async

from shadow_warden import AsyncWardenClient

async with AsyncWardenClient(gateway_url="...", api_key="...") as warden:
    result = await warden.filter("user prompt")

Batch filtering

results = warden.filter_batch([
    "What is the capital of France?",
    {"content": "My SSN is 123-45-6789", "strict": True},
])

Fail-open mode

# If the gateway is unreachable, return a permissive result instead of raising
warden = WardenClient(fail_open=True)

Configuration

Parameter Default Description
gateway_url http://localhost:8001 Warden gateway base URL
api_key "" X-API-Key header value
tenant_id "default" Default tenant for all requests
timeout 10.0 HTTP timeout in seconds
fail_open False Return permissive result on network errors

Error handling

from shadow_warden import WardenBlockedError, WardenGatewayError, WardenTimeoutError

try:
    result = warden.filter(content, raise_on_block=True)
except WardenBlockedError as e:
    print("Blocked:", e.result.risk_level)
except WardenTimeoutError:
    print("Gateway timeout")
except WardenGatewayError as e:
    print(f"HTTP {e.status_code}: {e.detail}")

FilterResult fields

Field Type Description
allowed bool Whether the content passed all filters
blocked bool Convenience inverse of allowed
risk_level str low / medium / high / block
filtered_content str Content after PII redaction
secrets_found list[SecretFinding] Detected secrets/PII
semantic_flags list[SemanticFlag] Triggered semantic rules
flag_names list[str] Shorthand for flag names
has_secrets bool True if any secrets were found
has_pii bool True if pii_detected flag is present
processing_ms dict[str, float] Per-stage timing breakdown

Agentic commerce

ShadowWardenClient carries the mandate, order, spend and MCP-intent calls, and SecureAgent is the mixin that gives any agent class mandate-controlled purchasing:

from shadow_warden import SecureAgent

class ProcurementAgent(SecureAgent):
    def run(self, task: str):
        if self.filter_prompt(task).get("blocked"):
            raise ValueError("task blocked")
        self.create_mandate(max_amount=200.0)
        return self.purchase({"store_url": "shop.example.com", "items": [...]})

OpenTelemetry

pip install "shadow-warden-sdk[otel]" adds WardenSpanProcessor, which filters span attributes through the gateway before they are exported.

Metadata

Release files for shadow-warden-sdk 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shadow-warden-sdk 1.0.0
File Size Uploaded Provenance Actions
shadow_warden_sdk-1.0.0.tar.gz 14.7 kB Without provenance Details for shadow_warden_sdk-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shadow-warden-sdk 1.0.0
File Interpreter ABI Platform Actions
shadow_warden_sdk-1.0.0-py3-none-any.whl Python 3 none any Details for shadow_warden_sdk-1.0.0-py3-none-any.whl

Total release size: 28.7 kB

Release files / shadow_warden_sdk-1.0.0.tar.gz

Download URL shadow_warden_sdk-1.0.0.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
09f04b4630e5ea6c634e040752a83608fd21d9d4f9a63c46016d332df2fe5c66
BLAKE2b-256 checksum
How to use checksums
1ab24d62295ccdbc847b2740d0dc2061c30e31aae1ae3f1c7de0c76492eb1ec9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / shadow_warden_sdk-1.0.0-py3-none-any.whl

Download URL shadow_warden_sdk-1.0.0-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1dfe9dfaffe6bc77529b79360cd75bdd83ddfece06bc01200c05c2620a87cf5
BLAKE2b-256 checksum
How to use checksums
09c2eb8308589125b9986319b1a40d63bf57cce3fb1a295b4d4eebb869cc9e3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Security for shadow-warden-sdk 1.0.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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page