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-1.1.16.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-1.1.16-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: promptguard_sdk-1.1.16.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-1.1.16.tar.gz
Algorithm Hash digest
SHA256 ad87c0813fd8a70351a169102d7a4663b4cc9e7905000599925b5cb12cf21de1
MD5 4042e5edbdc7744670caabd780625311
BLAKE2b-256 875aeb1578b40cda72a7a1b9d8906a9043df09902279e8767f4e68e84ba4c80a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for promptguard_sdk-1.1.16-py3-none-any.whl
Algorithm Hash digest
SHA256 362a16a2daf99c40e6cfcb5d28b0b3e9a202e8f5c359f7a3d9eebc9ba239dffa
MD5 8c06c22b422cfc57c96e4c794c9fc729
BLAKE2b-256 e65fe0af2d10750ed69f69399aa1ddcfd5182dddc9c4fd9bb7764a6258e2a50b

See more details on using hashes here.

Provenance

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