Production-ready multi-agent AI system for automated document compliance, risk assessment, and PII detection using CrewAI
An enterprise-grade document intelligence system powered by 6 specialized AI agents working collaboratively to:
- π Detect sensitive information (PII/PHI) across 6 pattern types
- βοΈ Validate compliance with GDPR, HIPAA, and SOC2 regulations
- π Calculate risk scores (0-100) with weighted algorithms
- π Generate audit-ready reports with actionable recommendations
- π€ Implement human-in-the-loop governance for critical cases
Perfect for: Healthcare, Finance, Legal, HR, and any industry handling sensitive data.
- 6 Specialized Agents working in sequential workflow
- YAML-based configuration for easy customization
- CrewAI orchestration with modern best practices
- PII/PHI Detection: SSN, MRN, DOB, Email, Phone, Credit Cards
- Multi-Framework Support: GDPR, HIPAA, SOC2
- Risk-Based Processing: Automatic routing based on sensitivity
- Human Oversight: Required for high-risk documents (score β₯ 75)
- Custom Tools with Pydantic validation
- Natural Language Parsing for flexible agent inputs
- Comprehensive Logging and error handling
- Sample Documents for testing all risk levels
βββββββββββββββ
β Document β
ββββββββ¬βββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββ
β 6-Agent Sequential Pipeline β
βββββββββββββββββββββββββββββββββββββββββββββββ€
β 1. Intake Specialist β Extract & Validateβ
β 2. Classifier β Type & Sensitivityβ
β 3. PII Scanner β Detect Sensitive β
β 4. Compliance Checker β Regulatory Review β
β 5. Risk Assessor β Calculate Score β
β 6. Report Generator β Audit Report β
ββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββ
β Report β
β Risk: 85/100β
β CRITICAL β
βββββββββββββββ
- Python 3.8 or higher
- OpenAI API key
- pip or conda for package management
-
Clone the repository
git clone https://github.com/YOUR_USERNAME/enterprise-doc-intelligence.git cd enterprise-doc-intelligence -
Create virtual environment (recommended)
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp .env.example .env # Edit .env and add your OpenAI API key: # OPENAI_API_KEY=your-api-key-here
cd src
python main.py ../sample_documents/medical_record_sample.txtExpected output:
- 6 agents execute in sequence
- PII detection: 5 types found (SSN, MRN, DOB, Email, Phone)
- Risk score: 85/100 (CRITICAL)
- Recommendation: Human review required
- Report saved to
outputs/compliance_report.md
enterprise-doc-intelligence/
βββ src/
β βββ config/
β β βββ agents.yaml # Agent definitions (roles, goals, backstory)
β β βββ tasks.yaml # Task definitions (descriptions, outputs)
β βββ tools/
β β βββ pii_detector.py # 6-pattern PII/PHI detection
β β βββ compliance_checker.py# GDPR/HIPAA/SOC2 validation
β β βββ risk_calculator.py # Weighted risk scoring
β β βββ pdf_extractor.py # PDF text extraction
β β βββ text_extractor.py # TXT file reader
β βββ crew.py # CrewAI orchestration
β βββ main.py # Entry point
βββ sample_documents/ # Test files (3 risk levels)
βββ docs/
β βββ COMPLETE_GUIDE.md # Step-by-step tutorial
β βββ YAML_QUICKSTART.md # YAML configuration guide
βββ requirements.txt
βββ .env.example
βββ README.md
| Agent | Role | Tools | Output |
|---|---|---|---|
| Intake Specialist | Document Validator | Text/PDF Extractor | Clean text + metadata |
| Classifier | Type Analyzer | LLM Reasoning | Document type + sensitivity |
| PII Scanner | Data Detector | PII Detector | Sensitive data list + score |
| Compliance Checker | Regulatory Auditor | Compliance Engine | Violations + remediation |
| Risk Assessor | Risk Calculator | Risk Scorer | 0-100 score + level |
| Report Generator | Documentation Writer | LLM Synthesis | Audit-ready report |
All agents are configured in src/config/agents.yaml using CrewAI's modern declarative YAML approach.
Patterns: SSN, Email, Phone, MRN, Credit Cards, DOB
Risk Weights: 3-10 points per type
Output: Detection list + total risk score
Frameworks: GDPR, HIPAA, SOC2
Rules: 15+ compliance checks per framework
Output: Violations + recommended controls
Inputs: PII score + Classification + Violations
Algorithm: Weighted sum (max 100)
Output: Risk level (LOW/MEDIUM/HIGH/CRITICAL)
Supported: PDF, TXT files
Output: Text content + metadata (size, line count)
Three sample documents demonstrate different risk levels:
| Document | Risk Level | PII Types | Use Case |
|---|---|---|---|
medical_record_sample.txt |
CRITICAL (85) | SSN, MRN, DOB, Email, Phone | Healthcare PHI |
invoice_sample.txt |
MEDIUM (45) | Email, Phone | Business documents |
public_announcement_sample.txt |
LOW (10) | None | Public communications |
cd src
python main.py /path/to/document.txtpython main.py ../sample_documents/medical_record_sample.txtfor file in ../sample_documents/*.txt; do
python main.py "$file"
donecat outputs/compliance_report.md# Compliance Report
## Executive Summary
- Document Type: Medical Record
- Classification: RESTRICTED
- Risk Score: 85/100 (CRITICAL)
## PII/PHI Findings
- SSN: 123-45-6789
- MRN: MRN-987654
- DOB: 03/15/1985
- Email: patient@email.com
- Phone: 555-123-4567
## Risk Assessment
β οΈ CRITICAL RISK - Requires human review
## Recommendations
1. [HUMAN REVIEW] Require approval before processing
2. [SECURITY] Apply enhanced PII protection
3. [ACTION] Implement RBAC and encryption- β No data storage: Documents processed in-memory only
- β API key protection: Environment variables for credentials
- β Audit logging: Complete activity trail
- β Configurable: Adjust risk thresholds and rules
- β Extensible: Add custom compliance frameworks
Edit src/config/agents.yaml:
pii_detection_agent:
role: "Sensitive Data
8000
Scanner"
goal: "Detect all PII and PHI in documents"
backstory: "Expert in data privacy with 15 years experience..."Edit src/config/tasks.yaml:
pii_detection_task:
description: "Scan the document for PII/PHI"
expected_output: "Complete PII detection results with risk scores"Edit src/tools/risk_calculator.py:
CLASSIFICATION_WEIGHT = {
'public': 0,
'internal': 10,
'confidential': 25,
'restricted': 40
}- Complete Guide - Comprehensive tutorial with diagrams
- YAML Quickstart - Agent/task configuration guide
- Test Results - System validation report
- Verification - Tool testing results
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- πΉ Additional compliance frameworks (PCI-DSS, ISO 27001)
- πΉ More PII patterns (passport numbers, tax IDs)
- πΉ Support for more file formats (DOCX, XLSX)
- πΉ Web UI for document upload
- πΉ Database integration for report storage
- πΉ Multi-language support
- πΉ Performance optimizations
- πΉ Unit tests and integration tests
- PDF extraction requires
PyPDF2(included in requirements) - Risk calculator currently supports text-based analysis only
- LLM calls can be slow for large documents (>10 pages)
- Requires OpenAI API key (costs apply)
- Add support for DOCX and XLSX files
- Implement caching for repeated analyses
- Add FastAPI REST API endpoint
- Create web-based UI
- Support for custom PII patterns via config
- Integration with document management systems
- Performance benchmarking suite
- Docker containerization
- Patient record processing
- PHI compliance validation
- HIPAA audit preparation
- Customer data governance
- PCI-DSS compliance
- Fraud detection support
- Contract analysis
- Discovery document review
- Client data protection
- Employee file processing
- Background check compliance
- GDPR data mapping
- CrewAI - For the excellent multi-agent framework
- OpenAI - For GPT-4 language models
- Community - For feedback and contributions
This project is licensed under the MIT License - see the LICENSE file for details.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- LinkedIn: Girijesh Prasad
- GitHub: girijesh-ai
If you find this project useful, please consider giving it a star! It helps others discover the project.
Built with β€οΈ using CrewAI, OpenAI, and Python
- Agents: 6 specialized agents
- Tools: 5 custom tools
- Frameworks: 3 compliance frameworks
- PII Types: 6 detection patterns
- Code: ~3,000 lines
- Documentation: Comprehensive guides included