Skip to content

: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.

chore(data-modeling): remove data-modeling-semantic-enrichment flag (#69772)

Thiago Salvatore74ffde123b4c
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index fec89ef28f39..993c83f018bc 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -282,7 +282,6 @@ export const FEATURE_FLAGS = {
DASHBOARDS_LIST_VIEW: 'dashboards-list-view', // owner: @vdekrijger #team-product-analytics multivariate=control,tree
DATA_MODELING_BACKEND_V2: 'data-modeling-backend-v2', // owner: #team-data-modeling
DATA_MODELING_MULTI_DAG: 'data-modeling-multi-dag', // owner: #team-data-modeling
- DATA_MODELING_SEMANTIC_ENRICHMENT: 'data-modeling-semantic-enrichment', // owner: #team-data-modeling
DATA_MODELING_TAB: 'data-modeling-tab', // owner: #team-data-modeling
DATA_WAREHOUSE_COLUMN_STATISTICS: 'data-warehouse-column-statistics', // owner: #team-warehouse-sources
DATA_WAREHOUSE_CUSTOM_SOURCE_AI_BUILDER: 'dwh-custom-source-ai-builder', // owner: #team-warehouse-sources
diff --git a/posthog/temporal/data_modeling/activities/succeed_materialization.py b/posthog/temporal/data_modeling/activities/succeed_materialization.py
index c5202e958191..87cad6108074 100644
--- a/posthog/temporal/data_modeling/activities/succeed_materialization.py
+++ b/posthog/temporal/data_modeling/activities/succeed_materialization.py
@@ -62,8 +62,8 @@ def _view_enrichment_needed(node: Node | None) -> tuple[bool, str | None]:
return False, str(node.saved_query_id)
if compute_enrichment_hash(saved_query) == saved_query.semantic_enrichment_hash:
return False, str(node.saved_query_id)
- # Gate on the flag + AI-processing approval before enqueuing, so a disabled team's re-materialization
- # never creates enrichment workflow work. The child activity re-checks both as the source of truth.
+ # Gate on AI-processing approval before enqueuing, so a non-consented team's re-materialization
+ # never creates enrichment workflow work. The child activity re-checks it as the source of truth.
if not enrichment_gates_pass(saved_query):
return False, str(node.saved_query_id)
return True, str(node.saved_query_id)
diff --git a/posthog/temporal/tests/data_modeling/test_materialize_view_activities.py b/posthog/temporal/tests/data_modeling/test_materialize_view_activities.py
index 96a9f04c6b7f..d8ec0e621676 100644
--- a/posthog/temporal/tests/data_modeling/test_materialize_view_activities.py
+++ b/posthog/temporal/tests/data_modeling/test_materialize_view_activities.py
@@ -632,29 +632,10 @@ class TestSucceedMaterializationActivity:
row_count=1,
duration_seconds=1.0,
)
- with unittest.mock.patch(
- "products.data_modeling.backend.logic.enrich_view_semantics.enrichment_enabled", return_value=True
- ):
- result = await activity_environment.run(succeed_materialization_activity, inputs)
+ result = await activity_environment.run(succeed_materialization_activity, inputs)
assert result.enrichment_needed is True
assert result.saved_query_id == str(anode.saved_query_id)
- async def test_no_enrichment_when_flag_disabled(self, activity_environment, ateam, anode, ajob, adag):
- # A changed view must not signal enrichment when the feature flag is off, even with no stored hash.
- inputs = SucceedMaterializationInputs(
- team_id=ateam.pk,
- node_id=str(anode.id),
- dag_id=str(adag.id),
- job_id=str(ajob.id),
- row_count=1,
- duration_seconds=1.0,
- )
- with unittest.mock.patch(
- "products.data_modeling.backend.logic.enrich_view_semantics.enrichment_enabled", return_value=False
- ):
- result = await activity_environment.run(succeed_materialization_activity, inputs)
- assert result.enrichment_needed is False
-
async def test_no_enrichment_when_hash_matches(self, activity_environment, ateam, anode, ajob, adag, asaved_query):
# A steady-state re-materialization (stored hash still current) must not spawn an enrichment child.
await database_sync_to_async(DataWarehouseSavedQuery.objects.filter(id=asaved_query.id).update)(
diff --git a/products/data_modeling/backend/logic/enrich_view_semantics.py b/products/data_modeling/backend/logic/enrich_view_semantics.py
index 6992d46ca27f..1d0fe86ab7bc 100644
--- a/products/data_modeling/backend/logic/enrich_view_semantics.py
+++ b/products/data_modeling/backend/logic/enrich_view_semantics.py
@@ -31,7 +31,6 @@ from posthog.llm.semantic_enrichment import (
MAX_PROMPT_CHARS,
bound_prompt_over_columns,
collapse_untrusted,
- enrichment_enabled,
generate_json_completion,
get_team_business_context,
upsert_column_annotation,
@@ -48,7 +47,6 @@ from products.warehouse_sources.backend.facade.models import DataWarehouseTable,
logger = structlog.get_logger(__name__)
-VIEW_ENRICHMENT_FEATURE_FLAG = "data-modeling-semantic-enrichment"
# Reuse the warehouse gateway product tag — no new llm-gateway config/deploy needed. Telemetry (below)
# distinguishes the two surfaces, and billing can split later if it ever needs to.
GATEWAY_PRODUCT: Product = "warehouse_semantic_enrichment"
@@ -313,8 +311,6 @@ def enrich_view_semantics_sync(team_id: int, saved_query_id: str) -> dict[str, A
log.info("view_enrichment.skipped", reason=reason)
return {"status": "skipped", "reason": reason}
- if not enrichment_enabled(team, VIEW_ENRICHMENT_FEATURE_FLAG):
- return skip("flag_disabled")
# Respect the org's AI data-processing opt-out: this ships view metadata and core memory to the LLM.
if team.organization.is_ai_data_processing_approved is not True:
return skip("ai_data_processing_not_approved")
@@ -446,23 +442,19 @@ def _upsert(saved_query: DataWarehouseSavedQuery, team_id: int, column_name: str
def enrichment_gates_pass(saved_query: DataWarehouseSavedQuery) -> bool:
- """Feature-flag + AI-processing-approval gate shared by the save- and materialization-dispatch paths.
+ """AI-processing-approval gate shared by the save- and materialization-dispatch paths.
- Both paths use this so a team where enrichment is off (or AI processing isn't approved) never enqueues
- a workflow. The activity re-checks the same gates as the source of truth.
+ Both paths use this so a team that hasn't approved AI processing never enqueues a workflow. The
+ activity re-checks the same gate as the source of truth.
"""
- team = saved_query.team
- return (
- enrichment_enabled(team, VIEW_ENRICHMENT_FEATURE_FLAG)
- and team.organization.is_ai_data_processing_approved is True
- )
+ return saved_query.team.organization.is_ai_data_processing_approved is True
def view_ready_for_enrichment(saved_query: DataWarehouseSavedQuery) -> bool:
"""The content half of the dispatch decision: enrichable view whose descriptions could have changed.
Not deleted/test/managed, has a query and columns, and its enrichment hash differs from the stored one.
- The team half (flag + AI consent) is `enrichment_gates_pass`. Split out so a backfill can check the
+ The team half (AI consent) is `enrichment_gates_pass`. Split out so a backfill can check the
team gate once per team and this once per view.
"""
if saved_query.deleted or saved_query.is_test or saved_query.managed_viewset_id:
diff --git a/products/data_modeling/backend/tests/test_backfill_view_semantic_enrichment.py b/products/data_modeling/backend/tests/test_backfill_view_semantic_enrichment.py
index 0fcbbf8fcbfd..f793b286266e 100644
--- a/products/data_modeling/backend/tests/test_backfill_view_semantic_enrichment.py
+++ b/products/data_modeling/backend/tests/test_backfill_view_semantic_enrichment.py
@@ -10,7 +10,6 @@ from parameterized import parameterized
from posthog.models import Organization, Team
-from products.data_modeling.backend.logic import enrich_view_semantics as enrich
from products.data_modeling.backend.logic.enrich_view_semantics import compute_enrichment_hash
from products.data_modeling.backend.models.datawarehouse_managed_viewset import DataWarehouseManagedViewSet
from products.data_modeling.backend.models.datawarehouse_saved_query import DataWarehouseSavedQuery
@@ -42,11 +41,8 @@ def _saved_query(team: Team, **extra: Any) -> DataWarehouseSavedQuery:
)
-def _run(*, enabled: bool = True, **options: Any) -> tuple[Any, str]:
- with (
- patch.object(enrich, "enrichment_enabled", return_value=enabled),
- patch(DISPATCH) as dispatch,
- ):
+def _run(**options: Any) -> tuple[Any, str]:
+ with patch(DISPATCH) as dispatch:
out = StringIO()
call_command(COMMAND, sleep=0, stdout=out, **options)
return dispatch, out.getvalue()
@@ -100,15 +96,14 @@ class TestBackfillViewSemanticEnrichment:
@parameterized.expand(
[
- ("flag_disabled", False, {}),
- ("deleted", True, {"deleted": True}),
- ("is_test", True, {"is_test": True}),
- ("empty_columns", True, {"columns": {}}),
- ("already_enriched", True, {"enriched": True}),
- ("managed_viewset", True, {"managed": True}),
+ ("deleted", {"deleted": True}),
+ ("is_test", {"is_test": True}),
+ ("empty_columns", {"columns": {}}),
+ ("already_enriched", {"enriched": True}),
+ ("managed_viewset", {"managed": True}),
]
)
- def test_skips_gated_or_ineligible_views(self, _name, enabled, mods):
+ def test_skips_gated_or_ineligible_views(self, _name, mods):
team = _team()
if mods.pop("managed", False):
mods["managed_viewset"] = DataWarehouseManagedViewSet.objects.create(
@@ -121,6 +116,6 @@ class TestBackfillViewSemanticEnrichment:
semantic_enrichment_hash=compute_enrichment_hash(sq)
)
- dispatch, _ = _run(team_ids=[team.id], live_run=True, enabled=enabled)
+ dispatch, _ = _run(team_ids=[team.id], live_run=True)
dispatch.assert_not_called()
diff --git a/products/data_modeling/backend/tests/test_enrich_view_semantics.py b/products/data_modeling/backend/tests/test_enrich_view_semantics.py
index 3dc49bfca7b9..ea5183ee8cd2 100644
--- a/products/data_modeling/backend/tests/test_enrich_view_semantics.py
+++ b/products/data_modeling/backend/tests/test_enrich_view_semantics.py
@@ -60,10 +60,9 @@ def _annotations(team: Team, sq: DataWarehouseSavedQuery) -> dict[str, DataWareh
}
-def _run(team, sq, *, generated, enabled=True, lineage=None, row_sample=None):
+def _run(team, sq, *, generated, lineage=None, row_sample=None):
"""Run the sync enrichment with the LLM + lineage/context boundaries mocked. Returns (result, mock_llm)."""
with (
- patch.object(enrich, "enrichment_enabled", return_value=enabled),
patch.object(enrich, "get_team_business_context", return_value=""),
patch.object(enrich, "_gather_lineage", return_value=lineage or []),
patch.object(enrich, "_get_row_sample", return_value=row_sample or []),
@@ -168,7 +167,6 @@ class TestEnrichViewSemanticsSync:
@parameterized.expand(
[
- ("flag_disabled", "flag_disabled"),
("ai_data_processing_not_approved", "ai_data_processing_not_approved"),
("deleted", "deleted"),
("is_test", "is_test"),
@@ -179,14 +177,11 @@ class TestEnrichViewSemanticsSync:
)
def test_gates_skip_without_calling_llm(self, condition, expected_reason):
team = _team()
- enabled = True
columns = _columns("amount")
query = "SELECT amount FROM events"
extra: dict[str, Any] = {}
- if condition == "flag_disabled":
- enabled = False
- elif condition == "ai_data_processing_not_approved":
+ if condition == "ai_data_processing_not_approved":
team.organization.is_ai_data_processing_approved = False
team.organization.save()
elif condition == "deleted":
@@ -203,7 +198,7 @@ class TestEnrichViewSemanticsSync:
columns = {}
sq = _saved_query(team, columns=columns, query=query, **extra)
- result, mock_llm = _run(team, sq, generated={"view_description": "x", "columns": {}}, enabled=enabled)
+ result, mock_llm = _run(team, sq, generated={"view_description": "x", "columns": {}})
mock_llm.assert_not_called()
assert result["status"] == "skipped"
@@ -307,7 +302,6 @@ class TestMaybeDispatchEnrichment:
assert compute_enrichment_hash(sq) != sq.semantic_enrichment_hash
with (
- patch.object(enrich, "enrichment_enabled", return_value=True),
patch("django.db.transaction.on_commit") as on_commit,
patch.object(enrich, "_start_enrichment_workflow") as start_workflow,
):
@@ -318,19 +312,15 @@ class TestMaybeDispatchEnrichment:
start_workflow.assert_called_once_with(sq.team_id, str(sq.id))
- @parameterized.expand([("flag_disabled", False, True), ("ai_not_approved", True, False)])
- def test_skips_dispatch_when_gated(self, _name, flag_enabled, approved):
- # A changed view still must not enqueue a workflow when enrichment is off or AI processing isn't
- # approved — the same gates the activity enforces.
+ def test_skips_dispatch_when_ai_not_approved(self):
+ # A changed view still must not enqueue a workflow when AI processing isn't approved — the same
+ # gate the activity enforces.
team = _team()
- team.organization.is_ai_data_processing_approved = approved
+ team.organization.is_ai_data_processing_approved = False
team.organization.save()
sq = _saved_query(team, columns=_columns("amount"), query="SELECT amount FROM events")
- with (
- patch.object(enrich, "enrichment_enabled", return_value=flag_enabled),
- patch("django.db.transaction.on_commit") as on_commit,
- ):
+ with patch("django.db.transaction.on_commit") as on_commit:
maybe_dispatch_enrichment(sq)
on_commit.assert_not_called()
@@ -341,20 +331,14 @@ class TestDispatchOnSave:
def test_creating_view_dispatches_once(self, django_capture_on_commit_callbacks):
team = _team()
- with (
- patch.object(enrich, "enrichment_enabled", return_value=True),
- patch.object(enrich, "_start_enrichment_workflow") as mock_start,
- ):
+ with patch.object(enrich, "_start_enrichment_workflow") as mock_start:
with django_capture_on_commit_callbacks(execute=True):
sq = _saved_query(team, columns=_columns("amount"), query="SELECT amount FROM events")
mock_start.assert_called_once_with(team.id, str(sq.id))
def test_status_only_save_does_not_dispatch(self, django_capture_on_commit_callbacks):
team = _team()
- with (
- patch.object(enrich, "enrichment_enabled", return_value=True),
- patch.object(enrich, "_start_enrichment_workflow") as mock_start,
- ):
+ with patch.object(enrich, "_start_enrichment_workflow") as mock_start:
sq = _saved_query(team, columns=_columns("amount"), query="SELECT amount FROM events")
mock_start.reset_mock()
with django_capture_on_commit_callbacks(execute=True):
@@ -364,10 +348,7 @@ class TestDispatchOnSave:
def test_unchanged_hash_save_does_not_dispatch(self, django_capture_on_commit_callbacks):
team = _team()
- with (
- patch.object(enrich, "enrichment_enabled", return_value=True),
- patch.object(enrich, "_start_enrichment_workflow") as mock_start,
- ):
+ with patch.object(enrich, "_start_enrichment_workflow") as mock_start:
sq = _saved_query(team, columns=_columns("amount"), query="SELECT amount FROM events")
DataWarehouseSavedQuery.objects.filter(id=sq.id).update(
semantic_enrichment_hash=compute_enrichment_hash(sq)