Skip to main content

Prompt injection protection for AI applications

Project description

SafePrompt Python SDK

Protect your AI application from prompt injection attacks with one function call.

PyPI version Python versions

Install

pip install safeprompt

Quick Start

from safeprompt import SafePrompt

sp = SafePrompt(api_key="YOUR_API_KEY")

result = sp.check(user_input, user_ip=request.remote_addr)
if not result["safe"]:
    raise ValueError(f"Blocked: {result['threats'][0]}")

Async Support

from safeprompt import AsyncSafePrompt

async with AsyncSafePrompt(api_key="YOUR_API_KEY") as sp:
    result = await sp.check(user_input)
    if not result["safe"]:
        raise ValueError(f"Blocked: {result['threats'][0]}")

Response Format

{
    "safe": True,
    "threats": [],
    "confidence": 0.99,
    "processingTimeMs": 45,
    "passesUsed": 1
}

Error Handling

from safeprompt import SafePromptError

try:
    result = sp.check(user_input)
except SafePromptError as e:
    print(e.status_code)
    print(str(e))

Links

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

safeprompt-1.4.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

safeprompt-1.4.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file safeprompt-1.4.0.tar.gz.

File metadata

  • Download URL: safeprompt-1.4.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for safeprompt-1.4.0.tar.gz
Algorithm Hash digest
SHA256 1d4c21d4a0a6ce05f19dc4c2e1df0a699ffdb4c1611858431aa4145ce2c7dd83
MD5 49ad25c12b7a1451869dcd40e556ff52
BLAKE2b-256 26c0e2bd7a3b7a71cddc98d3249c5e0c8e62d2a3cb051c5eb47daa7441182c20

See more details on using hashes here.

Provenance

The following attestation bundles were made for safeprompt-1.4.0.tar.gz:

Publisher: publish-pypi.yml on ianreboot/safeprompt

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

File details

Details for the file safeprompt-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: safeprompt-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for safeprompt-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9aff037f21d42b39ff70db0890b99f26640169b7c6f96a99eb5c702a3423702d
MD5 0044dd14de34b8e1f1e5654998d84895
BLAKE2b-256 2b8e2acfc0e03e463f0e30e075c746c126394d7d455e4ae6c43c0d73db80084a

See more details on using hashes here.

Provenance

The following attestation bundles were made for safeprompt-1.4.0-py3-none-any.whl:

Publisher: publish-pypi.yml on ianreboot/safeprompt

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