Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 4.0.3 instead.

Shrike Guard

PyPI version Python 3.8+ License: Apache 2.0

Shrike Guard is a Python SDK for the Shrike platform — AI governance for every AI interaction. It wraps OpenAI, Anthropic (Claude), and Google Gemini clients to automatically evaluate all prompts against policy before they reach the LLM. Govern LangChain agents, RAG pipelines, FastAPI chatbots, and any Python AI application with the same 9-layer cognitive pipeline.

Features

  • Drop-in replacement for OpenAI, Anthropic, and Gemini clients
  • Automatic prompt scanning for:
    • Prompt injection attacks
    • PII/sensitive data leakage
    • Jailbreak attempts
    • SQL injection
    • Path traversal
    • Malicious instructions
  • Fail-safe modes: Defaults to fail-closed (Zero Trust posture); opt into fail-open explicitly when availability outranks enforcement
  • Async support: Works with both sync and async clients
  • Zero code changes: Just replace your import

What Shrike Detects

Shrike's 9-layer cognitive pipeline includes sensitive-data detection aligned to 5 major regulatory frameworks:

Framework Coverage
GDPR EU personal data — names, addresses, national IDs
HIPAA Protected health information (PHI)
ISO 27001 Information security — passwords, tokens, certificates
SOC 2 Secrets, credentials, API keys, cloud tokens
NIST AI risk management (IR 8596), cybersecurity framework (CSF 2.0)

Detection coverage is not a certification claim — see shrikesecurity.com/compliance for our current certification status. Plus built-in detection for prompt injection, jailbreaks, social engineering, and dangerous requests.

Tiers

Detection depth depends on your tier. All tiers get the same SDK wrappers — tiers control which backend layers run.

Anonymous Community Pro Enterprise
Detection Layers L1-L5 L1-L7 L1-L9 (full) L1-L9 (full)
API Key Not needed Free signup Paid Paid
Rate Limit 10/min 100/min 1,000/min
Scans/month 1,000 25,000 1,000,000

Anonymous (no API key): Pattern-based detection (L1-L5). Community (free): Adds LLM-powered semantic analysis. Register at shrikesecurity.com/signup — instant, no credit card.

Installation

pip install shrike-guard                      # OpenAI (included by default)
pip install shrike-guard[anthropic]            # + Anthropic Claude
pip install shrike-guard[gemini]               # + Google Gemini
pip install shrike-guard[all]                  # All providers

Quick Start

OpenAI

from shrike_guard import ShrikeOpenAI

# Replace 'from openai import OpenAI' with this
client = ShrikeOpenAI(
    api_key="sk-...",           # Your OpenAI API key
    shrike_api_key="shrike-...", # Your Shrike API key
)

# Use exactly like the regular OpenAI client
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello, how are you?"}]
)

print(response.choices[0].message.content)

Anthropic (Claude)

from shrike_guard import ShrikeAnthropic

client = ShrikeAnthropic(
    api_key="sk-ant-...",
    shrike_api_key="shrike-...",
)

response = client.messages.create(
    model="claude-sonnet-4-5-20250929",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}]
)

print(response.content[0].text)

Google Gemini

from shrike_guard import ShrikeGemini

client = ShrikeGemini(
    api_key="AIza...",
    shrike_api_key="shrike-...",
)

model = client.GenerativeModel("gemini-pro")
response = model.generate_content("Hello!")

print(response.text)

Async Usage

import asyncio
from shrike_guard import ShrikeAsyncOpenAI

async def main():
    client = ShrikeAsyncOpenAI(
        api_key="sk-...",
        shrike_api_key="shrike-...",
    )

    response = await client.chat.completions.create(
        model="gpt-4",
        messages=[{"role": "user", "content": "Hello!"}]
    )

    print(response.choices[0].message.content)
    await client.close()

asyncio.run(main())

Configuration

Fail Modes

Choose how the SDK behaves when the security scan fails (timeout, network error, etc.):

# Fail-closed (default since v2.0.0): Block requests if scan fails
# Best for: Production security workloads. If the Shrike backend is down,
# the SDK raises ShrikeScanError instead of allowing traffic through unguarded.
client = ShrikeOpenAI(
    api_key="sk-...",
    shrike_api_key="shrike-...",
    fail_mode="closed",  # This is the default
)

# Fail-open: Allow requests if scan fails
# Best for: Non-production experiments, internal tools where availability must
# outrank enforcement. Trades the guard's enforcement promise for uptime.
client = ShrikeOpenAI(
    api_key="sk-...",
    shrike_api_key="shrike-...",
    fail_mode="open",
)

Timeout Configuration

client = ShrikeOpenAI(
    api_key="sk-...",
    shrike_api_key="shrike-...",
    scan_timeout=2.0,  # Timeout in seconds (default: 10.0)
)

Custom Endpoint

For self-hosted Shrike deployments:

client = ShrikeOpenAI(
    api_key="sk-...",
    shrike_api_key="shrike-...",
    shrike_endpoint="https://your-shrike-instance.com",
)

SQL and File Scanning

from shrike_guard import ScanClient

with ScanClient(api_key="shrike-...") as scanner:
    # Scan SQL queries for injection attacks
    sql_result = scanner.scan_sql("SELECT * FROM users WHERE id = 1")
    if not sql_result["safe"]:
        print(f"SQL threat: {sql_result['reason']}")

    # Scan file paths for path traversal
    file_result = scanner.scan_file("/app/data/output.csv")

    # Scan file content for secrets/PII
    content_result = scanner.scan_file("/tmp/config.py", "api_key = 'sk-...'")

Error Handling

from shrike_guard import ShrikeOpenAI, ShrikeBlockedError, ShrikeScanError

client = ShrikeOpenAI(
    api_key="sk-...",
    shrike_api_key="shrike-...",
    fail_mode="closed",  # To see scan errors
)

try:
    response = client.chat.completions.create(
        model="gpt-4",
        messages=[{"role": "user", "content": "Some prompt..."}]
    )
except ShrikeBlockedError as e:
    # Prompt was blocked due to security threat
    print(f"Blocked: {e.message}")
    print(f"Threat type: {e.threat_type}")
    print(f"Confidence: {e.confidence}")
except ShrikeScanError as e:
    # Scan failed (only raised with fail_mode="closed")
    print(f"Scan error: {e.message}")

Low-Level Scan Client

For more control, use the scan client directly:

from shrike_guard import ScanClient

with ScanClient(api_key="shrike-...") as scanner:
    result = scanner.scan("Check this prompt for threats")

    if result["safe"]:
        print("Prompt is safe!")
    else:
        print(f"Threat detected: {result['reason']}")

Compatibility

  • Python: 3.8+
  • LLM SDKs:
    • OpenAI SDK >=1.0.0
    • Anthropic SDK >=0.18.0 (optional: pip install shrike-guard[anthropic])
    • Google Generative AI >=0.3.0 (optional: pip install shrike-guard[gemini])
  • Works with:
    • OpenAI API
    • Azure OpenAI
    • OpenAI-compatible APIs (Ollama, vLLM, etc.)

Environment Variables

You can configure the SDK using environment variables:

export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
export SHRIKE_API_KEY="shrike-..."
export SHRIKE_ENDPOINT="https://your-shrike-instance.com"

Scope and Limitations

Scanned Not Scanned
Input prompts (user messages) Streaming output from LLM
System prompts Image/audio content
Multi-modal text content Non-chat API calls
SQL queries
File paths and content

Why Input-Only Scanning?

Shrike Guard focuses on pre-flight protection — blocking malicious prompts BEFORE they reach the LLM. This:

  • Prevents prompt injection attacks at the source
  • Has zero latency impact on LLM responses
  • Catches the vast majority of threats at the input layer

Other Integration Surfaces

Shrike Guard is one of several ways to integrate with the Shrike platform:

  • MCP Servernpx shrike-mcp (GitHub)
  • TypeScript SDKnpm install shrike-guard (GitHub)
  • REST APIPOST https://api.shrikesecurity.com/agent/scan
  • LLM Gateway — Change one URL, scan everything
  • Browser Extension — Chrome/Edge for ChatGPT, Claude, Gemini
  • Dashboardshrikesecurity.com

Use Cases

Scenario How Shrike Guard Helps
LangChain / CrewAI agents Wrap your LLM client. Every agent action scanned before execution.
RAG pipelines Scan retrieved context + user queries for PII leakage and injection.
FastAPI chatbot Middleware-style integration. Scan every request before it hits the model.
Internal AI tools Protect Slack bots, email assistants, and internal AI applications.

Alternatives

Looking for a Python AI security SDK? Here's how Shrike Guard compares:

Feature Shrike Guard Lakera Prompt Armor
Drop-in OpenAI/Anthropic/Gemini wrapper Yes No No
9-layer cognitive pipeline Yes Limited Limited
PII detection + redaction Yes Partial No
Async support Yes Partial No
Free tier (no API key) Yes No No
Open source client Yes (Apache 2.0) No No

License

Apache 2.0

Support

Download files

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

Source Distribution

shrike_guard-4.0.1.tar.gz (46.7 kB view details)

Uploaded Source

Built Distribution

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

shrike_guard-4.0.1-py3-none-any.whl (56.1 kB view details)

Uploaded Python 3

File details

Details for the file shrike_guard-4.0.1.tar.gz.

File metadata

  • Download URL: shrike_guard-4.0.1.tar.gz
  • Upload date:
  • Size: 46.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for shrike_guard-4.0.1.tar.gz
Algorithm Hash digest
SHA256 331e5710c4e879172069a40df36d0a238089a8423d4fbd9507236a5489da98a1
MD5 823bfb3df3294e1df287251477c52e3a
BLAKE2b-256 069a827ba46a3895b5f8a4edac2844db63d7cad90a29a9483ba2b636e255d9f9

See more details on using hashes here.

File details

Details for the file shrike_guard-4.0.1-py3-none-any.whl.

File metadata

  • Download URL: shrike_guard-4.0.1-py3-none-any.whl
  • Upload date:
  • Size: 56.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for shrike_guard-4.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3f248794f30e50380cc7ce69431801cbcdf83e541284e6ddfbedb88d07f4a094
MD5 708043968dc3f4f296b85c86c6c127a7
BLAKE2b-256 e320dd95de6ac1e234f7ac955e74bb11a6404202d18d99dbcd3824f76513c7fb

See more details on using hashes here.

Release history Release notifications | RSS feed

4.0.3

2 files

4.0.2

2 files

This release

4.0.1 This release

2 files

4.0.0

2 files

1.1.2

2 files

1.0.1

2 files

1.0.0

2 files

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