LLM-Security-Firewall is a lightweight semantic firewall designed to protect Large Language Models (LLMs) against:
- ๐ซ Prompt Injection Attacks
- ๐ Jailbreak Attempts
- ๐ง Role-play Exploits
โ ๏ธ Instruction Override Attacks- ๐ System Prompt Leakage
The system introduces a Decoupled Security Architecture that intercepts and analyzes prompts before they ever reach the LLM.
Unlike traditional keyword filtering systems, this project uses:
- ๐ง Semantic Vector Embeddings
- โก XGBoost Threat Classification
- ๐ Real-time Probability Analysis
- ๐ก๏ธ Local Security Inference
This allows the firewall to detect malicious intent even when attacks are obfuscated or rephrased.
The firewall operates using a 4-Phase Security Pipeline:
| Phase | Description |
|---|---|
| ๐ฅ Input & Ingestion | User submits prompt through Streamlit UI |
| ๐ง Semantic Analysis | MiniLM converts prompt into embeddings |
| ๐ฆ Logic Gate | XGBoost classifies malicious probability |
| โ๏ธ Secure Resolution | Only verified prompts reach the LLM |
The security core performs:
Prompt โ Embedding โ XGBoost โ Threat Score โ DecisionThe prompt is transformed into a 384-dimensional semantic vector using:
all-MiniLM-L6-v2The embedding is analyzed using an XGBoost classifier.
| Threat Score | Action |
|---|---|
| > 0.5 | ๐ซ BLOCK Prompt |
| โค 0.5 | โ Forward to LLM |
The user experience is designed for:
- โก Real-time detection
- ๐ Instant feedback
- ๐ก๏ธ Transparent security status
- โ๏ธ Secure API routing
Malicious prompts are intercepted locally before any external transmission occurs.
- Prompt Injection Detection
- Jailbreak Prevention
- Semantic Threat Analysis
- Probability-based Threat Scoring
- Decoupled LLM Firewall
- Lightweight ML inference
- Low latency (<50ms)
- CPU-friendly deployment
- Real-time classification
- Interactive Streamlit Dashboard
- Plotly Threat Meter
- Session Threat Logs
- Safe/Blocked Visual Alerts
- OpenRouter Integration
- Secure Request Routing
- Conditional API Access
- External LLM Protection Layer
| Component | Technology |
|---|---|
| Embedding Model | Sentence Transformers |
| Semantic Encoder | all-MiniLM-L6-v2 |
| Classifier | XGBoost |
| Frontend | Streamlit |
| Backend | FastAPI |
| Visualization | Plotly |
| API Integration | OpenRouter |
| Programming Language | Python |
| Metric | Score |
|---|---|
| ๐ฏ Accuracy | 85.15% |
| ๐ ROC-AUC | 0.8989 |
| โ๏ธ Weighted F1-Score | 83.85% |
| ๐ก๏ธ Precision (Malicious) | 86.20% |
| ๐จ Recall (Malicious) | 81.50% |
LLM-Security-Firewall/
โ
โโโ streamlit_app.py
โโโ api_server.py
โโโ config.py
โโโ requirements.txt
โโโ README.md
โโโ .gitignore
โโโ .env.example
โโโ LICENSE
โ
โโโ models/
โ โโโ xgb_embed_model.json
โ
โโโ notebook/
โ โโโ PromptInjectionSecurityFilter.ipynb
โ
โโโ assets/
โ โโโ architecture-overview.png
โ โโโ technical-workflow.png
โ โโโ security-decision-flow.png
โ โโโ chat-flow-diagram.png
โ
โโโ docs/
โโโ Project_Report.pdf
โโโ PSF_Presentation.pptxgit clone https://github.com/YOUR_USERNAME/LLM-Security-Firewall.git
cd LLM-Security-Firewallpip install -r requirements.txtCreate a .env file:
OPENROUTER_API_KEY=your_api_key_herestreamlit run streamlit_app.pyuvicorn api_server:app --reloadUser Prompt
โ
Semantic Vectorization
โ
XGBoost Threat Classification
โ
Threat Score Evaluation
โ
โโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโ
โ Malicious โ Safe โ
โ Prompt โ Prompt โ
โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโค
โ BLOCK โ Forward to LLM โ
โโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโ
This project demonstrates that:
- Lightweight machine learning models can effectively secure LLMs
- Semantic embeddings outperform traditional keyword filters
- Decoupled architectures reduce inference costs
- Real-time LLM firewalls can operate on standard consumer hardware
- ๐ง FAISS vector database integration
- ๐ Multilingual attack detection
- ๐ผ๏ธ Multimodal prompt injection defense
- ๐ฌ Multi-turn conversational memory analysis
- โก Adaptive threshold optimization
- โ๏ธ Cloud-native deployment support
Detailed research and implementation documents are available inside:
docs/Including:
- ๐ Research Report
- ๐ Project Presentation
- ๐งช Experimental Results
- ๐ง ML Workflow Analysis
If you found this project useful:
- โญ Star the repository
- ๐ด Fork the project
- ๐ก๏ธ Contribute to LLM security research
This project is licensed under the MIT License.



