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]"

Memory (Context Management)

# Store user preferences
pg.memory.store(
    content="User prefers Python for coding tasks",
    memory_type="preference",
    user_id="user-123"
)

# Retrieve relevant context
memories = pg.memory.retrieve(
    query="What programming language should I use?",
    user_id="user-123"
)

# Inject into your prompts
context = memories["formatted_context"]

Async Support

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-0.1.1.tar.gz (6.7 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-0.1.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for promptguard_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 be5a109e62332722aecebc3c0a6dd9dcf579e8634730da73ffd5583bb666526d
MD5 a0730ea69aefe51fb3126a74bf3f63cf
BLAKE2b-256 781fe63ade343b79362404d975f5b49b322d37271e570e48494dc57952f851b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptguard_sdk-0.1.1.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-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for promptguard_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 34694d21fec47040344a68ea8d512f05f99e770788db1b2139d97f517df4f97f
MD5 522a4456fc7d2a6102d24e17f6f43def
BLAKE2b-256 a8743f8bff66fab11e8000a03bc535ff51456efa3362e358e587e54af6912c38

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptguard_sdk-0.1.1-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