IMPORTANT NOTICE: This project is still a work in progress. Some features may be incomplete or subject to change.
PrivacyChatBoX is a comprehensive Python-based AI privacy protection platform that provides an intuitive and engaging approach to safeguarding sensitive information across multiple document types and providers.
This application offers a privacy-focused environment for AI interactions with multiple model integrations while ensuring user data remains secure.
- Multi-Provider AI Integration: Seamlessly switch between OpenAI, Anthropic Claude, Google Gemini, and local LLM models
- Privacy Scanning: Automatically scans text for sensitive information before sending to AI models
- Document Anonymization: Detects and anonymizes sensitive information in documents
- Privacy Alerts: Visual indicators (
⚠️ ) for conversations with detected sensitive information - Role-Based Access Control: Admin and regular user roles with appropriate permissions
- Privacy-Focused Administration: Admins can see metadata and privacy alerts but not conversation content
- Microsoft Purview DLP Integration: Enforces Microsoft sensitivity labels on uploads and evaluates prompts against your Purview DLP policies
- Conversation Management: Save, export, and manage conversation history
- Azure AD Authentication: Enterprise-ready authentication with Microsoft identities
- Admin Dashboard: User management, system metrics, and configuration
- Analytics: Comprehensive privacy metrics and visualization
- PDF Export: Export conversations to well-formatted PDF documents
- Web Search: Integrated web search capabilities through SerpAPI
- Docker Deployment: Containerized deployment for easy installation and scaling
Security Notice: Conversation titles, message content and file names are encrypted at rest when
DATA_ENCRYPTION_KEYis set (see Encryption at Rest). Without a key they are stored in plaintext and the Admin panel shows a warning. Privacy logs store masked previews of detected values, and uploaded files are not retained after their DLP checks.
The application is built using the following technologies:
- Frontend & Backend: Streamlit (Python web application framework)
- Database: PostgreSQL
- AI Providers: OpenAI API, Anthropic Claude API, Google Gemini API
- Authentication: Local authentication with password hashing, Azure AD integration
- Privacy Analysis: Custom regex patterns and Microsoft DLP integration
PrivacyChatBoX/
├── app.py # Main application entry point
├── pages/ # Streamlit pages
│ ├── admin.py # Admin dashboard
│ ├── chat.py # Main chat interface
│ ├── history.py # Conversation history and analytics
│ ├── model_manager.py # Local LLM model management (admin only)
│ └── settings.py # User settings
├── models.py # Database models
├── database.py # Database connection utilities
├── database_check.py # Database schema validation
├── ai_providers.py # AI provider integration
├── privacy_scanner.py # Privacy scanning functionality
├── ms_dlp.py # Microsoft Purview DLP / sensitivity label integration
├── model_catalog.py # Supported AI model IDs (single source of truth)
├── web_search.py # /search command via the official serpapi client
├── data_protection.py # Encryption at rest and audit-log masking
├── migration_secure_existing_data.py # Encrypt legacy rows, rotate keys, mask old logs
├── auth.py # Authentication utilities
├── azure_auth.py # Azure AD authentication
├── utils.py # General utilities
├── utils_auth.py # Authentication utilities
├── pdf_export.py # PDF export functionality
├── shared_sidebar.py # Shared UI components (with role-based visibility)
├── style.py # Custom CSS styling
├── assets/ # Static assets
│ ├── logo.png # Application logo
│ └── ... # Other assets
├── .env # Environment variables (not in repo)
├── .streamlit/ # Streamlit configuration
│ └── config.toml # Streamlit configuration file
├── pyproject.toml # Project metadata and Python dependencies
├── migration_add_dlp_columns.py # Microsoft DLP integration migration
├── migration_add_local_llm_columns.py # Local LLM settings migration
├── migration_pattern_levels.py # Privacy pattern levels migration
├── model_utils.py # Local LLM model utilities
├── test_local_llm.py # Testing script for local LLM integration
├── setup.sh # Automated installation script
├── models/ # Directory for local LLM models
└── docs/ # Documentation
├── Modules.md # Module documentation
├── Database.md # Database documentation
├── Setup_Guide.md # Detailed setup instructions
├── Troubleshooting.md # Solutions for common issues
├── ConversationData.md # Conversation data formatting guide
├── LocalLLM.md # Local LLM integration guide
└── Optimization_Guide.md # Performance optimization techniques
- Python 3.11 or higher
- PostgreSQL database (recommended)
- API keys for desired AI providers (OpenAI, Claude, Gemini) - optional
-
Clone the repository:
git clone https://github.com/yourusername/PrivacyChatBoX.git cd PrivacyChatBoX -
Run the setup script:
./setup.sh
This script will:
- Create a Python virtual environment
- Install required dependencies
- Set up the PostgreSQL database
- Create necessary directories
- Configure environment variables
- Run database migrations
-
Start the application:
source venv/bin/activate streamlit run app.py -
Access the application at
http://localhost:5000
For detailed setup instructions, troubleshooting, and manual setup options, see Setup Guide.
If you prefer a manual setup:
-
Clone the repository:
git clone https://github.com/yourusername/PrivacyChatBoX.git cd PrivacyChatBoX -
Install dependencies:
pip install . -
Configure environment variables by creating a
.envfile:# Database Configuration DATABASE_URL=postgresql://username:password@localhost/privacychatbox # OpenAI API (Optional) OPENAI_API_KEY=your_openai_api_key # Anthropic API (Optional) ANTHROPIC_API_KEY=your_anthropic_api_key # Google Gemini API (Optional) GOOGLE_API_KEY=your_gemini_api_key # SerpAPI for web search (Optional) SERPAPI_KEY=your_serpapi_key # Azure AD Authentication (Optional) AZURE_CLIENT_ID=your_azure_client_id AZURE_CLIENT_SECRET=your_azure_client_secret AZURE_TENANT_ID=your_azure_tenant_id AZURE_REDIRECT_URI=http://localhost:5000/ # Microsoft Purview DLP Integration (Optional) MS_CLIENT_ID=your_ms_client_id MS_CLIENT_SECRET=your_ms_client_secret MS_TENANT_ID=your_ms_tenant_id # Encryption at rest (strongly recommended) DATA_ENCRYPTION_KEY=your_fernet_key
-
Create Streamlit configuration:
mkdir -p .streamlit echo "[server]" > .streamlit/config.toml echo "headless = true" >> .streamlit/config.toml echo "address = \"0.0.0.0\"" >> .streamlit/config.toml echo "port = 5000" >> .streamlit/config.toml
-
Run database migrations:
python database_check.py
-
Start the application:
streamlit run app.py
-
Access the application at
http://localhost:5000
The application can be easily deployed using Docker and Docker Compose:
-
Clone the repository:
git clone https://github.com/yourusername/PrivacyChatBoX.git cd PrivacyChatBoX -
Start the application:
docker-compose up -d
-
Access the application at
http://localhost:5000
For a complete step-by-step guide on Docker deployment, configuration, and troubleshooting, see:
- Docker Setup Guide - Comprehensive instructions for Docker deployment
- Docker Guide - Detailed reference and advanced configurations
Run the automated test suite locally with:
python -m pytest tests -qThe current test suite focuses on the highest-risk application logic, including:
- authentication and session expiry
- conversation access control and deletion
- privacy scanning and anonymization behavior
- provider privacy-scan bypass logic
- PDF export escaping and authorization
- migration commit behavior
- history, analytics, and page-level data-shaping helpers
A lightweight GitHub Actions workflow is included at .github/workflows/tests.yml so the same command runs automatically on pushes and pull requests.
On first run, init_auth() in auth.py creates a bootstrap admin account:
- Username:
admin(override withDEFAULT_ADMIN_USERNAME) - Password: a random temporary password printed once in the server log (
docker-compose logs appfor Docker). SetDEFAULT_ADMIN_PASSWORDto choose it yourself; weak values such asadminare rejected and a random password is generated instead.
The bootstrap password is temporary: the admin must change it at first login before using chat. Passwords that an administrator sets for other users are also temporary. Existing installations whose admin still uses the old admin/admin default are forced to change it at next login.
The application supports two types of user roles with different permissions:
- Can access Chat, History, and Settings pages
- Can only see and manage their own conversations
- Can configure their own AI provider settings and privacy preferences
- Cannot access Admin Panel or Model Manager pages
- Have full access to all pages including Admin Panel and Model Manager
- Can manage users (create, delete, change roles and passwords)
- Can view metadata about all users' conversations (titles, timestamps, file attachments, privacy alerts)
- Can see which conversations contain privacy alerts (
⚠️ indicator) - Cannot view the actual content of other users' conversations, only metadata
- Can manage system-wide settings and local LLM models
Security Note: With
DATA_ENCRYPTION_KEYset, conversation content is encrypted at rest, so database dumps and backups do not expose it. Anyone holding both the database and the key (including the application host) can still decrypt it.
- Login: Use the login form or Azure AD login if configured
- Chat: Navigate to the chat page to start conversations with AI
- Settings: Configure your AI providers, privacy settings, and more
- History: View your conversation history and analytics
- Admin: Manage users and view system metrics (admin only)
- Model Manager: Download and configure local LLM models (admin only)
This application uses environment variables to store sensitive configuration like API keys and database credentials. This approach enhances security by keeping secrets out of your code repository.
-
Create your .env file:
- Copy the provided
.env.examplefile:cp .env.example .env
- Edit the
.envfile with your actual credentials
- Copy the provided
-
Security measures in place:
- The
.gitignorefile is configured to exclude the.envfile from git - Environment variables are loaded at runtime and never stored in the database
- API keys are accessed only when needed for specific operations
- The
-
Available variables:
- Database connection:
DATABASE_URL - API keys:
OPENAI_API_KEY,ANTHROPIC_API_KEY,GOOGLE_API_KEY(orGEMINI_API_KEY),SERPAPI_KEY - Model lists:
OPENAI_MODELS,CLAUDE_MODELS,GEMINI_MODELS(optional overrides) - Azure authentication:
AZURE_CLIENT_ID,AZURE_CLIENT_SECRET, etc. - Microsoft Purview DLP:
MS_CLIENT_ID,MS_CLIENT_SECRET,MS_TENANT_ID, optionalMS_PURVIEW_*/MS_DLP_* - Encryption at rest:
DATA_ENCRYPTION_KEY - Bootstrap admin:
DEFAULT_ADMIN_USERNAME,DEFAULT_ADMIN_PASSWORD
- Database connection:
You can also refer to the Settings page > Environment Config tab for a complete list of available environment variables and additional descriptions.
- NEVER commit your
.envfile to version control - Double-check your
.gitignorefile includes.enventries - Regularly rotate your API keys for production deployments
- Use separate API keys for development and production environments
This application requires various API keys for full functionality:
- OpenAI API Key: Get from OpenAI Platform
- Claude API Key: Get from Anthropic Console
- Gemini API Key: Get from Google AI Studio
- SerpAPI Key: Get from SerpAPI
Model IDs live in one place, model_catalog.py. The first entry is the default for new users.
| Provider | Models offered | SDK |
|---|---|---|
| OpenAI | gpt-5.6-terra (default), gpt-6.1-sol, gpt-6-luna, gpt-5.5, gpt-5.4-mini, gpt-5.4-nano |
openai |
| Anthropic | claude-sonnet-5-5 (default), claude-opus-5-5, claude-fable-5-1, claude-haiku-5-5 |
anthropic |
gemini-3.8-flash (default), gemini-3.5-flash-lite, gemini-3.1-pro-preview (preview) |
google-genai |
- Settings saved with a retired model (for example
gpt-4oorclaude-3-5-sonnet-20241022) are resolved to the provider default automatically. - Model lists go stale quickly. Replace a provider's list without a code change with
OPENAI_MODELS,CLAUDE_MODELSorGEMINI_MODELS(comma-separated). - OpenAI GPT-5 and later are reasoning models, so requests use
max_completion_tokensand the default temperature. - Gemini uses the
google-genaiSDK; the previousgoogle-generativeaipackage has reached end of life.
The /search <query> chat command uses SerpApi's officially maintained serpapi client. It replaces the legacy google-search-results package, which is no longer developed and fails to build on recent Python versions. Both install a module named serpapi, so when upgrading run:
pip uninstall -y google-search-results && pip install serpapiThe query is sent after privacy scanning and anonymization, so detected sensitive values are not forwarded to the search provider when auto-anonymize is on.
The integration uses documented Microsoft APIs:
- Sensitivity labels on uploads. Labels are read locally from the file's own metadata (
MSIP_Label_*properties in Office files, PDFs and e-mails), so files are not uploaded to Microsoft just to learn their label. Label IDs are resolved to names with Microsoft GraphGET /beta/security/informationProtection/sensitivityLabels. Files labelled at or above the user's threshold are blocked. - Purview DLP policies on prompts and file text. Content is evaluated with Microsoft Graph v1.0
POST /users/{id}/dataSecurityAndGovernance/processContent. Content is blocked when Purview returnsrestrictAccesswithblock. Blocked uploads are recorded in Purview audit withcontentActivities.
Setup: register an Entra application, grant the Microsoft Graph application permissions InformationProtectionPolicy.Read.All, Content.Process.User and ContentActivity.Write with admin consent, and set MS_CLIENT_ID, MS_CLIENT_SECRET and MS_TENANT_ID. Then create a Purview DLP policy that targets the application. Without one, processContent allows everything. The Admin panel's Microsoft DLP tab has a connection test that lists your tenant's labels.
Coverage: label enforcement applies to every user. Purview policy evaluation needs a Microsoft Entra identity, so it applies to users who sign in with Azure AD.
Optional settings: MS_DLP_LABEL_LEVELS maps label names or IDs to levels (JSON). MS_DLP_UNKNOWN_LABEL_LEVEL sets the level for unrecognised labels and defaults to confidential, so unknown labels fail safe. MS_PURVIEW_FAIL_CLOSED=true blocks content when Purview cannot be reached. MS_DLP_ENDPOINT_ID from earlier versions is no longer used.
Set DATA_ENCRYPTION_KEY to a Fernet key to encrypt conversation titles, message content and uploaded file names in the database:
python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"setup.shgenerates a key automatically if none exists.- Run
python migration_secure_existing_data.pyonce to encrypt existing plaintext rows. The Docker entrypoint runs it on every start, and it is idempotent. - Key rotation: prepend a new key (
DATA_ENCRYPTION_KEY=new_key,old_key), run the migration, then remove the old key. - Back up the key securely. Data encrypted with a lost key cannot be recovered.
PrivacyChatBoX includes several performance optimizations to improve scanning speed and memory efficiency:
- Pre-compiled Regex Patterns: All privacy patterns are pre-compiled at startup for faster matching
- Confidence Scoring: Each pattern has a confidence score to reduce false positives
- Chunked File Processing: Large files are processed in manageable chunks to prevent memory issues
- Parallel Processing: Multi-threading support for faster document scanning
- Adaptive Loading: Document processing libraries are loaded conditionally as needed
For detailed information on performance optimizations, see Optimization Guide.
PrivacyChatBoX supports running local language models without requiring an internet connection or API keys, which enhances privacy and reduces operational costs.
The application supports GGUF format models through the llama-cpp-python library. Popular models include:
- Llama 2: Meta's Llama 2 models in various sizes
- Mistral: Mistral AI's efficient models
- Phi-2: Microsoft's compact but capable models
- Any GGUF format model: Compatible with the llama-cpp-python library
The Model Manager page provides a user-friendly interface for:
- Downloading pre-configured models directly within the application
- Customizing model parameters like context length and temperature
- Testing models before deploying them in the chat interface
- Offline Operation: Process all requests entirely on your own hardware
- Bypass Privacy Scanning: Option to disable privacy scanning for local models (since data never leaves your system)
- Hardware Acceleration: GPU acceleration support for faster inference
This application uses several database migration scripts to handle schema updates:
- migration_add_dlp_columns.py: Adds Microsoft DLP integration columns to the Settings table
- migration_add_local_llm_columns.py: Adds local LLM configuration columns to the Settings table
- migration_pattern_levels.py: Adds 'level' attribute to custom patterns in Settings table, enabling categorization of patterns into standard and strict modes
If you encounter database-related errors, especially with missing columns, make sure to run these migration scripts:
python migration_add_dlp_columns.py
python migration_add_local_llm_columns.py
python migration_pattern_levels.pyThe application includes auto-migration checks that will attempt to detect and apply necessary migrations when features are accessed.
-
Missing Database Columns Error:
- Error:
column settings.enable_ms_dlp does not existor similar - Solution: Run the appropriate migration script as mentioned above
- Error:
-
Detached Instance Errors:
- Error:
Instance <User at 0x...> is not bound to a Session - Solution: The application uses the session_scope context manager to properly handle database sessions. Check that all database operations are performed within a session_scope block.
- Error:
-
Conversation Display Issues:
- Problem: Conversations not displaying correctly or errors when accessing message properties
- Solution: The application uses a robust message formatting function that handles both model objects and dictionaries. Make sure to use the format_conversation_messages function when working with conversation data.
The following features and improvements are planned for future versions of PrivacyChatBoX:
-
Key Management Integration: Load
DATA_ENCRYPTION_KEYfrom a managed key store (Azure Key Vault, AWS KMS, HashiCorp Vault) instead of an environment variable. -
Chat Interface Optimization: Improve the chat interface performance and responsiveness, including faster message rendering and reduced latency for long conversations.
-
Multi-modal AI Support: Expand capabilities to handle image, audio, and video inputs/outputs with privacy-preserving processing for all media types.
-
Advanced RAG Implementation: Add Retrieval-Augmented Generation capabilities with local vector databases for organizational knowledge bases, with privacy-aware embedding generation.
-
Federated Learning Integration: Implement privacy-preserving model fine-tuning using federated learning techniques to improve AI responses without compromising user data.
-
Enterprise SSO Integration: Expand authentication options to support additional enterprise SSO providers beyond Azure AD, including Okta, Auth0, and Google Workspace.
-
Compliance Reporting: Implement automated compliance reporting for privacy regulations like GDPR, HIPAA, and CCPA with audit trails for all AI interactions.
Here are some screenshots showing the various interfaces of the PrivacyChatBoX application:
The welcome screen with login form and key features overview
The chat interface showing privacy protection in action with anonymized phone number
AI model configuration settings with API key management
Custom regex pattern configuration for privacy scanning
Conversation history with privacy alert indicators
This project is licensed under a dual-license model:
- Free for personal, educational, research, and non-profit use
- Permission to use, modify, and redistribute for non-commercial purposes
- Must include original copyright notice and license terms
- Contributions back to the project welcome under same license terms
- Requires a paid commercial license for any business or revenue-generating applications
- Contact the copyright holders for commercial licensing options and pricing
- Enterprise support and customization available under commercial agreements
The full license terms are available in the LICENSE.md file, which includes all conditions, disclaimers, and limitations. This dual-licensing approach helps maintain the project's sustainable development while providing free access for non-commercial users.
DISCLAIMER: This software is provided "AS IS" without warranty of any kind. Use at your own risk. The developers assume no liability for any damages or losses resulting from the use of this software.
