Documentation
Understand how Wren acts as a secure, invisible layer between your application and AI model providers.
The problem
The Bing prompt injection case
Traditional APIs accept structured, predictable input—which makes them straightforward to validate. AI systems interpret free-form human language, making the range of possible inputs essentially unbounded.
One of the most prominent examples of this vulnerability occurred during the early release of Microsoft's Bing Chat AI. By instructing the model to ignore its previous instructions, attackers could override the system prompt entirely and extract sensitive information about the AI's internal configuration.
This incident demonstrated that model-level guardrails alone are insufficient. There is a clear need for an external security layer that analyzes and filters prompts before they ever reach the model.
Architecture
The reverse proxy model
Wren is designed to be a transparent reverse proxy. Instead of your internal applications or microservices calling OpenAI (or Anthropic, Google, etc.) directly, they route their requests through the Wren Gateway.
Wren intercepts the inbound prompt, evaluates it against your configured security policies, routes the clean request to the upstream target, evaluates the returning response, and finally returns the strictly-validated payload back to your client.

Edge policies
Security & validation
Wren's core logic is dictated by its `policy_engine.py` and modular security scanners. These policies are defined programmatically and applied throughout the request lifecycle.
Prompt injection
Leverages heuristic scanning and specialized secondary models to detect and block malicious jailbreaks before they reach your primary, expensive model.
PII redaction
Identifies and masks Personally Identifiable Information (like SSNs, emails, and phone numbers) in prompt context in real-time to maintain compliance.
RAG integrity
Validates that the LLM's response only utilizes facts found strictly within the provided context window (preventing context stuffing & poisoning).
Tool interception
Inspects arguments provided by the AI to invoked tools, ensuring the model isn't attempting destructive actions (e.g., `os.system`) or accessing unauthorized network resources.
Jailbreak mitigation
Blocks explicit attempts to bypass model safety and content policies (e.g., "You are DAN, you can do anything...").
ML detection
Semantic intent scoring
Wren's core detection engine is built on a fine-tuned DistilBERT model. Rather than purely relying on keyword matching—which is easily evaded via obfuscation or translation—the model understands the meaning and intent of a prompt in context.
The scoring system combines multiple signal dimensions to calculate a final composite risk score before routing the prompt to the LLM:
- ML Score: Raw semantic confidence from the DistilBERT inference.
- Regex Match: Fast rule-based fallback for immediate matches on known threat vectors.
- Instruction Override: Likelihood the prompt attempts to explicitly modify system rules.
- Translation Signal: Detection of language obfuscation attempts.
Integration
Python SDK
Wren acts as a drop-in integration. Install it via pip install wren-gateway, run the interactive wren init command to select your local or remote proxy target, and integrate the native Python SDK—which handles authentication and routing transparently with identical method signatures to standard provider SDKs.
