Skip to content

ru-aish/PrivacyAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Privacy Guardian AI Gateway

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.

๐ŸŽฏ Features

  • 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

๐Ÿ—๏ธ Architecture

Core Components

  1. Rule-Based Detector: Uses regex patterns for structured data (emails, phones, IPs, etc.)
  2. Local Model Detector: Uses NER models via LM Studio for unstructured entities (names, locations, organizations)
  3. Hybrid Detector: Combines both approaches for comprehensive coverage
  4. Privacy Processor: Main orchestrator for sanitization and de-sanitization

Data Flow with Gemini Integration

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ 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

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.10+
  • LM Studio (for local NER model)

Installation

  1. Clone the repository:
git clone <repository-url>
cd privacy-guardian-gateway
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up environment variables:
cp .env.example .env
# Edit .env with your API keys

Basic Usage

from 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}")

๐Ÿงช Testing

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 -v

๐Ÿ“ Project Structure

privacy-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

๐Ÿ”ง Configuration

Environment Variables

  • LM_STUDIO_URL: URL for local LM Studio instance (default: http://localhost:1234)
  • GEMINI_API_KEY: Google Gemini API key for AI responses

LM Studio Setup

  1. Download and install LM Studio
  2. Download a small NER model (recommended: any BERT-based NER model)
  3. Start the local server on port 1234
  4. The Privacy Processor will automatically detect and use the local model

๐Ÿ”’ Security Features

Privacy Guarantees

  • 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

Supported Entity Types

  • Structured Data: Emails, phone numbers, IP addresses, URLs, credit cards, SSNs
  • Unstructured Data: Person names, locations, organizations, miscellaneous PII

๐Ÿ“Š Performance

  • 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

๐Ÿšง Current Status: FULLY OPERATIONAL ๐Ÿš€

โœ… 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

๐Ÿ“š Documentation

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (pytest)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Support

If you encounter any issues or have questions:

  1. Check the test files for usage examples
  2. Review the plan.md for detailed architecture information
  3. Open an issue on GitHub

๐Ÿ”ฎ Roadmap

  • Web interface (Phase 2)
  • User configuration profiles
  • Multiple AI provider support
  • Advanced context preservation
  • Browser extension
  • Mobile app# PrivacyAI

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors