Skip to main content

Shrike Security SDK - Protect your LLM applications (OpenAI, Claude, Gemini) from prompt injection, PII leakage, and jailbreaks

Project description

Shrike Guard — Python SDK

Public repo: https://github.com/Shrike-Security/shrike-guard-python

This directory is mirrored from the public repository. For the latest version, issues, and contributions, please use the public repo.

PyPI version Python 3.8+ License: Apache 2.0

Shrike Guard is a Python SDK that provides security protection for your LLM applications. It wraps the OpenAI Python client to automatically scan all prompts for security threats before they reach the LLM.

Features

  • Drop-in replacement for the OpenAI Python client
  • Automatic prompt scanning for:
    • Prompt injection attacks
    • PII/sensitive data leakage
    • Jailbreak attempts
    • Malicious instructions
  • Fail-safe modes: Choose between fail-open (default) or fail-closed behavior
  • Async support: Works with both sync and async OpenAI clients
  • Zero code changes: Just replace your import

Installation

pip install shrike-guard

Quick Start

Synchronous Usage

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)

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-open (default): Allow requests if scan fails
# Best for: Most applications where availability is important
client = ShrikeOpenAI(
    api_key="sk-...",
    shrike_api_key="shrike-...",
    fail_mode="open",  # This is the default
)

# Fail-closed: Block requests if scan fails
# Best for: Security-critical applications
client = ShrikeOpenAI(
    api_key="sk-...",
    shrike_api_key="shrike-...",
    fail_mode="closed",
)

Timeout Configuration

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

Custom Endpoint

For enterprise customers with a dedicated Shrike deployment (VPC or single-tenant):

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

Dedicated endpoints are provisioned by Shrike during enterprise onboarding. Contact sales@shrikesecurity.com for details.

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+
  • OpenAI SDK: 1.0.0+
  • 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 SHRIKE_API_KEY="shrike-..."
export SHRIKE_ENDPOINT="https://your-org.shrike.internal"  # Enterprise/VPC deployments only

Then initialize without explicit arguments:

import os
from shrike_guard import ShrikeOpenAI

client = ShrikeOpenAI(
    shrike_api_key=os.environ.get("SHRIKE_API_KEY"),
)

Scope and Limitations

What Shrike Guard Scans

Scanned ✅ Not Scanned ❌
Input prompts (user messages) Streaming output from LLM
System prompts Non-streaming completions (V2 roadmap)
Multi-modal text content Image/audio content

Why Input-Only Scanning?

V1 Design Decision: 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 95%+ of threats (attacks are in the INPUT)

Output Scanning Roadmap

Output scanning (detecting leaked PII, secrets in responses) is planned for V2. For now:

  • Use Shrike's real-time dashboard to monitor flagged prompts
  • Enable audit logging for compliance review
  • Consider post-processing with ScanClient.scan() for high-sensitivity applications

License

Apache 2.0

Support

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

shrike_guard-1.0.1.tar.gz (21.9 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-1.0.1-py3-none-any.whl (29.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for shrike_guard-1.0.1.tar.gz
Algorithm Hash digest
SHA256 398c4f76b041de73512ccd8b9fbc04d6c62df3bc7cb26ae6feeccf502a9873d1
MD5 3dad07b7d8515a99d9034d34f5d602ea
BLAKE2b-256 3c795a229f681bf4a0cd3626100814365565c94c6bbc1b788e00ae89b3de0c08

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for shrike_guard-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 704959dc4137091184f856fc6fba5f8f14a2967dfff903e025d66eb26ee8f3ec
MD5 aaeb4e467026a50375e736518cfaf979
BLAKE2b-256 388676f22a526fe5d876a28d9f8226aba2b956d4460e488be2fbcdc99694e992

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