LaunchPromptly Python SDK — LLM privacy & security toolkit
Project description
launchpromptly
Official Python SDK for LaunchPromptly — runtime safety layer for LLM applications. PII redaction, prompt injection detection, cost guards, and content filtering with zero core dependencies.
Install
pip install launchpromptly
For ML-enhanced detection (NER-based PII, semantic injection analysis):
pip install launchpromptly[ml]
Quick Start
from launchpromptly import LaunchPromptly
from openai import OpenAI
lp = LaunchPromptly(
api_key="lp_live_...",
security={
"pii": {"enabled": True, "redaction": "placeholder"},
"injection": {"enabled": True, "block_on_high_risk": True},
"cost_guard": {"max_cost_per_request": 0.50},
},
)
# Wrap your OpenAI client — all security features activate automatically
openai = lp.wrap(OpenAI())
response = openai.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": user_input}],
)
# If user_input contains "john@acme.com", the LLM receives "[EMAIL_1]"
# The response is de-redacted before being returned to your code
await lp.flush() # On server shutdown
Features
- PII Redaction — 16 built-in regex detectors (email, phone, SSN, credit card, IP, etc.) with pluggable ML providers
- Prompt Injection Detection — Rule-based scoring across 5 attack categories with configurable thresholds
- Cost Guards — Per-request, per-minute, per-hour, per-day, and per-customer budget limits
- Content Filtering — Block or warn on hate speech, violence, self-harm, and custom patterns
- Model Policy — Restrict which models, providers, and parameters are allowed
- Output Schema Validation — Validate LLM responses against JSON schemas
- Streaming Guards — Mid-stream PII scanning, injection detection, and response length limits
- Multi-Provider — Wrap OpenAI, Anthropic (
wrap_anthropic), and Google Gemini (wrap_gemini) clients - Context Propagation —
with lp.context(trace_id=...)propagates context viacontextvars - Singleton Pattern —
LaunchPromptly.init()/LaunchPromptly.shared()for app-wide usage - Zero Dependencies — No runtime dependencies for core features
- Event Dashboard — Enriched security events sent to your LaunchPromptly dashboard
Security Pipeline
On every LLM call, the SDK runs these checks in order:
- Cost guard (estimate cost, check budgets)
- PII scan & redact (replace PII with placeholders)
- Injection detection (score risk, warn/block)
- Content filter (check input policy violations)
- LLM API Call (with redacted content)
- Response PII scan (defense-in-depth)
- Response content filter
- Output schema validation
- De-redact response (restore original values)
- Send enriched event to dashboard
API
LaunchPromptly(api_key, endpoint, ...)
| Parameter | Default | Description |
|---|---|---|
api_key |
LAUNCHPROMPTLY_API_KEY env |
Your LaunchPromptly API key |
endpoint |
https://launchpromptly-api-950530830180.us-west1.run.app |
API base URL |
flush_at |
10 |
Batch size threshold for auto-flush |
flush_interval |
5.0 |
Timer interval for auto-flush (seconds) |
on |
— | Guardrail event handlers |
lp.wrap(client, options?) / lp.wrap_anthropic(client) / lp.wrap_gemini(client)
Wrap an LLM client with security guardrails.
from launchpromptly.types import WrapOptions, SecurityOptions
wrapped = lp.wrap(OpenAI(), WrapOptions(
feature="chat",
security=SecurityOptions(
pii={"enabled": True, "redaction": "placeholder"},
injection={"enabled": True, "block_on_high_risk": True},
cost_guard={"max_cost_per_request": 1.00},
content_filter={"enabled": True, "categories": ["hate_speech", "violence"]},
model_policy={"allowed_models": ["gpt-4o", "gpt-4o-mini"]},
stream_guard={"pii_scan": True, "on_violation": "abort"},
output_schema={"schema": my_json_schema, "strict": True},
),
))
PII Redaction
{
"pii": {
"enabled": True,
"redaction": "placeholder", # "placeholder" | "mask" | "hash" | "none"
"types": ["email", "phone", "ssn", "credit_card", "ip_address"],
"scan_response": True,
"on_detect": lambda detections: print(f"Found {len(detections)} PII entities"),
}
}
Built-in PII types: email, phone, ssn, credit_card, ip_address, iban, drivers_license, uk_nino, nhs_number, passport, aadhaar, eu_phone, us_address, api_key, date_of_birth, medicare
Injection Detection
{
"injection": {
"enabled": True,
"block_threshold": 0.7, # 0-1 risk score
"block_on_high_risk": True, # raise PromptInjectionError
"on_detect": lambda analysis: print(f"Risk: {analysis.risk_score}"),
}
}
Cost Guards
{
"cost_guard": {
"max_cost_per_request": 1.00,
"max_cost_per_minute": 10.00,
"max_cost_per_hour": 50.00,
"max_cost_per_day": 200.00,
"max_cost_per_customer": 5.00,
"max_tokens_per_request": 100000,
"block_on_exceed": True,
}
}
Context Propagation
with lp.context(trace_id="req-123", customer_id="user-42"):
# All SDK calls inside inherit the context
result = await wrapped.chat.completions.create(...)
Singleton Pattern
# Initialize once at app startup
LaunchPromptly.init(api_key="lp_live_...")
# Access anywhere
lp = LaunchPromptly.shared()
await lp.flush() / await lp.shutdown() / lp.destroy()
flush()— send all pending eventsshutdown()— flush then destroy (for graceful server shutdown)destroy()— stop timers and release resources
Error Handling
from launchpromptly import (
PromptInjectionError,
CostLimitError,
ContentViolationError,
ModelPolicyError,
OutputSchemaError,
StreamAbortError,
)
try:
res = await wrapped.chat.completions.create(...)
except PromptInjectionError as e:
print(f"Injection blocked: risk={e.analysis.risk_score}")
except CostLimitError as e:
print(f"Budget exceeded: {e.violation.violation_type}")
except ContentViolationError as e:
print(f"Content violation: {e.violations}")
Guardrail Events
lp = LaunchPromptly(
api_key="lp_live_...",
on={
"pii.detected": lambda e: log("PII found", e.data),
"injection.blocked": lambda e: alert("Injection blocked", e.data),
"cost.exceeded": lambda e: alert("Budget exceeded", e.data),
},
)
Event types: pii.detected, pii.redacted, injection.detected, injection.blocked, cost.exceeded, content.violated, schema.invalid, model.blocked
Environment Variables
| Variable | Description |
|---|---|
LAUNCHPROMPTLY_API_KEY |
API key (alternative to passing in constructor) |
LP_API_KEY |
Shorthand alias |
License
MIT
Project details
Release history Release notifications | RSS feed
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 launchpromptly-0.1.1.tar.gz.
File metadata
- Download URL: launchpromptly-0.1.1.tar.gz
- Upload date:
- Size: 80.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fd38e6002cdef05f239e757087400008d9b2abf924c3ef3eddf7385fc797bb9
|
|
| MD5 |
30bcfcefa8190d9224cd5b5a68fabd41
|
|
| BLAKE2b-256 |
d4431adeb9c92023fe95aeb532e6ea97a2197361612fec5bca7f8eff5e207be5
|
File details
Details for the file launchpromptly-0.1.1-py3-none-any.whl.
File metadata
- Download URL: launchpromptly-0.1.1-py3-none-any.whl
- Upload date:
- Size: 61.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ada6cc03b8c603f6d80bd5d45d69c5bf00329d0c4dde94907f7c675b10ee06c8
|
|
| MD5 |
cee8052a97cf9ca9af7f9660f170ded2
|
|
| BLAKE2b-256 |
3cc331d8d3c98f09ced0e1dc89de161b02abdd9fd1ac6df756ae86fa1087cf61
|