Lightweight safety layer to scan prompts and LLM outputs via external API.
Project description
LockPrompt
LockPrompt is a 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 Injection.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lockprompt-1.1.1.tar.gz.
File metadata
- Download URL: lockprompt-1.1.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae3e5606791bea6d1ada93396d7d5b91b57a125d97a673c5c2ab13c83f1dfa79
|
|
| MD5 |
d8f24fd1695fd4516bbca0fbfaa22fb0
|
|
| BLAKE2b-256 |
4477688df1bd9793bc2a2bde15d9cd0b12477f2c474068d99e167b8384c8721f
|
File details
Details for the file lockprompt-1.1.1-py3-none-any.whl.
File metadata
- Download URL: lockprompt-1.1.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b857206fcf1b2ef0f4280af59f71371b85e2f3c39636528888dd770cb615974
|
|
| MD5 |
ad9423c14afdc4aeac786f5f3e989bdd
|
|
| BLAKE2b-256 |
ba177fb916095bedea7e5f6b8fc4b8da862ac5a26f8d24d63d46a3b38024bf8e
|