Skip to main content

Drop-in security for AI applications - AI Firewall SDK

Project description

PromptGuard Python SDK

Drop-in security for AI applications. No code changes required.

Installation

pip install promptguard-sdk

Quick Start

from promptguard import PromptGuard

# Initialize client
pg = PromptGuard(api_key="pg_xxx")

# Use exactly like OpenAI client
response = pg.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}]
)

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

Drop-in Replacement

If you're already using OpenAI's Python client, just change the import:

# Before
from openai import OpenAI
client = OpenAI()

# After
from promptguard import PromptGuard
client = PromptGuard(api_key="pg_xxx")

# Your existing code works unchanged!

Features

Security Scanning

# Scan content for threats
result = pg.security.scan("Ignore previous instructions...")

if result["blocked"]:
    print(f"Threat detected: {result['reason']}")

PII Redaction

# Redact PII before sending to LLM
result = pg.security.redact(
    "My email is john@example.com and SSN is 123-45-6789"
)

print(result["redacted_content"])
# Output: "My email is [EMAIL] and SSN is [SSN]"

context = memories["formatted_context"]


## Async Support

```python
from promptguard import PromptGuardAsync

async with PromptGuardAsync(api_key="pg_xxx") as pg:
    response = await pg.chat.completions.create(
        model="gpt-4",
        messages=[{"role": "user", "content": "Hello!"}]
    )

Configuration

from promptguard import PromptGuard, Config

config = Config(
    api_key="pg_xxx",
    base_url="https://api.promptguard.co/api/v1/proxy",
    enable_caching=True,
    enable_security_scan=True,
    timeout=30.0,
)

pg = PromptGuard(config=config)

Environment Variables

export PROMPTGUARD_API_KEY="pg_xxx"
export PROMPTGUARD_BASE_URL="https://api.promptguard.co/api/v1/proxy"

Then just:

from promptguard import PromptGuard

pg = PromptGuard()  # Uses env vars automatically

Error Handling

from promptguard import PromptGuard, PromptGuardError

try:
    response = pg.chat.completions.create(...)
except PromptGuardError as e:
    if e.code == "BLOCKED":
        print(f"Request blocked: {e.message}")
    elif e.code == "RATE_LIMITED":
        print("Rate limited, try again later")
    else:
        raise

License

MIT

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

promptguard_sdk-1.2.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

promptguard_sdk-1.2.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file promptguard_sdk-1.2.0.tar.gz.

File metadata

  • Download URL: promptguard_sdk-1.2.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for promptguard_sdk-1.2.0.tar.gz
Algorithm Hash digest
SHA256 0cdf9bee7fbd776d1fb50c462615f0d40548b09c570f43400c4513309b74e605
MD5 c8687c262494f9c351b6fee7c5402a68
BLAKE2b-256 67c5fc4e99df33ff25a6e8992e232331ff3aa0cb437b9766ddc409cd31091b97

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptguard_sdk-1.2.0.tar.gz:

Publisher: publish-sdks.yml on acebot712/promptguard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file promptguard_sdk-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for promptguard_sdk-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4efd732a1d88e90c03a38b5c949f8a3e62cdf656e26ffde0fb735ccfa6fd1e17
MD5 5f981fc2fa7af342b8455d6e525fc10e
BLAKE2b-256 2b88bdcccc16f56c63dc4d2911ca123ca9ee228f94cb9431a452349e04f42e3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptguard_sdk-1.2.0-py3-none-any.whl:

Publisher: publish-sdks.yml on acebot712/promptguard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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