🆚 Compare Mode🛡️ With Prompt Security vs ⚡ Raw LLM
🛡️ With Prompt Security
⚡ Without Prompt Security (raw LLM)
📎
Estimated prompt tokens: 0
Prompt Security Integration Code
Two ways to protect your AI app with Prompt Security. Both achieve the same security outcome — the difference is where the logic lives. API Mode gives full visibility into every scan result. Gateway Mode is one URL change.
API Mode — explicit scans (~15 lines)
from prompt_security import Client
ps = Client(
base_url="https://apsouth.prompt.security",
app_id=PS_APP_ID
)
# Before calling the LLM:
result = ps.protect_prompt(user_prompt=user_msg)
if not result.allowed:
return "Blocked"
# <your LLM call here>
# After the LLM responds:
resp = ps.protect_response(response_text=llm_reply)
return resp.modified_text or llm_reply
Gateway Mode — one URL change
# Before (direct OpenAI):
client = OpenAI(
api_key=OPENAI_API_KEY
)
# After (via Prompt Security Gateway):
client = OpenAI(
base_url="https://apsouth.prompt.security/v1",
api_key=OPENROUTER_API_KEY,
default_headers={"ps-app-id": PS_APP_ID}
)
# Your LLM call is UNCHANGED:
reply = client.chat.completions.create(
model="openai/gpt-4o-mini",
messages=messages
)
API Mode makes two explicit calls to the PS scan API — once before the LLM (prompt scan) and once after (response scan). You receive full violation details: category, risk score, and whether the text was modified or blocked.
Scan the prompt before calling the LLM
import httpx, os
PS_BASE = os.getenv("PS_BASE_URL") # https://apsouth.prompt.security
PS_APP_ID = os.getenv("PS_APP_ID")
async def protect_prompt(user_msg: str) -> str | None:
async with httpx.AsyncClient() as client:
r = await client.post(
f"{PS_BASE}/api/protect/prompt",
headers={"APP-ID": PS_APP_ID},
json={"prompt": user_msg}
)
data = r.json()
action = data["result"]["prompt"]["action"] # pass | modify | block
if action == "block":
return None # blocked
if action == "modify":
return data["result"]["prompt"]["modified_text"]
return user_msg
Scan the response before returning to user
async def protect_response(reply: str, original_prompt: str) -> str | None:
async with httpx.AsyncClient() as client:
r = await client.post(
f"{PS_BASE}/api/protect/response",
headers={"APP-ID": PS_APP_ID},
json={"response": reply, "prompt": original_prompt}
)
data = r.json()
action = data["result"]["response"]["action"]
if action == "block": return None
if action == "modify": return data["result"]["response"]["modified_text"]
return reply
Gateway Mode requires changing exactly one thing: the base_url of your OpenAI-compatible client. The Prompt Security Gateway intercepts every request and response, scans them transparently, and routes to the LLM via OpenRouter. No other code changes needed.
Chatbot→API Gateway→Prompt Security (DMZ)→Org Proxy→3rd Party LLMs+ Prompt Security → 1st Party LLMs (scan)
See Integration Guide →
When implementing Prompt Security, choose between two integration approaches based on your team's development resources and security requirements.
API Integration
POST /api/protect
Direct API calls to inspect prompts and responses. Each LLM interaction requires separate calls — one for the prompt, one for the response.
✓ Greater flexibility & control over security
✓ Different code areas can call API differently
✓ Parallel execution in monitor-only mode (zero latency)
✓ Programmatic policy switching per request
✓ Rich metadata: user country, IP, user groups
✗ More development work to implement
✗ Needs integration throughout the codebase
Best for: teams needing granular control and rich analytics
AI Gateway (Reverse Proxy)
base_url swap
Prompt Security acts as man-in-the-middle. Route all traffic through Prompt Security by changing your LLM base URL. All input/output is processed automatically.
✓ Minimal effort — one line of code change
✓ Seamless with existing auth methods
✓ Automatic processing of all input/output
✗ Less granular control, fewer customization options
✗ No programmatic policy switching per connector
✗ No advanced options (e.g. immediate_response)
✗ Limited to supported LLM providers
Best for: fast integration with minimal code changes
AI Gateway Limitations vs API
Programmatic Policy Management — Cannot switch policies per request on the same connector. Workaround: Create multiple connectors with different policies, switch the app-id per request.
Advanced Configurations — No support for immediate_response or asynchronous inspection.
Analytics Metadata — Cannot include user country, IP address, or user group information.
Full prevention mode: scan the prompt before sending to the LLM, then scan the response after. Supports block, modify (sanitize), and pass actions.
Minimal code change: point the OpenAI SDK at the Prompt Security gateway. Prompt Security scans transparently — just add the ps-app-id header.
Same approach as OpenAI but for Azure-hosted models. Add the forward-domain header to route to your Azure instance through PS.
Protect local/self-hosted LLMs via Ollama. Route through PS gateway with the forward-domain pointing to your Ollama server.
Prompt Security ships as a first-class plugin/guardrail inside popular LLM gateways and guardrail frameworks. Drop it into your existing stack without writing integration code.
How Prompt Security fits into a Homegrown GenAI Application: the app calls PS before and after the LLM, enabling real-time detection and remediation of PII, injections, and policy violations.
👤
GenAI App User
prompt
response
🖥️
Homegrown GenAI App
Your chatbot / assistant
prompt
response
☁️
LLM Providers
OpenAI · Anthropic AWS Bedrock · Google Llama · Mistral
on prompt
on response
Prompt Security Engine
BlockModifyLog
See Integration Guide →
Step through the exact code path of a request through this app. See what Python runs at each stage and what Prompt Security does with it.
💻 Code Being Executed
💡 What's Happening
🎭 Demo Scenarios
Severity
Title
Expected
Actions
No scenarios found.
Welcome
New Scenario
Country *(required for PII Detection)
Prompt
Entities
SE Talking Point
⚙️
Setup Required
This application is not yet configured. Please contact your administrator.
📋
Before You Begin
Please read and accept the following before using this application.
💼
Work use only
This application is provided for professional use only. Personal use is not permitted.
🔒
All chats are stored
Every conversation is logged and retained for support, security monitoring, and audit purposes. Do not enter passwords, personal data, or anything you would not want your organisation to review.
1
2
3
Welcome to HGA Prompt Demo 👋
This tool lets you explore how Prompt Security protects AI apps in real time. Let's get you set up in a few quick steps.
This name appears in the admin activity log so sessions can be attributed to you.
@
Used for identification in audit logs.
Check your inbox
Enter the 4-digit code to continue. Code expires in 10 minutes.
Connect Prompt Security
Select your Prompt Security region and enter your Deployment API Key to continue.
Setup instructions:
You need to create your own Homegrown Application in the PS portal. Do not use the default connector.
Click Homegrown Apps in the PS portal
Click the Settings Cog
Click + Create New, give it a name and click +Add
Define the policy for your application
Get the Deployment API Key under Deployment → Homegrown Apps
Gateway URL: —
⚠️ Selected region has no Gateway URL configured. Ask your admin to add one.
Your Preferences
SE Coaching Notes
Shows attacker goals and talking points on demo scenarios. Turn off when presenting to a live audience.
Explanation Notes
Shows "Why PS Caught This" panel on blocked/modified messages. Turn off to keep the demo focused on the outcome.
📋
Before You Begin
Please read and accept the following before using this application.
💼
Work use only
This application is provided for professional use only. Personal use is not permitted.
🔒
All chats are stored
Every conversation is logged and retained for support, security monitoring, and audit purposes. Do not enter passwords, personal data, or anything you would not want your organisation to review.
1
2
3
Welcome to HGA Prompt Demo 👋
This tool lets you explore how Prompt Security protects AI applications in real time. Let's get you set up.
What to expect:
Chat with an AI assistant
See how Prompt Security scans and protects prompts in real time
Run pre-built demo scenarios to show PS in action
Connect Prompt Security
Prompt Security is required to use this application. Select your region and enter your Deployment API Key to continue.
Setup instructions:
You need to create your own Homegrown Application in the PS portal. Do not use the default connector.
Click Homegrown Apps in the PS portal
Click the Settings Cog
Click + Create New, give it a name and click +Add
Define the policy for your application
Get the Deployment API Key under Deployment → Homegrown Apps
Gateway URL: —
⚠️ Selected region has no Gateway URL configured. Ask your admin to add one.
No Prompt Security regions have been configured yet. Contact your administrator to add a region before you can continue.
Your Preferences
SE Coaching Notes
Shows attacker goals and talking points on demo scenarios. Turn off when presenting to a live audience.
Explanation Notes
Shows "Why PS Caught This" panel on blocked/modified messages. Turn off to keep the demo focused on the outcome.