A privacy-first AI gateway that sanitizes sensitive data before sending prompts to AI models and de-sanitizes the responses. This ensures your personal information never leaves your local environment while still allowing you to benefit from powerful cloud-based AI services.
- Client-Side Privacy: All sensitive data processing happens locally
- Hybrid Detection: Combines rule-based regex patterns with local NER models
- Context-Aware Placeholders: Generates meaningful placeholders to maintain AI response quality
- Multi-Provider Support: Works with any AI API (OpenAI, Google Gemini, Anthropic, etc.)
- Real-Time Processing: Fast sanitization and de-sanitization
- Comprehensive Testing: >90% test coverage on core functionality
- Rule-Based Detector: Uses regex patterns for structured data (emails, phones, IPs, etc.)
- Local Model Detector: Uses NER models via LM Studio for unstructured entities (names, locations, organizations)
- Hybrid Detector: Combines both approaches for comprehensive coverage
- Privacy Processor: Main orchestrator for sanitization and de-sanitization
โโโโโโโโโโโโโโโ
โ User Input โ "My name is Alice, email: alice@email.com"
โ (with PII) โ
โโโโโโโโฌโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโ
โ Privacy Analysis โ Detects: "Alice" (name), "alice@email.com" (email)
โ (LM Studio) โ Creates: PERSON_1, EMAIL_ADDRESS_1
โโโโโโโโฌโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโ
โ Sanitized Prompt โ "My name is PERSON_1, email: EMAIL_ADDRESS_1"
โ (PII Removed) โ
โโโโโโโโฌโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโ
โ GEMINI API ๐ โ Gemini ONLY sees anonymized version
โ (Cloud Service) โ Generates response with placeholders
โโโโโโโโฌโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโ
โ Privacy Restoration โ PERSON_1 โ Alice
โ (Local) โ EMAIL_ADDRESS_1 โ alice@email.com
โโโโโโโโฌโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโ
โ Final Response โ "Hello Alice! I've sent info to alice@email.com"
โ (to User) โ
โโโโโโโโโโโโโโโโโโโโโโโโ
โ
Your personal data NEVER sent to cloud
โ
Gemini generates contextually-aware responses
โ
Original information restored in final output
- Python 3.10+
- LM Studio (for local NER model)
- Clone the repository:
git clone <repository-url>
cd privacy-guardian-gateway- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
cp .env.example .env
# Edit .env with your API keysfrom privacy_guardian.sanitizer import PrivacyProcessor
processor = PrivacyProcessor()
# Sanitize text
text = "Hi, I'm John Smith. Email me at john@example.com"
result = processor.sanitize(text)
print(f"Original: {result.original_text}")
print(f"Sanitized: {result.sanitized_text}")
print(f"Session Map: {result.session_map}")
# De-sanitize AI response
ai_response = "Hello [PERSON_NAME], I received your message at [EMAIL_ADDRESS]"
final_response = processor.desanitize(ai_response, result.session_map)
print(f"Final: {final_response}")Run the test suite:
# Run all tests
pytest
# Run with coverage
pytest --cov=privacy_guardian --cov-report=html
# Run specific test file
pytest tests/test_sanitizer/test_processor.py -vprivacy-guardian-gateway/
โโโ privacy_guardian/ # Main source code
โ โโโ sanitizer/ # Core sanitization logic
โ โโโ multi_ai_coordinator.py # Multi-AI service coordination
โ โโโ ai_client.py # AI service clients
โ โโโ prompt_loader.py # Centralized prompt management
โโโ prompts/ # AI prompts (externalized)
โ โโโ privacy/ # Privacy analysis prompts
โ โโโ ner/ # Named entity recognition prompts
โ โโโ system/ # System prompts
โโโ documents/ # Detailed documentation
โ โโโ API_DOCS.md # API reference
โ โโโ USER_GUIDE.md # User guide
โ โโโ TERMINAL_README.md # Terminal interface guide
โโโ tests/ # Comprehensive test suite
โโโ app.py # Flask web API
โโโ privacy_terminal.py # Interactive terminal interface
โโโ README.md # This file
LM_STUDIO_URL: URL for local LM Studio instance (default: http://localhost:1234)GEMINI_API_KEY: Google Gemini API key for AI responses
- Download and install LM Studio
- Download a small NER model (recommended: any BERT-based NER model)
- Start the local server on port 1234
- The Privacy Processor will automatically detect and use the local model
- No Data Transmission: Sensitive data never leaves your local environment
- Stateless Processing: No conversation history is stored
- Session Isolation: Each request uses a unique session map
- Fallback Protection: Works with rule-based detection even if local model fails
- Structured Data: Emails, phone numbers, IP addresses, URLs, credit cards, SSNs
- Unstructured Data: Person names, locations, organizations, miscellaneous PII
- Rule-based detection: < 1ms for typical inputs
- Local model detection: 100-500ms depending on model size
- Total processing time: Usually < 1 second end-to-end
โ Completed - Multi-AI Privacy Gateway:
- Core Privacy Engine: Advanced multi-level privacy protection
- Multi-AI Coordination: Intelligent service routing (LM Studio + Gemini)
- Interactive Terminal: Full-featured terminal interface with testing
- Web API: Complete Flask API with security features
- Prompt Management: Externalized prompts in
/prompts/folder - Comprehensive Testing: Interactive privacy testing with detailed metrics
- Production Ready: Docker deployment and security configurations
- Quick Start - Get started with web interface
- Terminal Interface - Command-line usage
- Interactive Testing - Testing features
- API Reference - Complete API documentation
- Deployment Guide - Production deployment
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests (
pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
- Check the test files for usage examples
- Review the plan.md for detailed architecture information
- Open an issue on GitHub
- Web interface (Phase 2)
- User configuration profiles
- Multiple AI provider support
- Advanced context preservation
- Browser extension
- Mobile app# PrivacyAI