: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(growth): read wizard AI SDK detection from its scan events (#115789)
Rafael Audibert86ef022338a5
diff --git a/products/growth/backend/enrichment/bridge.py b/products/growth/backend/enrichment/bridge.pyindex ba84cc2d5611..df8e4a67b545 100644--- a/products/growth/backend/enrichment/bridge.py+++ b/products/growth/backend/enrichment/bridge.py@@ -15,6 +15,8 @@ unreachable group store raises. Scoring an org on inputs we failed to fetch woulsilently-too-low score, which is worse than writing none — so callers degrade to writingfirmographics without a score on a raise, and get another chance at the delayed recheck.+The wizard input is true when a stored codebase scan of any of the org's projects finds one of+this module's LLM tool kinds, or when the organization group still carries the stamp older wizards set."""import dataclasses@@ -29,10 +31,43 @@ from posthog.models.team import Teamfrom posthog.utils import get_instance_regionfrom products.growth.backend.enrichment.writer import ORGANIZATION_GROUP_TYPE+from products.warehouse_sources.backend.facade.types import ExternalDataSourceType+from products.wizard.backend.facade import api as wizard_facadeCLAY_EST_REVENUE_PROPERTY = "icp_est_revenue"CLAY_COMPANY_TYPE_PROPERTY = "icp_company_type"+# Set by wizards before they reported scans to PostHog. Still read, so those orgs keep the input.WIZARD_AI_SDK_DETECTED_PROPERTY = "wizard_ai_sdk_detected"+# Tool kinds from the wizard's scan that mean the org builds with LLMs. This list is the scoring+# decision, so it lives here rather than in the wizard's tool catalog.+LLM_TOOL_KINDS: frozenset[ExternalDataSourceType] = frozenset(+ {+ ExternalDataSourceType.ANTHROPIC,+ ExternalDataSourceType.ASSEMBLYAI,+ ExternalDataSourceType.BROWSERBASE,+ ExternalDataSourceType.COHERE,+ ExternalDataSourceType.DEEPGRAM,+ ExternalDataSourceType.E2B,+ ExternalDataSourceType.ELEVENLABS,+ ExternalDataSourceType.FIRECRAWL,+ ExternalDataSourceType.FIREWORKSAI,+ ExternalDataSourceType.GROQ,+ ExternalDataSourceType.HELICONE,+ ExternalDataSourceType.HUGGINGFACE,+ ExternalDataSourceType.LANGSMITH,+ ExternalDataSourceType.LANGFUSE,+ ExternalDataSourceType.LLAMACLOUD,+ ExternalDataSourceType.MEM0,+ ExternalDataSourceType.MISTRALAI,+ ExternalDataSourceType.OPENAI,+ ExternalDataSourceType.OPENROUTER,+ ExternalDataSourceType.REPLICATE,+ ExternalDataSourceType.TOGETHERAI,+ ExternalDataSourceType.VELLUM,+ ExternalDataSourceType.WEIGHTSANDBIASES,+ ExternalDataSourceType.ZEP,+ }+)class OrganizationGroupTypeMissing(Exception):@@ -51,7 +86,7 @@ class ClayBridgeInputs:@frozenclass WizardBridgeInputs:- """The wizard's own AI-SDK detection stamp for one org. False when the wizard never reported it."""+ """Whether the wizard found an LLM SDK in one org's code. False when it never scanned."""ai_sdk_detected: bool = False@@ -87,7 +122,7 @@ def _organization_group_type_index(team: Team) -> int:def read_organization_bridge_inputs(*, organization_id: str) -> OrganizationBridgeInputs:- """Fetch score inputs from one organization-group read. Raises when the group store cannot be read."""+ """Fetch score inputs for one org. Raises when the group store or the wizard's scan store cannot be read."""# Clay only ever wrote to the US internal project, so outside US there is nothing to read —# skip the lookup entirely instead of querying a project the bridge never touched.if get_instance_region() != "US":@@ -100,16 +135,20 @@ def read_organization_bridge_inputs(*, organization_id: str) -> OrganizationBridgroup_type_index=_organization_group_type_index(team),group_key=organization_id,)+ properties = (group.group_properties or {}) if group is not None else {}+ wizard = WizardBridgeInputs(+ ai_sdk_detected=properties.get(WIZARD_AI_SDK_DETECTED_PROPERTY) is True+ or wizard_facade.organization_has_detected_tool(+ organization_id=organization_id, kinds=[kind.value for kind in LLM_TOOL_KINDS]+ )+ )if group is None:- return OrganizationBridgeInputs()+ return OrganizationBridgeInputs(wizard=wizard)- properties = group.group_properties or {}return OrganizationBridgeInputs(clay=ClayBridgeInputs(est_revenue=_numeric(properties.get(CLAY_EST_REVENUE_PROPERTY)),clay_processed=CLAY_COMPANY_TYPE_PROPERTY in properties,),- wizard=WizardBridgeInputs(- ai_sdk_detected=properties.get(WIZARD_AI_SDK_DETECTED_PROPERTY) is True,- ),+ wizard=wizard,)diff --git a/products/growth/backend/tests/test_enrichment_bridge.py b/products/growth/backend/tests/test_enrichment_bridge.pyindex bf88e226ac47..46eb0b2c8ee7 100644--- a/products/growth/backend/tests/test_enrichment_bridge.py+++ b/products/growth/backend/tests/test_enrichment_bridge.py@@ -17,7 +17,7 @@ _ORGANIZATION_GROUP_TYPES = [{"group_type": "organization", "group_type_index":class TestEnrichmentBridge(BaseTest):- def _read(self, group, group_types=_ORGANIZATION_GROUP_TYPES, region="US"):+ def _read(self, group, group_types=_ORGANIZATION_GROUP_TYPES, region="US", scan_found=False):with (patch("products.growth.backend.enrichment.bridge.get_instance_region", return_value=region),patch("products.growth.backend.enrichment.bridge.Team.objects.get", return_value=self.team),@@ -26,6 +26,10 @@ class TestEnrichmentBridge(BaseTest):return_value=group_types,),patch("products.growth.backend.enrichment.bridge.get_group_by_key", return_value=group) as get_group,+ patch(+ "products.growth.backend.enrichment.bridge.wizard_facade.organization_has_detected_tool",+ return_value=scan_found,+ ) as self.scan_lookup,):return read_organization_bridge_inputs(organization_id="org-1"), get_group@@ -85,9 +89,22 @@ class TestEnrichmentBridge(BaseTest):inputs, _ = self._read(Group(group_properties={"icp_est_revenue": raw}))assert inputs.clay.est_revenue == expected- def test_non_boolean_wizard_value_reads_as_false(self):- inputs, _ = self._read(Group(group_properties={"wizard_ai_sdk_detected": "true"}))- assert inputs.wizard == WizardBridgeInputs()+ @parameterized.expand(+ [+ ("stamp_only", Group(group_properties={"wizard_ai_sdk_detected": True}), False, True),+ ("scan_only", Group(group_properties={}), True, True),+ ("scan_with_no_group_yet", None, True, True),+ ("neither", Group(group_properties={}), False, False),+ ("non_boolean_stamp", Group(group_properties={"wizard_ai_sdk_detected": "true"}), False, False),+ ]+ )+ def test_wizard_input_combines_the_old_stamp_with_stored_scans(self, _name, group, scan_found, expected):+ inputs, _ = self._read(group, scan_found=scan_found)++ assert inputs.wizard == WizardBridgeInputs(ai_sdk_detected=expected)+ if self.scan_lookup.called:+ assert self.scan_lookup.call_args.kwargs["organization_id"] == "org-1"+ assert "OpenAI" in self.scan_lookup.call_args.kwargs["kinds"]def test_missing_organization_group_type_raises_rather_than_reading_as_absent(self):with self.assertRaises(OrganizationGroupTypeMissing):diff --git a/products/wizard/backend/facade/api.py b/products/wizard/backend/facade/api.pyindex 149b708cd00e..52137133e84b 100644--- a/products/wizard/backend/facade/api.py+++ b/products/wizard/backend/facade/api.py@@ -8,7 +8,7 @@ dataclasses. Never return ORM instances or import DRF.from __future__ import annotations-from collections.abc import AsyncIterator+from collections.abc import AsyncIterator, Collectionfrom contextlib import asynccontextmanagerfrom typing import Anyfrom uuid import UUID@@ -57,6 +57,11 @@ def record_scan(params: RecordWizardScanInput) -> WizardScanResult:return scans.record_scan(params)+def organization_has_detected_tool(*, organization_id: str, kinds: Collection[str]) -> bool:+ """Whether the latest scan of any workspace in the organization still finds one of `kinds`."""+ return scans.organization_has_detected_tool(organization_id=organization_id, kinds=kinds)++def get_tool_catalog_json() -> bytes:return tool_catalog_json()diff --git a/products/wizard/backend/logic/scans.py b/products/wizard/backend/logic/scans.pyindex 94e2ecfc75e4..0e78b7b0489d 100644--- a/products/wizard/backend/logic/scans.py+++ b/products/wizard/backend/logic/scans.py@@ -1,3 +1,4 @@+from collections.abc import Collectionfrom datetime import datetimefrom django.db import connection, transaction@@ -222,3 +223,12 @@ def _report_competitor_changes(scan: WizardScan, changes: _ScanChanges) -> None:"competes_with": list(removal.competes_with),},)+++def organization_has_detected_tool(*, organization_id: str, kinds: Collection[str]) -> bool:+ # Reads across teams on purpose: the question is whether any project in the organization uses the tool.+ return (+ WizardDetectedTool.objects.unscoped()+ .filter(team__organization_id=organization_id, kind__in=kinds, removed_at__isnull=True)+ .exists()+ )diff --git a/products/wizard/backend/tests/scans/test_logic.py b/products/wizard/backend/tests/scans/test_logic.pyindex beb1bea68f4e..857026a3382a 100644--- a/products/wizard/backend/tests/scans/test_logic.py+++ b/products/wizard/backend/tests/scans/test_logic.py@@ -192,3 +192,28 @@ def test_competitor_events_belong_to_the_scanned_projects_organization(_scan(team, "s1", 0, ["Amplitude"], created_by_id=user.id)assert capture.call_args.kwargs["groups"]["organization"] == str(team.organization_id)+++ "scans, same_organization, expected",+ [+ ([("s1", 0, ["Stripe", "OpenAI"])], True, True),+ ([("s1", 0, ["OpenAI"]), ("s2", 1, ["Stripe"])], True, False),+ ([("s1", 0, ["Stripe"])], True, False),+ ([("s1", 0, ["OpenAI"])], False, False),+ ],+ ids=["active_in_another_project", "removed_by_a_later_scan", "other_kind", "other_organization"],+)+def test_organization_has_detected_tool_reads_every_project_in_the_organization(+ team: Team, scans: list[tuple[str, int, list[str]]], same_organization: bool, expected: bool+) -> None:+ organization = team.organization if same_organization else Organization.objects.create(name="Other organization")+ scanned_team = Team.objects.create_with_data(initiating_user=None, organization=organization)+ for session_id, hours, kinds in scans:+ _scan(scanned_team, session_id, hours, kinds)++ assert (+ wizard_facade.organization_has_detected_tool(organization_id=str(team.organization_id), kinds=["OpenAI"])+ is expected+ )diff --git a/tach.toml b/tach.tomlindex 7802c73e9fab..1f84fc936d1f 100644--- a/tach.toml+++ b/tach.toml@@ -528,6 +528,7 @@ depends_on = ["ee","posthog", "products.access_control","products.signals", "products.tasks",+ "products.warehouse_sources", "products.wizard",]layer = "modules"