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.

feat(warehouse_sources): add BuildBetter tag and type tables (#101612)

Tom Owers5fbd46a2eccb
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index 864e71171562..7e956c146a15 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -1072,7 +1072,7 @@ Note: Pulled the raw API Blueprint (384KB) behind the Apiary docs. It self-decla
## BuildBetter — gaps
-Today (8): `companies`, `documents`, `extraction_topics`, `extractions`, `interview_attendees`, `interview_sentences`, `interviews`, `persons`
+Today (11): `companies`, `documents`, `extraction_topics`, `extraction_types`, `extractions`, `interview_attendees`, `interview_sentences`, `interview_tags`, `interview_types`, `interviews`, `persons`
Diffed against: <https://docs.buildbetter.ai/pages/api/data-access.md>
@@ -1080,9 +1080,9 @@ Diffed against: <https://docs.buildbetter.ai/pages/api/data-access.md>
- [x] `interview.attendees (attendee/person join)` — membership table linking interviews we already sync to persons we already sync — currently no way to join calls to participants (high)
- [x] `interview.sentences / transcript_segments (REST /recordings/{id}/transcript)` — sentence-level transcript rows with speaker and timing; the raw text behind every call (high)
- [x] `extraction.topics (topic)` — lookup table resolving the topic IDs attached to extractions we already sync (high)
-- [ ] `extraction.types / interview.type (call and signal type)` — lookup tables resolving the type IDs carried on interviews and extractions (high)
-- [ ] `tag (interview tags)` — lookup for the tag references on calls, needed for any segmentation by tag (medium)
-- [ ] `recordings` — REST recording resource with public UUID, duration, source, and transcript_status — the supported successor to the interview asset fields (medium)
+- [x] `extraction.types / interview.type (call and signal type)` — lookup tables resolving the type IDs carried on interviews and extractions (high)
+- [x] `tag (interview tags)` — lookup for the tag references on calls, needed for any segmentation by tag (medium)
+- [ ] `recordings` — REST recording resource with public UUID, duration, source, and transcript_status — the supported successor to the interview asset fields (medium). Deferred: this resource only exists on the REST API at `https://api.buildbetter.app/v3/rest`, which this source does not talk to — it is pinned to GraphQL v1. Adding it means adding a second vendor API version, which is the `warehouse-source-new-version` workflow. The recording fields themselves (`asset_url`, `asset_duration_seconds`, `asset_is_audio`, `transcript_status`) already sync on `interviews`; the list projection carries neither duration nor transcript status.
Note: PostHog's registered api_docs_url (https://docs.buildbetter.app/) no longer resolves — DNS fails. The live docs are at https://docs.buildbetter.ai (llms.txt index at https://docs.buildbetter.ai/llms.txt). The GraphQL endpoint (api.buildbetter.app/v1/graphql) that this source uses is explicitly deprecated for customer integrations in favor of a REST API at https://api.buildbetter.app/v3/rest; unauthenticated introspection returns 'no_queries_available', so the resource list came from the docs, not the schema. Worth a follow-up to re-point the source at REST before GraphQL is retired.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/buildbetter.py b/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/buildbetter.py
index 106bf6f8d4f6..b93e78e893a0 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/buildbetter.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/buildbetter.py
@@ -110,11 +110,18 @@ def _execute_query(
return payload
+def _nested_items(nested: BuildBetterNestedConfig, parent: dict) -> list[dict]:
+ value = parent.get(nested.nested_field)
+ if not nested.single:
+ return value or []
+ return [{f"{nested.unwrap_prefix}{key}": item for key, item in value.items()}] if value else []
+
+
def _flatten_nested_rows(nested: BuildBetterNestedConfig, parent_rows: list[dict]) -> list[dict]:
rows: list[dict] = []
for parent in parent_rows:
parent_columns = {column: parent.get(parent_field) for parent_field, column in nested.parent_columns.items()}
- for index, child in enumerate(parent.get(nested.nested_field) or []):
+ for index, child in enumerate(_nested_items(nested, parent)):
row = dict(child)
if nested.unwrap_field:
inner = row.pop(nested.unwrap_field, None)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/canonical_descriptions.py
index 9eefa9150abf..af5814ac61eb 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/canonical_descriptions.py
@@ -67,6 +67,29 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"end_sec": "End time of the sentence within the recording, in seconds.",
},
},
+ "interview_tags": {
+ "description": "A tag applied to a call, resolving the tag references carried on interviews.",
+ "docs_url": "https://docs.buildbetter.ai/pages/api/data-access.md",
+ "columns": {
+ "interview_id": "Identifier of the interview the tag is applied to.",
+ "interview_created_at": "Time at which the interview record was created.",
+ "interview_updated_at": "Time at which the interview record was last updated.",
+ "tag_id": "Unique identifier of the tag.",
+ "tag_name": "Name of the tag.",
+ "tag_color": "Display color of the tag.",
+ },
+ },
+ "interview_types": {
+ "description": "The call type of an interview, such as a demo call or a user interview.",
+ "docs_url": "https://docs.buildbetter.ai/pages/api/data-access.md",
+ "columns": {
+ "interview_id": "Identifier of the interview the call type is assigned to.",
+ "interview_created_at": "Time at which the interview record was created.",
+ "interview_updated_at": "Time at which the interview record was last updated.",
+ "type_id": "Unique identifier of the call type.",
+ "type_name": "Name of the call type.",
+ },
+ },
"extractions": {
"description": "An AI-extracted insight from an interview — a quote with sentiment, topics, and context.",
"docs_url": "https://docs.buildbetter.app/",
@@ -98,6 +121,16 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"topic_text": "Text of the topic.",
},
},
+ "extraction_types": {
+ "description": "A signal type assigned to an extraction, such as a pain point or a feature request.",
+ "docs_url": "https://docs.buildbetter.ai/pages/api/data-access.md",
+ "columns": {
+ "extraction_id": "Identifier of the extraction the signal type is assigned to.",
+ "extraction_created_at": "Time at which the extraction was created.",
+ "type_id": "Unique identifier of the signal type.",
+ "type_name": "Name of the signal type.",
+ },
+ },
"documents": {
"description": "An AI-generated document in BuildBetter, produced from calls or folders.",
"docs_url": "https://docs.buildbetter.ai/pages/api/data-access.md",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/queries.py b/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/queries.py
index 16491fc28c5f..654fb008bc1f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/queries.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/queries.py
@@ -209,6 +209,49 @@ query PaginatedInterviewSentences($limit: Int!, $offset: Int!, $where: interview
}
}"""
+INTERVIEW_TAGS_QUERY = """
+query PaginatedInterviewTags($limit: Int!, $offset: Int!, $where: interview_bool_exp) {
+ interview(limit: $limit, offset: $offset, order_by: {updated_at: asc}, where: $where) {
+ id
+ created_at
+ updated_at
+ tags {
+ tag {
+ id
+ name
+ color
+ }
+ }
+ }
+}"""
+
+INTERVIEW_TYPES_QUERY = """
+query PaginatedInterviewTypes($limit: Int!, $offset: Int!, $where: interview_bool_exp) {
+ interview(limit: $limit, offset: $offset, order_by: {updated_at: asc}, where: $where) {
+ id
+ created_at
+ updated_at
+ type {
+ id
+ name
+ }
+ }
+}"""
+
+EXTRACTION_TYPES_QUERY = """
+query PaginatedExtractionTypes($limit: Int!, $offset: Int!, $where: extraction_bool_exp) {
+ extraction(limit: $limit, offset: $offset, order_by: {created_at: asc}, where: $where) {
+ id
+ created_at
+ types {
+ type {
+ id
+ name
+ }
+ }
+ }
+}"""
+
EXTRACTION_TOPICS_QUERY = """
query PaginatedExtractionTopics($limit: Int!, $offset: Int!, $where: extraction_bool_exp) {
extraction(limit: $limit, offset: $offset, order_by: {created_at: asc}, where: $where) {
@@ -281,8 +324,11 @@ QUERIES: dict[str, str] = {
"interviews": INTERVIEWS_QUERY,
"interview_attendees": INTERVIEW_ATTENDEES_QUERY,
"interview_sentences": INTERVIEW_SENTENCES_QUERY,
+ "interview_tags": INTERVIEW_TAGS_QUERY,
+ "interview_types": INTERVIEW_TYPES_QUERY,
"extractions": EXTRACTIONS_QUERY,
"extraction_topics": EXTRACTION_TOPICS_QUERY,
+ "extraction_types": EXTRACTION_TYPES_QUERY,
"documents": DOCUMENTS_QUERY,
"persons": PERSONS_QUERY,
"companies": COMPANIES_QUERY,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/settings.py
index db2d4d68fdf3..8c9bad5bf069 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/settings.py
@@ -17,6 +17,8 @@ EXTRACTION_ID = "extraction_id"
EXTRACTION_CREATED_AT = "extraction_created_at"
SENTENCE_INDEX = "sentence_index"
TOPIC_ID = "topic_id"
+TAG_ID = "tag_id"
+TYPE_ID = "type_id"
BUILDBETTER_API_URL = "https://api.buildbetter.app/v1/graphql"
BUILDBETTER_DEFAULT_PAGE_SIZE = 1000
@@ -43,9 +45,9 @@ INCREMENTAL_EXTRACTION_CREATED_AT = _incremental_datetime_field(EXTRACTION_CREAT
class BuildBetterNestedConfig:
"""A table built from a nested relation of a parent query, one row per nested item.
- BuildBetter exposes attendees, transcript sentences and extraction topics only as relations
- of `interview` / `extraction`, so these tables page their parent query and flatten the
- relation, carrying the parent's identifier and timestamps onto every row.
+ BuildBetter exposes attendees, transcript sentences, tags and the topic and type lookups only
+ as relations of `interview` / `extraction`, so these tables page their parent query and
+ flatten the relation, carrying the parent's identifier and timestamps onto every row.
"""
nested_field: str
@@ -53,6 +55,9 @@ class BuildBetterNestedConfig:
unwrap_field: str | None = None
unwrap_prefix: str = ""
index_column: str | None = None
+ # An object relationship resolves to one record rather than a list, so the record's own
+ # fields become the row and `unwrap_prefix` applies to them directly.
+ single: bool = False
@dataclass(frozen=True)
@@ -107,6 +112,32 @@ BUILDBETTER_ENDPOINTS: dict[str, BuildBetterEndpointConfig] = {
),
partition_keys=[INTERVIEW_CREATED_AT],
),
+ "interview_tags": BuildBetterEndpointConfig(
+ graphql_query_name="interview",
+ incremental_fields=INCREMENTAL_INTERVIEW_UPDATED_AT,
+ page_size=500,
+ primary_keys=[INTERVIEW_ID, TAG_ID],
+ nested=BuildBetterNestedConfig(
+ nested_field="tags",
+ parent_columns=INTERVIEW_PARENT_COLUMNS,
+ unwrap_field="tag",
+ unwrap_prefix="tag_",
+ ),
+ partition_keys=[INTERVIEW_CREATED_AT],
+ ),
+ "interview_types": BuildBetterEndpointConfig(
+ graphql_query_name="interview",
+ incremental_fields=INCREMENTAL_INTERVIEW_UPDATED_AT,
+ page_size=500,
+ primary_keys=[INTERVIEW_ID, TYPE_ID],
+ nested=BuildBetterNestedConfig(
+ nested_field="type",
+ parent_columns=INTERVIEW_PARENT_COLUMNS,
+ unwrap_prefix="type_",
+ single=True,
+ ),
+ partition_keys=[INTERVIEW_CREATED_AT],
+ ),
"extractions": BuildBetterEndpointConfig(
graphql_query_name="extraction",
incremental_fields=INCREMENTAL_CREATED_AT,
@@ -125,6 +156,19 @@ BUILDBETTER_ENDPOINTS: dict[str, BuildBetterEndpointConfig] = {
),
partition_keys=[EXTRACTION_CREATED_AT],
),
+ "extraction_types": BuildBetterEndpointConfig(
+ graphql_query_name="extraction",
+ incremental_fields=INCREMENTAL_EXTRACTION_CREATED_AT,
+ page_size=500,
+ primary_keys=[EXTRACTION_ID, TYPE_ID],
+ nested=BuildBetterNestedConfig(
+ nested_field="types",
+ parent_columns={ID: EXTRACTION_ID, CREATED_AT: EXTRACTION_CREATED_AT},
+ unwrap_field="type",
+ unwrap_prefix="type_",
+ ),
+ partition_keys=[EXTRACTION_CREATED_AT],
+ ),
"documents": BuildBetterEndpointConfig(
graphql_query_name="document",
incremental_fields=INCREMENTAL_UPDATED_AT,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/test_buildbetter.py b/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/test_buildbetter.py
index eb7cd6cd4bd7..c740287b390c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/test_buildbetter.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/buildbetter/test_buildbetter.py
@@ -307,6 +307,89 @@ class TestNestedEndpoints:
},
],
),
+ (
+ "interview_tags",
+ "interview_tags",
+ {
+ "interview": [
+ {
+ "id": 6,
+ "created_at": "2026-01-01",
+ "updated_at": "2026-01-02",
+ "tags": [
+ {"tag": {"id": 20, "name": "Churn risk", "color": "#ff0000"}},
+ # A tag reference the API resolves to nothing has no key columns
+ {"tag": None},
+ ],
+ }
+ ]
+ },
+ [
+ {
+ "interview_id": 6,
+ "interview_created_at": "2026-01-01",
+ "interview_updated_at": "2026-01-02",
+ "tag_id": 20,
+ "tag_name": "Churn risk",
+ "tag_color": "#ff0000",
+ },
+ ],
+ ),
+ (
+ # An object relationship yields at most one row, built from the type's own fields
+ "interview_types",
+ "interview_types",
+ {
+ "interview": [
+ {
+ "id": 7,
+ "created_at": "2026-01-01",
+ "updated_at": "2026-01-02",
+ "type": {"id": 30, "name": "User interview"},
+ },
+ {"id": 8, "created_at": "2026-01-03", "updated_at": "2026-01-04", "type": None},
+ ]
+ },
+ [
+ {
+ "interview_id": 7,
+ "interview_created_at": "2026-01-01",
+ "interview_updated_at": "2026-01-02",
+ "type_id": 30,
+ "type_name": "User interview",
+ },
+ ],
+ ),
+ (
+ "extraction_types",
+ "extraction_types",
+ {
+ "extraction": [
+ {
+ "id": 9,
+ "created_at": "2026-01-05",
+ "types": [
+ {"type": {"id": 40, "name": "Pain point"}},
+ {"type": {"id": 41, "name": "Feature request"}},
+ ],
+ }
+ ]
+ },
+ [
+ {
+ "extraction_id": 9,
+ "extraction_created_at": "2026-01-05",
+ "type_id": 40,
+ "type_name": "Pain point",
+ },
+ {
+ "extraction_id": 9,
+ "extraction_created_at": "2026-01-05",
+ "type_id": 41,
+ "type_name": "Feature request",
+ },
+ ],
+ ),
(
"extraction_topics",
"extraction_topics",