Skip to main content

Shrike Guard

PyPI version Python 3.10+ 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-L5 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): Same L1-L5 detection with a dashboard and higher limits; LLM-powered semantic analysis (L6-L9) is Pro+. 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 (the default across the 4.x line): 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.10+
  • 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 Server — npx shrike-mcp (GitHub)
  • TypeScript SDK — npm install shrike-guard (GitHub)
  • REST API — POST https://api.shrikesecurity.com/agent/scan
  • LLM Gateway — Change one URL, scan everything
  • Browser Extension — Chrome/Edge for ChatGPT, Claude, Gemini
  • Dashboard — shrikesecurity.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

Metadata

Release files for shrike-guard 4.0.4

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

Source distribution (sdist)

Source distribution for shrike-guard 4.0.4
File Size Uploaded
shrike_guard-4.0.4.tar.gz 51.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shrike-guard 4.0.4
File Interpreter ABI Platform
shrike_guard-4.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 108.8 kB

Release files / shrike_guard-4.0.4.tar.gz

Download URL shrike_guard-4.0.4.tar.gz
Size 51.3 kB
Tags Source
SHA-256 checksum
How to use checksums
57aacdd441fe9d0059b7558c1a49989b9bdc41f5af6014749618c0aa0dc87bf7
BLAKE2b-256 checksum
How to use checksums
f2f60e5381e734b47a26ee0c514cb4f8bf2214ef3ebe224b7d128130f86305e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.4 CPython/3.12.14 Linux/6.17.0-1022-azure

Release files / shrike_guard-4.0.4-py3-none-any.whl

Download URL shrike_guard-4.0.4-py3-none-any.whl
Size 57.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b8333f117dc439c0d2cca6f8b2184da3bfb939cc7e571251f2619947adbab03
BLAKE2b-256 checksum
How to use checksums
b66b8f6ef64fafdac71d5ac808623a0033d298baa039d11868296d0d2a546465
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.4 CPython/3.12.14 Linux/6.17.0-1022-azure

Release history Release notifications | RSS feed

4.3.0

2 release files

4.2.0

2 release files

4.1.0

2 release files

4.0.5

2 release files

This release

4.0.4 This release

2 release files

4.0.3

2 release files

4.0.2

2 release files

4.0.0

2 release 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