Skip to content

Latest commit

Β 

History

History
395 lines (281 loc) Β· 11.4 KB

File metadata and controls

395 lines (281 loc) Β· 11.4 KB

πŸ”” Automatic Compliance Failure Notifications

Overview

Your GDPR Compliance Checker now automatically sends notifications whenever compliance issues are detected in uploaded contracts. No manual intervention required!


πŸ“‹ What Gets Notified

When a contract is analyzed and compliance issues are found, notifications are automatically sent containing:

βœ… Included Information:

  • Document Type - Type of contract analyzed
  • Risk Score - Numerical score from 0-100 (with visual indicators)
  • Missing Clauses - List of GDPR clauses not found in the document
  • Compliance Risks - Detailed compliance risks identified
  • Recommendations - Specific actions to achieve compliance
  • Timestamp - When the analysis was performed

πŸš€ How It Works

Automatic Flow:

  1. User uploads a contract via Streamlit app
  2. System analyzes the document against GDPR templates
  3. Risk score is calculated (0-100)
  4. If risk score > 0, notifications are automatically sent to:
    • πŸ“§ Email (always, if configured)
    • πŸ’¬ Slack (optional, if configured)
  5. User sees results in the app AND receives notifications

Manual Testing:

You can test notifications without uploading a contract:

# Test all notification types
python project/test_compliance_notification.py

# Test email only
python project/notification.py

# Test Slack only
python project/slack_notification.py

βš™οΈ Configuration

Required: Email Notifications

Add to your .env file:

# Gmail SMTP Configuration
SMTP_SENDER_EMAIL=your_email@gmail.com
SMTP_PASSWORD=your_app_password_here
SMTP_RECEIVER_EMAIL=receiver_email@gmail.com
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587

Important: For Gmail, use an App Password, not your regular password.

Optional: Slack Notifications

Add to your .env file:

# Slack Webhook URL
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL

Get your webhook URL from Slack Incoming Webhooks.


πŸ“§ Email Notification Example

When compliance issues are detected, an email like this is sent:

Subject: ⚠️ GDPR Compliance Alert: Data Processing Agreement - Risk Score 75/100

╔══════════════════════════════════════════════════════════════╗
β•‘           GDPR COMPLIANCE FAILURE NOTIFICATION               β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

πŸ“„ DOCUMENT INFORMATION
─────────────────────────────────────────────────────────────────
Document Type: Data Processing Agreement
Analysis Date: 2025-10-29 14:30:00

⚠️ RISK ASSESSMENT
─────────────────────────────────────────────────────────────────
Risk Score:    75/100
Risk Level:    HIGH RISK πŸ”Ά

❌ MISSING CLAUSES
─────────────────────────────────────────────────────────────────
  β€’ Data Subject Rights - Article 15-22 GDPR
  β€’ Data Breach Notification - Article 33 GDPR
  β€’ Data Protection Impact Assessment (DPIA) - Article 35 GDPR

🚨 COMPLIANCE RISKS IDENTIFIED
─────────────────────────────────────────────────────────────────
  β€’ Inadequate data subject rights provisions may violate GDPR Articles 15-22
  β€’ Missing breach notification clause creates regulatory risk under Article 33
  β€’ Absence of DPIA requirements may expose organization to fines

βœ… RECOMMENDATIONS
─────────────────────────────────────────────────────────────────
  β€’ Add comprehensive data subject rights clause covering all GDPR Articles 15-22
  β€’ Include data breach notification procedures with 72-hour timeline
  β€’ Add DPIA requirements for high-risk processing activities

─────────────────────────────────────────────────────────────────
πŸ€– This alert was automatically generated by the GDPR Compliance Checker.
Please review and take appropriate action to ensure compliance.

πŸ’¬ Slack Notification Example

Slack notifications use rich formatting with:

  • Color-coded risk levels (Green/Orange/Red)
  • Structured blocks for easy reading
  • Emojis for visual clarity
  • Section dividers for organization

Example:

⚠️ GDPR COMPLIANCE ALERT

Document Type: Data Processing Agreement
Analysis Date: 2025-10-29 14:30:00

Risk Score: πŸ”Ά 75/100
Risk Level: High Risk

❌ Missing Clauses:
β€’ Data Subject Rights - Article 15-22 GDPR
β€’ Data Breach Notification - Article 33 GDPR
β€’ Data Protection Impact Assessment (DPIA)

🚨 Compliance Risks:
β€’ Inadequate data subject rights provisions may violate GDPR
β€’ Missing breach notification clause creates regulatory risk
β€’ Absence of DPIA requirements may expose organization to fines

βœ… Recommendations:
β€’ Add comprehensive data subject rights clause
β€’ Include data breach notification procedures
β€’ Add DPIA requirements for high-risk processing

πŸ€– Automated alert from GDPR Compliance Checker - Please review and take action

🎯 Risk Level Indicators

Notifications automatically categorize risk levels:

Risk Score Level Indicator Email Priority Slack Color
0-25 Low βœ… Normal Green
26-50 Medium ⚠️ Important Orange
51-75 High πŸ”Ά Urgent Dark Orange
76-100 Critical πŸ”΄ CRITICAL Red

πŸ§ͺ Testing Your Setup

Quick Test Commands:

cd project

# Test email notifications
python test_compliance_notification.py

# Test email only (basic test)
python notification.py

# Test Slack only
python slack_notification.py

What to Expect:

  1. Email Test: Check your SMTP_RECEIVER_EMAIL inbox
  2. Slack Test: Check your configured Slack channel
  3. Full Test: Runs 4 different scenarios (low, medium, high, critical risk)

πŸ”„ Integration Points

Notifications are automatically triggered in:

1. Main Streamlit App (main.py)

  • Runs when user uploads a contract
  • Triggered immediately after compliance analysis
  • Sends both email and Slack (if configured)

2. Template Updates (scrapping.py)

  • Runs when GDPR templates are updated
  • Scheduled to run daily at midnight
  • Uses different notification format (template updates, not failures)

πŸ“ Using Notifications Programmatically

Email Notification:

from notification import send_compliance_failure_notification
from datetime import datetime

# Prepare data
notification_data = {
    "document_type": "Data Processing Agreement",
    "risk_score": 75,
    "missing_clauses": ["Clause 1", "Clause 2"],
    "compliance_risks": ["Risk 1", "Risk 2"],
    "recommendations": ["Fix 1", "Fix 2"],
    "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
}

# Send notification
send_compliance_failure_notification(notification_data)

Slack Notification:

from slack_notification import send_compliance_failure_alert
from datetime import datetime

# Prepare data (same format as email)
notification_data = {
    "document_type": "Joint Controller Agreement",
    "risk_score": 55,
    "missing_clauses": ["Clause A", "Clause B"],
    "compliance_risks": ["Risk X", "Risk Y"],
    "recommendations": ["Action 1", "Action 2"],
    "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
}

# Send notification
send_compliance_failure_alert(notification_data)

πŸ› οΈ Troubleshooting

Email Not Sending?

  1. Check .env credentials

    • Verify SMTP_SENDER_EMAIL and SMTP_PASSWORD
    • Use Gmail App Password, not regular password
  2. Check Gmail settings

    • Enable 2-factor authentication
    • Generate App Password from Google Account settings
  3. Test connection

    python project/notification.py

Slack Not Sending?

  1. Check webhook URL

    • Verify SLACK_WEBHOOK_URL in .env
    • Ensure URL starts with https://hooks.slack.com/
  2. Test webhook

    python project/slack_notification.py
  3. Verify webhook is active

    • Go to Slack App settings
    • Check webhook is not disabled

Notifications Not Automatic?

  1. Check main.py integration

    • Ensure notification and slack_notification are imported
    • Verify notification code is present after compare_agreements
  2. Check risk score parsing

    • Verify parse_comparison_result function works
    • Check that risk_score > 0 for issues

πŸ“Š Notification Preferences

Customize Email Receiver:

# Send to specific email
send_compliance_failure_notification(
    report_data, 
    receiver="custom@example.com"
)

Disable Notifications Temporarily:

In main.py, comment out the notification section:

# # Send notifications
# if risk_score > 0:
#     notification.send_compliance_failure_notification(...)

Send to Multiple Channels:

Modify main.py to send to multiple Slack channels:

# Send to multiple Slack channels
webhooks = [
    "https://hooks.slack.com/services/TEAM1/...",
    "https://hooks.slack.com/services/TEAM2/...",
]

for webhook in webhooks:
    slack_notification.send_compliance_failure_alert(
        notification_data, 
        webhook_url=webhook
    )

πŸŽ“ Best Practices

  1. Test notifications before production

    • Run test_compliance_notification.py
    • Verify formatting looks good
  2. Monitor notification delivery

    • Check email delivery rates
    • Monitor Slack channel activity
  3. Keep credentials secure

    • Never commit .env to version control
    • Use environment variables in production
  4. Set up notification filters

    • Create email rules for compliance alerts
    • Set up Slack channel notifications
  5. Review notifications regularly

    • Check for false positives
    • Adjust risk scoring if needed

πŸ“ž Support

If you encounter issues:

  1. Check the troubleshooting section above
  2. Verify .env configuration
  3. Test individual components separately
  4. Check logs for error messages

πŸŽ‰ Summary

βœ… Automatic notifications when compliance issues detected
βœ… Email AND Slack support
βœ… Detailed failure reports with missing clauses, risks, and recommendations
βœ… Risk-based categorization (Low, Medium, High, Critical)
βœ… Easy testing with test scripts
βœ… Customizable for your needs

Your compliance failures will never go unnoticed again! πŸš€