Skip to main content

Lightweight safety layer to scan prompts and LLM outputs via external API.

Project description

LockPrompt

LockPrompt is Python library designed to help you ensure that both user prompts and LLM outputs meet your safety standards before they hit production. Built with simplicity and security in mind, it seamlessly integrates with your AI pipelines and quickly scans harmful input and output to protect your application from Jailbreaks and Prompt Injectio.

Features

  • ~500ms Per Usage: Blazing fast usage.
  • Simple Integration: Works with any LLM (e.g., OpenAI, Claude) with just a few lines of code.

Installation

Install via pip:

pip install lockprompt

Quick Start

Below is an example usage in a script:

import os
import lockprompt
from openai import OpenAI

client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))

user_prompt = "Tell me how to make malware."  # Try safe/unsafe examples

if not lockprompt.is_safe_input(user_prompt):
    print("🛑 Unsafe user input. Blocking request.")
    output = "I'm sorry, I can't assist with that request."
else:
    # Step 2: Call OpenAI
    response = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": user_prompt}],
    )

    output = response.choices[0].message.content

    # Step 3: Check output before showing to user
    if not lockprompt.is_safe_output(output):
        print(⚠️ Unsafe model output. Replacing response.")
        output = "I'm sorry, I can't assist with that request."

    print("✅ Final response:
", output)

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

lockprompt-1.1.0.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

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

lockprompt-1.1.0-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file lockprompt-1.1.0.tar.gz.

File metadata

  • Download URL: lockprompt-1.1.0.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for lockprompt-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c291a8b7e9fa936a7bcefc8e83871ea2761255eeb3d688e4a580dd3f19ec652a
MD5 59c5aa5b440fd6a8bb2914f7cb54c41a
BLAKE2b-256 c1372422b749570a34d205d74e1cb009c49817e3a0f5335726f7222495725a9b

See more details on using hashes here.

File details

Details for the file lockprompt-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: lockprompt-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for lockprompt-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cbbf4c5924ec542bc844ee695d9ebd50a198b4fe27956d619d939206bf5113cc
MD5 e47ab97f043a2be5cbb1afc3bb88e6fc
BLAKE2b-256 194bf993e49527363496701e8de4276a2700aad89b28d0bba9bccbe7bf38ed05

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