:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat: default AI data processing to opt-in, auto-disable on BAA signed (#59715)
Rafael Audibert06d2b3428a84
diff --git a/frontend/src/scenes/max/components/AILiabilityNotice.tsx b/frontend/src/scenes/max/components/AILiabilityNotice.tsxindex d9e0ecd58c04..03fa88fe1d03 100644--- a/frontend/src/scenes/max/components/AILiabilityNotice.tsx+++ b/frontend/src/scenes/max/components/AILiabilityNotice.tsx@@ -19,8 +19,8 @@ export function AILiabilityNotice(): JSX.Element | null {return (<div className="flex flex-col mb-2 max-w-160 w-full px-3"><LemonBanner type="ai" onClose={dismissLiabilityNotice}>- PostHog AI uses third-party LLM providers (OpenAI and Anthropic). Your data will not be used for- training third-party models.+ PostHog AI uses third-party LLM providers (OpenAI, Anthropic, and Alphabet). Your data will not be used+ for training third-party models.{isAdminOrOwner && (<>{' '}diff --git a/frontend/src/scenes/settings/organization/aiConsentCopy.tsx b/frontend/src/scenes/settings/organization/aiConsentCopy.tsxindex 1fc2ce0eb9d3..8f25edcbd323 100644--- a/frontend/src/scenes/settings/organization/aiConsentCopy.tsx+++ b/frontend/src/scenes/settings/organization/aiConsentCopy.tsx@@ -4,7 +4,7 @@ import { dayjs } from 'lib/dayjs'import { Link } from 'lib/lemon-ui/Link'export function getExternalAIProvidersTooltipTitle(): string {- return `As of ${dayjs().format('MMMM YYYY')}: Anthropic and OpenAI`+ return `As of ${dayjs().format('MMMM YYYY')}: Anthropic, OpenAI, and Alphabet`}export function AIHipaaDisclaimer(): JSX.Element {diff --git a/posthog/admin/admins/organization_admin.py b/posthog/admin/admins/organization_admin.pyindex 2e54c1d033de..d436295da6ab 100644--- a/posthog/admin/admins/organization_admin.py+++ b/posthog/admin/admins/organization_admin.py@@ -158,6 +158,7 @@ class OrganizationAdmin(admin.ModelAdmin):"is_hipaa","is_platform","members_can_invite",+ "is_ai_data_processing_approved","is_ai_training_opted_in","is_ai_training_locked","is_ai_training_cta_shown",diff --git a/posthog/email.py b/posthog/email.pyindex c4844a6b046e..864ecc7d63a4 100644--- a/posthog/email.py+++ b/posthog/email.py@@ -121,6 +121,7 @@ CUSTOMER_IO_TEMPLATE_ID_MAP = {"proxy_provisioned": "64","delegation_invite": "66","provisioning_welcome": "67",+ "baa_signed_ai_disabled": "68",}diff --git a/posthog/migrations/1177_alter_organization_is_ai_data_processing_approved.py b/posthog/migrations/1177_alter_organization_is_ai_data_processing_approved.pynew file mode 100644index 000000000000..a8442b0f14f9--- /dev/null+++ b/posthog/migrations/1177_alter_organization_is_ai_data_processing_approved.py@@ -0,0 +1,17 @@+# Generated by Django 5.2.14 on 2026-05-22 17:48++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("posthog", "1176_migrate_web_analytics_models"),+ ]++ operations = [+ migrations.AlterField(+ model_name="organization",+ name="is_ai_data_processing_approved",+ field=models.BooleanField(blank=True, default=True, null=True),+ ),+ ]diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txtindex 3f671bfe9ff6..a64b8f7e879c 100644--- a/posthog/migrations/max_migration.txt+++ b/posthog/migrations/max_migration.txt@@ -1 +1 @@-1176_migrate_web_analytics_models+1177_alter_organization_is_ai_data_processing_approveddiff --git a/posthog/models/organization.py b/posthog/models/organization.pyindex a780309271af..145741179a6b 100644--- a/posthog/models/organization.py+++ b/posthog/models/organization.py@@ -202,7 +202,7 @@ class Organization(ModelActivityMixin, UUIDTModel): # type: ignore[django-managis_member_join_email_enabled = models.BooleanField(default=True) # DEPRECATED in favor of User.partial_notification_settings- is_ai_data_processing_approved = models.BooleanField(null=True, blank=True, default=False)+ is_ai_data_processing_approved = models.BooleanField(null=True, blank=True, default=True)is_ai_training_opted_in = models.BooleanField(default=True,null=True,diff --git a/posthog/templates/email/baa_signed_ai_disabled.html b/posthog/templates/email/baa_signed_ai_disabled.htmlnew file mode 100644index 000000000000..f0df13e2869e--- /dev/null+++ b/posthog/templates/email/baa_signed_ai_disabled.html@@ -0,0 +1,20 @@+{% extends "email/base.html" %}+{% block section %}+<h1>AI features have been disabled for {{ organization_name }}</h1>+<p>+ Thanks for signing the Business Associate Agreement ("BAA") with PostHog.+</p>+<p>+ Heads up: the BAA does not cover the third-party AI services PostHog uses (currently Anthropic, OpenAI, and+ Alphabet). To keep your organization's data out of those AI subprocessors by default, we've automatically turned+ off AI features that use them for <strong>{{ organization_name }}</strong>.+</p>+<p>+ If your team still wants to use these AI features for workflows that do <em>not</em> involve Protected Health+ Information ("PHI"), an organization admin can re-enable them at any time. You remain responsible for ensuring+ your use complies with applicable laws and regulations.+</p>+<div class="mb mt text-center">+ <a class="button primary" href="{{ ai_settings_url }}">Open AI settings</a>+</div>+{% endblock %}diff --git a/products/legal_documents/backend/facade/api.py b/products/legal_documents/backend/facade/api.pyindex e25e73ad69a5..c7baffe06b3c 100644--- a/products/legal_documents/backend/facade/api.py+++ b/products/legal_documents/backend/facade/api.py@@ -156,5 +156,6 @@ def mark_signed_by_pandadoc_document_id(if not logic.download_and_store_signed_pdf(document):raise LegalDocumentDownloadFailed(f"Failed to retrieve signed PDF for legal_document {document.id}")document = logic.mark_document_signed(document)+ logic.apply_baa_signed_side_effects(document)logic.fire_legal_document_signed_event(document)return _to_dto(document)diff --git a/products/legal_documents/backend/logic/__init__.py b/products/legal_documents/backend/logic/__init__.pyindex 40e4fed9c0a6..860cfe29c7cb 100644--- a/products/legal_documents/backend/logic/__init__.py+++ b/products/legal_documents/backend/logic/__init__.py@@ -16,9 +16,10 @@ import structlogimport posthoganalyticsfrom posthog.cloud_utils import get_cached_instance_license+from posthog.email import EmailMessage, is_email_availablefrom posthog.event_usage import groupsfrom posthog.exceptions_capture import capture_exception-from posthog.models.organization import Organization+from posthog.models.organization import Organization, OrganizationMembershipfrom posthog.storage import object_storagefrom ee.billing.billing_manager import BillingManager@@ -129,6 +130,82 @@ def mark_document_signed(document: LegalDocument) -> LegalDocument:return document+# Customer.io template name for the email sent to org owners when we auto opt+# them out of AI data processing because they signed a BAA. Wired through+# CUSTOMER_IO_TEMPLATE_ID_MAP in posthog/email.py.+BAA_SIGNED_AI_DISABLED_TEMPLATE = "baa_signed_ai_disabled"+++def apply_baa_signed_side_effects(document: LegalDocument) -> None:+ """+ When a BAA is signed, opt the organization out of AI data processing and+ notify its owners. The BAA does not cover third-party AI subprocessors, so+ we fail safe to opt-out — owners can re-enable from settings if they want+ AI features for non-PHI workflows.++ Best-effort: any failure here is logged but does not roll back the BAA+ signature itself (PandaDoc has already collected it).+ """+ if document.document_type != DocumentType.BAA:+ return++ organization = document.organization+ try:+ if organization.is_ai_data_processing_approved is not False:+ organization.is_ai_data_processing_approved = False+ organization.save(update_fields=["is_ai_data_processing_approved"])+ except Exception as exc:+ logger.exception("legal_document_baa_opt_out_failed", document_id=str(document.id), error=str(exc))+ capture_exception(exc, additional_properties={"legal_document_id": str(document.id)})+ return++ _send_baa_signed_ai_disabled_email(organization, document)+++def _send_baa_signed_ai_disabled_email(organization: Organization, document: LegalDocument) -> None:+ if not is_email_available():+ return++ owner_users = [+ membership.user+ for membership in organization.memberships.filter(level=OrganizationMembership.Level.OWNER).select_related(+ "user"+ )+ if membership.user and membership.user.email+ ]+ if not owner_users:+ return++ try:+ message = EmailMessage(+ campaign_key=f"baa_signed_ai_disabled_{document.id}",+ template_name=BAA_SIGNED_AI_DISABLED_TEMPLATE,+ subject=f"AI features have been disabled for {organization.name}",+ template_context={+ "organization_name": organization.name,+ "ai_settings_url": f"{settings.SITE_URL}/settings/organization-details#organization-ai-consent",+ },+ use_http=True,+ )+ for user in owner_users:+ message.add_user_recipient(user)+ message.send(send_async=True)+ except Exception as exc:+ logger.exception(+ "legal_document_baa_email_failed",+ document_id=str(document.id),+ organization_id=str(organization.id),+ error=str(exc),+ )+ capture_exception(+ exc,+ additional_properties={+ "legal_document_id": str(document.id),+ "organization_id": str(organization.id),+ },+ )++# Short-enough that leaked URLs stop working on a human timescale, long enough# that slow network conditions or a distracted user can still complete the# download without the presigned URL expiring mid-stream.