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(user-interviews): drop interviewee_cohort, snapshot audience at create time (#58635)

Paul D'Ambra488772d4d54a
diff --git a/products/user_interviews/backend/api.py b/products/user_interviews/backend/api.py
index b2c562659d56..dcb3e516e666 100644
--- a/products/user_interviews/backend/api.py
+++ b/products/user_interviews/backend/api.py
@@ -243,20 +243,15 @@ class UserInterviewViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):
class UserInterviewTopicSerializer(serializers.ModelSerializer):
created_by = UserBasicSerializer(read_only=True)
- interviewee_cohort = serializers.IntegerField(
- required=False,
- allow_null=True,
- help_text="Optional cohort ID identifying who to target. Not enforced as a foreign key.",
- )
interviewee_emails = serializers.ListField(
child=serializers.CharField(max_length=254, validators=[EmailWithDisplayNameValidator()]),
required=False,
- help_text="Email addresses of people to interview. May be combined with interviewee_cohort and interviewee_distinct_ids.",
+ help_text="Email addresses of people to interview. May be combined with interviewee_distinct_ids.",
)
interviewee_distinct_ids = serializers.ListField(
child=serializers.CharField(max_length=400),
required=False,
- help_text="PostHog distinct IDs of people to interview. May be combined with interviewee_cohort and interviewee_emails.",
+ help_text="PostHog distinct IDs of people to interview. May be combined with interviewee_emails.",
)
topic = serializers.CharField(
help_text="The product, feature, or idea you want to ask interviewees about.",
@@ -278,7 +273,6 @@ class UserInterviewTopicSerializer(serializers.ModelSerializer):
"id",
"created_by",
"created_at",
- "interviewee_cohort",
"interviewee_emails",
"interviewee_distinct_ids",
"topic",
@@ -287,28 +281,20 @@ class UserInterviewTopicSerializer(serializers.ModelSerializer):
)
read_only_fields = ("id", "created_by", "created_at")
+ MISSING_TARGETING_ERROR = "At least one of interviewee_emails or interviewee_distinct_ids must be provided."
+
def validate(self, attrs: dict) -> dict:
- cohort = (
- attrs.get("interviewee_cohort")
- if "interviewee_cohort" in attrs
- else getattr(self.instance, "interviewee_cohort", None)
- )
- emails = (
- attrs.get("interviewee_emails")
- if "interviewee_emails" in attrs
- else getattr(self.instance, "interviewee_emails", [])
- )
- distinct_ids = (
- attrs.get("interviewee_distinct_ids")
- if "interviewee_distinct_ids" in attrs
- else getattr(self.instance, "interviewee_distinct_ids", [])
- )
- if cohort is None and not emails and not distinct_ids:
- raise serializers.ValidationError(
- "At least one of interviewee_cohort, interviewee_emails, or interviewee_distinct_ids must be provided."
- )
+ if not self._current(attrs, "interviewee_emails", []) and not self._current(
+ attrs, "interviewee_distinct_ids", []
+ ):
+ raise serializers.ValidationError(self.MISSING_TARGETING_ERROR)
return attrs
+ def _current(self, attrs: dict, field: str, default: Any) -> Any:
+ if field in attrs:
+ return attrs[field]
+ return getattr(self.instance, field, default)
+
def create(self, validated_data: dict) -> UserInterviewTopic:
request = self.context["request"]
team = self.context["get_team"]()
@@ -455,7 +441,7 @@ class SendInvitesRequestSerializer(serializers.Serializer):
@extend_schema(tags=[ProductKey.USER_INTERVIEWS])
class UserInterviewTopicViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):
- """Planned user interview topics: who we want to target (cohort) and what we want to ask about."""
+ """Planned user interview topics: who we want to target and what we want to ask about."""
scope_object = "user_interview"
# Treat the custom @action endpoints as writes so personal API keys with
@@ -498,8 +484,8 @@ class UserInterviewTopicViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):
return response.Response(
{
"error": (
- "Topic targets a cohort but has no resolved emails or distinct IDs. "
- "Add interviewee_emails or interviewee_distinct_ids before generating links."
+ "Topic has no interviewee_emails or interviewee_distinct_ids set. "
+ "Add them before generating links."
)
},
status=status.HTTP_400_BAD_REQUEST,
@@ -544,8 +530,8 @@ class UserInterviewTopicViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):
return response.Response(
{
"error": (
- "Topic targets a cohort but has no resolved emails or distinct IDs. "
- "Add interviewee_emails or interviewee_distinct_ids before sending invites."
+ "Topic has no interviewee_emails or interviewee_distinct_ids set. "
+ "Add them before sending invites."
)
},
status=status.HTTP_400_BAD_REQUEST,
diff --git a/products/user_interviews/backend/migrations/0005_remove_userinterviewtopic_interviewee_cohort_state.py b/products/user_interviews/backend/migrations/0005_remove_userinterviewtopic_interviewee_cohort_state.py
new file mode 100644
index 000000000000..a42967230f7d
--- /dev/null
+++ b/products/user_interviews/backend/migrations/0005_remove_userinterviewtopic_interviewee_cohort_state.py
@@ -0,0 +1,29 @@
+"""Phase 1 of 2: remove `UserInterviewTopic.interviewee_cohort` from Django state.
+
+The actual `DROP COLUMN` happens in a follow-up migration once this deploy bakes —
+keeping the column in the DB during one deploy cycle lets old workers and rollbacks
+keep reading from it without error (the field was nullable, so any reader gets None).
+
+See PostHog's safe-django-migrations playbook (docs/published/handbook/engineering/
+safe-django-migrations.md#dropping-columns) for the two-phase pattern.
+"""
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("user_interviews", "0004_userinterview_vapi_fields"),
+ ]
+
+ operations = [
+ migrations.SeparateDatabaseAndState(
+ state_operations=[
+ migrations.RemoveField(
+ model_name="userinterviewtopic",
+ name="interviewee_cohort",
+ ),
+ ],
+ database_operations=[],
+ ),
+ ]
diff --git a/products/user_interviews/backend/migrations/max_migration.txt b/products/user_interviews/backend/migrations/max_migration.txt
index 01b3a6aaefdd..50101431675b 100644
--- a/products/user_interviews/backend/migrations/max_migration.txt
+++ b/products/user_interviews/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0004_userinterview_vapi_fields
+0005_remove_userinterviewtopic_interviewee_cohort_state
diff --git a/products/user_interviews/backend/models.py b/products/user_interviews/backend/models.py
index 13dcbf344763..a1db77ca792f 100644
--- a/products/user_interviews/backend/models.py
+++ b/products/user_interviews/backend/models.py
@@ -44,7 +44,6 @@ class UserInterview(UUIDTModel, CreatedMetaFields):
class UserInterviewTopic(UUIDTModel, CreatedMetaFields):
team = models.ForeignKey(Team, on_delete=models.CASCADE)
- interviewee_cohort = models.BigIntegerField(null=True, blank=True)
interviewee_emails = ArrayField(
models.CharField(max_length=254, validators=[EmailWithDisplayNameValidator()]),
default=list,
diff --git a/products/user_interviews/backend/test_interview_sharing.py b/products/user_interviews/backend/test_interview_sharing.py
index eac65a275c03..c410361fed94 100644
--- a/products/user_interviews/backend/test_interview_sharing.py
+++ b/products/user_interviews/backend/test_interview_sharing.py
@@ -17,6 +17,7 @@ from rest_framework import status
from posthog.api.test.test_sharing import mock_exporter_template
from posthog.models.sharing_configuration import SharingConfiguration
+from products.user_interviews.backend.api import UserInterviewTopicSerializer
from products.user_interviews.backend.models import IntervieweeContext, UserInterview, UserInterviewTopic
from products.user_interviews.backend.webhooks import EMBEDDING_CONTENT_MAX_BYTES
@@ -94,16 +95,46 @@ class TestGenerateInterviewLinks(_FeatureFlagEnabledMixin):
self.assertIn("heavy user, churned last quarter", link["agent_context"])
self.assertIn("Researching adoption of session replay", link["agent_context"])
- def test_generate_links_rejects_topic_with_only_cohort(self):
- topic = self._create_topic(
- interviewee_emails=[],
- interviewee_distinct_ids=[],
- interviewee_cohort=123,
- )
+ def test_generate_links_rejects_topic_with_no_identifiers(self):
+ topic = self._create_topic(interviewee_emails=[], interviewee_distinct_ids=[])
response = self.client.post(self._generate_links_url(str(topic.id)))
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
+class TestUserInterviewTopicCreate(_FeatureFlagEnabledMixin):
+ def _url(self) -> str:
+ return f"/api/environments/{self.team.id}/user_interview_topics/"
+
+ @parameterized.expand(
+ [
+ ("no_targeting", {}),
+ ("empty_lists", {"interviewee_emails": [], "interviewee_distinct_ids": []}),
+ ]
+ )
+ def test_rejects_topic_without_identifiers(self, _name: str, targeting: dict[str, Any]):
+ payload = {"topic": "Why people churn", **targeting}
+ response = self.client.post(self._url(), data=payload, format="json")
+ self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.content)
+ body = response.json()
+ candidates = body.get("non_field_errors") or [body.get("detail", "")]
+ assert UserInterviewTopicSerializer.MISSING_TARGETING_ERROR in candidates, body
+
+ @parameterized.expand(
+ [
+ ("emails_only", {"interviewee_emails": ["[email protected]"]}),
+ ("distinct_ids_only", {"interviewee_distinct_ids": ["distinct-abc"]}),
+ (
+ "both",
+ {"interviewee_emails": ["[email protected]"], "interviewee_distinct_ids": ["distinct-abc"]},
+ ),
+ ]
+ )
+ def test_accepts_topic_with_identifiers(self, _name: str, targeting: dict[str, Any]):
+ payload = {"topic": "Why people churn", **targeting}
+ response = self.client.post(self._url(), data=payload, format="json")
+ self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.content)
+
+
class TestInterviewPublicViewer(APIBaseTest):
def _create_share(self) -> SharingConfiguration:
topic = UserInterviewTopic.objects.create(
@@ -544,8 +575,8 @@ class TestSendInterviewInvites(_FeatureFlagEnabledMixin):
response = self.client.post(self._url(str(topic.id)), data={}, format="json")
self.assertEqual(response.status_code, status.HTTP_503_SERVICE_UNAVAILABLE)
- def test_send_invites_400_when_topic_only_has_cohort(self):
- topic = self._create_topic(interviewee_emails=[], interviewee_distinct_ids=[], interviewee_cohort=123)
+ def test_send_invites_400_when_topic_has_no_identifiers(self):
+ topic = self._create_topic(interviewee_emails=[], interviewee_distinct_ids=[])
with patch("products.user_interviews.backend.api.is_email_available", return_value=True):
response = self.client.post(self._url(str(topic.id)), data={}, format="json")
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
diff --git a/products/user_interviews/frontend/UserInterview.tsx b/products/user_interviews/frontend/UserInterview.tsx
index 233899c43d6d..10572af97765 100644
--- a/products/user_interviews/frontend/UserInterview.tsx
+++ b/products/user_interviews/frontend/UserInterview.tsx
@@ -23,11 +23,7 @@ export const scene: SceneExport<UserInterviewLogicProps> = {
function targetingLabel(topic: UserInterviewTopicApi): string {
const emailCount = topic.interviewee_emails?.length || 0
const distinctIdCount = topic.interviewee_distinct_ids?.length || 0
- const hasCohort = topic.interviewee_cohort != null
const parts: string[] = []
- if (hasCohort) {
- parts.push(`Cohort #${topic.interviewee_cohort}`)
- }
if (emailCount > 0) {
parts.push(`${emailCount} email${emailCount !== 1 ? 's' : ''}`)
}
diff --git a/products/user_interviews/frontend/UserInterviewResponse.tsx b/products/user_interviews/frontend/UserInterviewResponse.tsx
index b27f61c72cb3..f03118fe2d9a 100644
--- a/products/user_interviews/frontend/UserInterviewResponse.tsx
+++ b/products/user_interviews/frontend/UserInterviewResponse.tsx
@@ -185,9 +185,6 @@ export function UserInterviewResponse({ topicId, responseId }: UserInterviewResp
<div className="p-4 space-y-2">
<DetailRow label="Topic" value={topic.topic} />
<DetailRow label="Created" value={topic.created_at.split('T')[0]} />
- {topic.interviewee_cohort != null && (
- <DetailRow label="Cohort" value={`#${topic.interviewee_cohort}`} />
- )}
</div>
</LemonWidget>
</div>
diff --git a/products/user_interviews/frontend/UserInterviews.tsx b/products/user_interviews/frontend/UserInterviews.tsx
index 2493b8848b3c..8611a315e1bb 100644
--- a/products/user_interviews/frontend/UserInterviews.tsx
+++ b/products/user_interviews/frontend/UserInterviews.tsx
@@ -24,11 +24,7 @@ export const scene: SceneExport = {
function targetingLabel(topic: UserInterviewTopicApi): string {
const emailCount = topic.interviewee_emails?.length || 0
const distinctIdCount = topic.interviewee_distinct_ids?.length || 0
- const hasCohort = topic.interviewee_cohort != null
const parts: string[] = []
- if (hasCohort) {
- parts.push(`Cohort #${topic.interviewee_cohort}`)
- }
if (emailCount > 0) {
parts.push(`${emailCount} email${emailCount !== 1 ? 's' : ''}`)
}
@@ -41,7 +37,7 @@ function targetingLabel(topic: UserInterviewTopicApi): string {
const NEW_TOPIC_PROMPT = `!I want to set up a new user research topic. Help me through the process:
1. First, let's figure out what I want to learn — what feature, behavior, or question I want to research.
-2. Then, help me identify the right users to interview — find or create a cohort, or I can provide emails.
+2. Then, help me identify the right users to interview — pick a cohort, find users by behavior, or provide emails directly.
3. Draft interview questions based on the topic.
4. Set up the outreach workflow to email each user with their unique interview link.
5. Once I confirm, trigger the emails — I'll track responses in User research.
@@ -56,7 +52,7 @@ export function UserInterviews(): JSX.Element {
<SceneContent>
<SceneTitleSection
name={sceneConfigurations[Scene.UserInterviews].name}
- description="Run AI-powered voice research campaigns. Target a cohort, set a topic, and let the AI handle the interviews."
+ description="Run AI-powered voice research campaigns. Target an audience, set a topic, and let the AI handle the interviews."
resourceType={{
type: sceneConfigurations[Scene.UserInterviews].iconType || 'default_icon_type',
}}
diff --git a/products/user_interviews/frontend/generated/api.schemas.ts b/products/user_interviews/frontend/generated/api.schemas.ts
index 1977b48d4cdb..83372534ff39 100644
--- a/products/user_interviews/frontend/generated/api.schemas.ts
+++ b/products/user_interviews/frontend/generated/api.schemas.ts
@@ -66,14 +66,9 @@ export interface UserInterviewTopicApi {
readonly id: string
readonly created_by: UserBasicApi
readonly created_at: string
- /**
- * Optional cohort ID identifying who to target. Not enforced as a foreign key.
- * @nullable
- */
- interviewee_cohort?: number | null
- /** Email addresses of people to interview. May be combined with interviewee_cohort and interviewee_distinct_ids. */
+ /** Email addresses of people to interview. May be combined with interviewee_distinct_ids. */
interviewee_emails?: string[]
- /** PostHog distinct IDs of people to interview. May be combined with interviewee_cohort and interviewee_emails. */
+ /** PostHog distinct IDs of people to interview. May be combined with interviewee_emails. */
interviewee_distinct_ids?: string[]
/** The product, feature, or idea you want to ask interviewees about. */
topic: string
@@ -96,14 +91,9 @@ export interface PatchedUserInterviewTopicApi {
readonly id?: string
readonly created_by?: UserBasicApi
readonly created_at?: string
- /**
- * Optional cohort ID identifying who to target. Not enforced as a foreign key.
- * @nullable
- */
- interviewee_cohort?: number | null
- /** Email addresses of people to interview. May be combined with interviewee_cohort and interviewee_distinct_ids. */
+ /** Email addresses of people to interview. May be combined with interviewee_distinct_ids. */
interviewee_emails?: string[]
- /** PostHog distinct IDs of people to interview. May be combined with interviewee_cohort and interviewee_emails. */
+ /** PostHog distinct IDs of people to interview. May be combined with interviewee_emails. */
interviewee_distinct_ids?: string[]
/** The product, feature, or idea you want to ask interviewees about. */
topic?: string
diff --git a/products/user_interviews/frontend/generated/api.ts b/products/user_interviews/frontend/generated/api.ts
index ecfb3dadd2ea..36f6d2c57a3e 100644
--- a/products/user_interviews/frontend/generated/api.ts
+++ b/products/user_interviews/frontend/generated/api.ts
@@ -60,7 +60,7 @@ export const getUserInterviewTopicsListUrl = (projectId: string, params?: UserIn
}
/**
- * Planned user interview topics: who we want to target (cohort) and what we want to ask about.
+ * Planned user interview topics: who we want to target and what we want to ask about.
*/
export const userInterviewTopicsList = async (
projectId: string,
@@ -78,7 +78,7 @@ export const getUserInterviewTopicsCreateUrl = (projectId: string) => {
}
/**
- * Planned user interview topics: who we want to target (cohort) and what we want to ask about.
+ * Planned user interview topics: who we want to target and what we want to ask about.
*/
export const userInterviewTopicsCreate = async (
projectId: string,
@@ -98,7 +98,7 @@ export const getUserInterviewTopicsRetrieveUrl = (projectId: string, id: string)
}
/**
- * Planned user interview topics: who we want to target (cohort) and what we want to ask about.
+ * Planned user interview topics: who we want to target and what we want to ask about.
*/
export const userInterviewTopicsRetrieve = async (
projectId: string,
@@ -116,7 +116,7 @@ export const getUserInterviewTopicsUpdateUrl = (projectId: string, id: string) =
}
/**
- * Planned user interview topics: who we want to target (cohort) and what we want to ask about.
+ * Planned user interview topics: who we want to target and what we want to ask about.
*/
export const userInterviewTopicsUpdate = async (
projectId: string,
@@ -137,7 +137,7 @@ export const getUserInterviewTopicsPartialUpdateUrl = (projectId: string, id: st
}
/**
- * Planned user interview topics: who we want to target (cohort) and what we want to ask about.
+ * Planned user interview topics: who we want to target and what we want to ask about.
*/
export const userInterviewTopicsPartialUpdate = async (
projectId: string,
@@ -158,7 +158,7 @@ export const getUserInterviewTopicsDestroyUrl = (projectId: string, id: string)
}
/**
- * Planned user interview topics: who we want to target (cohort) and what we want to ask about.
+ * Planned user interview topics: who we want to target and what we want to ask about.
*/
export const userInterviewTopicsDestroy = async (
projectId: string,
diff --git a/products/user_interviews/frontend/generated/api.zod.ts b/products/user_interviews/frontend/generated/api.zod.ts
index db7335b1923d..941fd99f8270 100644
--- a/products/user_interviews/frontend/generated/api.zod.ts
+++ b/products/user_interviews/frontend/generated/api.zod.ts
@@ -10,29 +10,21 @@
import * as zod from 'zod'
/**
- * Planned user interview topics: who we want to target (cohort) and what we want to ask about.
+ * Planned user interview topics: who we want to target and what we want to ask about.
*/
export const userInterviewTopicsCreateBodyIntervieweeEmailsItemMax = 254
export const userInterviewTopicsCreateBodyIntervieweeDistinctIdsItemMax = 400
export const UserInterviewTopicsCreateBody = /* @__PURE__ */ zod.object({
- interviewee_cohort: zod
- .number()
- .nullish()
- .describe('Optional cohort ID identifying who to target. Not enforced as a foreign key.'),
interviewee_emails: zod
.array(zod.string().max(userInterviewTopicsCreateBodyIntervieweeEmailsItemMax))
.optional()
- .describe(
- 'Email addresses of people to interview. May be combined with interviewee_cohort and interviewee_distinct_ids.'
- ),
+ .describe('Email addresses of people to interview. May be combined with interviewee_distinct_ids.'),
interviewee_distinct_ids: zod
.array(zod.string().max(userInterviewTopicsCreateBodyIntervieweeDistinctIdsItemMax))
.optional()
- .describe(
- 'PostHog distinct IDs of people to interview. May be combined with interviewee_cohort and interviewee_emails.'
- ),
+ .describe('PostHog distinct IDs of people to interview. May be combined with interviewee_emails.'),
topic: zod.string().describe('The product, feature, or idea you want to ask interviewees about.'),
agent_context: zod
.string()
@@ -45,29 +37,21 @@ export const UserInterviewTopicsCreateBody = /* @__PURE__ */ zod.object({
})
/**
- * Planned user interview topics: who we want to target (cohort) and what we want to ask about.
+ * Planned user interview topics: who we want to target and what we want to ask about.
*/
export const userInterviewTopicsUpdateBodyIntervieweeEmailsItemMax = 254
export const userInterviewTopicsUpdateBodyIntervieweeDistinctIdsItemMax = 400
export const UserInterviewTopicsUpdateBody = /* @__PURE__ */ zod.object({
- interviewee_cohort: zod
- .number()
- .nullish()
- .describe('Optional cohort ID identifying who to target. Not enforced as a foreign key.'),
interviewee_emails: zod
.array(zod.string().max(userInterviewTopicsUpdateBodyIntervieweeEmailsItemMax))
.optional()
- .describe(
- 'Email addresses of people to interview. May be combined with interviewee_cohort and interviewee_distinct_ids.'
- ),
+ .describe('Email addresses of people to interview. May be combined with interviewee_distinct_ids.'),
interviewee_distinct_ids: zod
.array(zod.string().max(userInterviewTopicsUpdateBodyIntervieweeDistinctIdsItemMax))
.optional()
- .describe(
- 'PostHog distinct IDs of people to interview. May be combined with interviewee_cohort and interviewee_emails.'
- ),
+ .describe('PostHog distinct IDs of people to interview. May be combined with interviewee_emails.'),
topic: zod.string().describe('The product, feature, or idea you want to ask interviewees about.'),
agent_context: zod
.string()
@@ -80,29 +64,21 @@ export const UserInterviewTopicsUpdateBody = /* @__PURE__ */ zod.object({
})
/**
- * Planned user interview topics: who we want to target (cohort) and what we want to ask about.
+ * Planned user interview topics: who we want to target and what we want to ask about.
*/
export const userInterviewTopicsPartialUpdateBodyIntervieweeEmailsItemMax = 254
export const userInterviewTopicsPartialUpdateBodyIntervieweeDistinctIdsItemMax = 400
export const UserInterviewTopicsPartialUpdateBody = /* @__PURE__ */ zod.object({
- interviewee_cohort: zod
- .number()
- .nullish()
- .describe('Optional cohort ID identifying who to target. Not enforced as a foreign key.'),
interviewee_emails: zod
.array(zod.string().max(userInterviewTopicsPartialUpdateBodyIntervieweeEmailsItemMax))
.optional()
- .describe(
- 'Email addresses of people to interview. May be combined with interviewee_cohort and interviewee_distinct_ids.'
- ),
+ .describe('Email addresses of people to interview. May be combined with interviewee_distinct_ids.'),
interviewee_distinct_ids: zod
.array(zod.string().max(userInterviewTopicsPartialUpdateBodyIntervieweeDistinctIdsItemMax))
.optional()
- .describe(
- 'PostHog distinct IDs of people to interview. May be combined with interviewee_cohort and interviewee_emails.'
- ),
+ .describe('PostHog distinct IDs of people to interview. May be combined with interviewee_emails.'),
topic: zod.string().optional().describe('The product, feature, or idea you want to ask interviewees about.'),
agent_context: zod
.string()
diff --git a/products/user_interviews/mcp/tools.yaml b/products/user_interviews/mcp/tools.yaml
index c3eb0fe092de..4973237974b7 100644
--- a/products/user_interviews/mcp/tools.yaml
+++ b/products/user_interviews/mcp/tools.yaml
@@ -21,13 +21,14 @@ tools:
title: Create user interview topic
description: >
Plan a user interview by recording who you want to target and what product or idea you want to ask them
- about. `topic` is the free-text description of the question or product area. Targets can be specified as any
- combination of `interviewee_cohort` (optional cohort identifier), `interviewee_emails` (list of email
- addresses), and `interviewee_distinct_ids` (list of PostHog distinct IDs) — at least one target must be
- provided. Pass `agent_context` (free text) to give the voice agent extra background or instructions, and
- `questions` (list of strings) for the ordered set of questions the agent should work through.
+ about. `topic` is the free-text description of the question or product area. Targets are specified as a
+ combination of `interviewee_emails` (list of email addresses) and `interviewee_distinct_ids` (list of
+ PostHog distinct IDs) — at least one of the two must be provided. To target a cohort, resolve cohort members
+ to emails/distinct_ids in the calling agent first (see the planning-user-interviews skill) and pass them
+ explicitly here — topics snapshot their audience at creation time. Pass `agent_context` (free text) to give
+ the voice agent extra background or instructions, and `questions` (list of strings) for the ordered set of
+ questions the agent should work through.
include_params:
- - interviewee_cohort
- interviewee_emails
- interviewee_distinct_ids
- topic
@@ -114,9 +115,8 @@ tools:
title: List user interview topics
description: >
List planned user interview topics in the current project, newest first. Each result includes the topic,
- targeting (interviewee_cohort, interviewee_emails, interviewee_distinct_ids), and the voice agent setup
- (agent_context, questions). Supports `search` for substring match against the topic, and `limit`/`offset`
- for pagination.
+ targeting (interviewee_emails, interviewee_distinct_ids), and the voice agent setup (agent_context,
+ questions). Supports `search` for substring match against the topic, and `limit`/`offset` for pagination.
feature_flag: user-interviews
user-interview-topics-partial-update:
operation: user_interview_topics_partial_update
diff --git a/products/user_interviews/skills/planning-user-interviews/SKILL.md b/products/user_interviews/skills/planning-user-interviews/SKILL.md
index a8e0b4f6bed7..4c9369f1fae3 100644
--- a/products/user_interviews/skills/planning-user-interviews/SKILL.md
+++ b/products/user_interviews/skills/planning-user-interviews/SKILL.md
@@ -1,6 +1,6 @@
---
name: planning-user-interviews
-description: 'Plan a user interview topic in PostHog — pick who to target (cohort, emails, or PostHog distinct IDs), draft what to ask about, and prepare the voice-agent context plus a question list. Use when the user asks to "talk to users", "check how users feel about X", "interview some customers", "set up a user interview", "run a user-research call", "find users to ask about Y", or otherwise wants qualitative feedback through a conversation. Walks the user through targeting (cohorts-list, persons-list, or accepting emails / distinct IDs directly), captures the topic, and prompts for agent context and questions before calling user-interview-topics-create. Do NOT trigger when the user is uploading a recorded interview audio file (that''s the separate UserInterview/transcript flow) or only browsing existing topics with user-interview-topics-list.'
+description: 'Plan a user interview topic in PostHog — pick who to target (cohort, emails, or PostHog distinct IDs), draft what to ask about, and prepare the voice-agent context plus a question list. Use when the user asks to "talk to users", "check how users feel about X", "interview some customers", "set up a user interview", "run a user-research call", "find users to ask about Y", or otherwise wants qualitative feedback through a conversation. Walks the user through targeting (cohorts-list, persons-list, or accepting emails / distinct IDs directly), captures the topic, and prompts for agent context and questions before calling user-interview-topics-create. Cohort targeting is resolved to explicit emails/distinct_ids at create time — topics snapshot their audience and do not re-evaluate cohort membership later. Do NOT trigger when the user is uploading a recorded interview audio file (that''s the separate UserInterview/transcript flow) or only browsing existing topics with user-interview-topics-list.'
---
# Planning user interviews
@@ -12,14 +12,15 @@ Use this skill when someone asks to set up a user interview — to talk to custo
Before calling `user-interview-topics-create`, gather these:
1. **Who to interview** — at least one of:
- - `interviewee_cohort` — an existing cohort ID
- `interviewee_emails` — list of email addresses
- `interviewee_distinct_ids` — list of PostHog distinct IDs
2. **What to ask about** — `topic` (required free text)
3. **How the agent should frame the conversation** — optional `agent_context` (extra system prompt)
4. **The questions to work through** — optional ordered `questions` list
-The API rejects topics with no targeting, so at least one of the three audience fields must be set. They can be combined — a cohort plus a handful of extra emails is fine.
+Topics snapshot their audience at create time — there is no live cohort link. If the user names a cohort, you (the agent) resolve cohort members to emails/distinct_ids before calling `user-interview-topics-create`. See Step 2 for the resolution flow and the 500-member cap UX.
+
+The API rejects topics with no targeting, so `interviewee_emails` and/or `interviewee_distinct_ids` must end up non-empty.
## Step 1: Clarify intent
@@ -35,8 +36,8 @@ Skip these questions only when the user has already answered them.
Map what the user said to one of these paths:
-- **They named a cohort** ("our power users", "trial signups last week") — use `cohorts-list` filtered by name to find the cohort, confirm the match, and pass the cohort ID as `interviewee_cohort`.
-- **They described the kind of person but no cohort exists** — offer to either create the cohort first (`cohorts-create`) or fall back to finding people by behavior (see below).
+- **They named a cohort** ("our power users", "trial signups last week") — use `cohorts-list` (or a `system.cohorts` SQL search) to find the cohort, confirm the match, then resolve cohort members to emails/distinct_ids (see "Resolving a cohort" below).
+- **They described the kind of person but no cohort exists** — offer to either create the cohort first (`cohorts-create`), then resolve it, or fall back to finding people by behavior (see below).
- **They gave email addresses or distinct IDs** — accept them directly. Skip the cohort lookup.
- **They described a behavior, not a cohort** ("users who tried checkout but didn't finish", "people who used to use dark mode and stopped") — find them by querying their events (see below).
- **They were vague** ("a few customers", "some power users") — ask which they prefer:
@@ -47,6 +48,41 @@ Map what the user said to one of these paths:
Each email passes through DRF email validation (display-name format `Paul D'Ambra <[email protected]>` is accepted alongside plain `[email protected]`).
+### Resolving a cohort
+
+Topics snapshot their audience at create time. When the user picks a cohort, you must materialize the member list into `interviewee_emails` (and `interviewee_distinct_ids` for members without emails) before creating the topic.
+
+1. **Count the cohort first.** Cheap query, decides the next step:
+
+ ```sql
+ SELECT count() FROM persons WHERE id IN COHORT <cohort_id>
+ ```
+
+2. **If the cohort has 500 or fewer members**, fetch their emails:
+
+ ```sql
+ SELECT properties.email AS email
+ FROM persons
+ WHERE id IN COHORT <cohort_id> AND properties.email IS NOT NULL
+ LIMIT 500
+ ```
+
+ Put each row into `interviewee_emails`. Dedupe.
+
+ Cohort members without an email property aren't included by default — the `persons.id` column is the person UUID, not the SDK distinct_id, so it can't be used as an `interviewee_distinct_id` without a `pdi.distinct_id` join. If you specifically need to reach members who only exist as distinct IDs, ask the user first, then do the join explicitly.
+
+3. **If the cohort has more than 500 members**, stop and ask the user. Do not silently truncate, sample, or fall back to a different cohort — the user needs to choose. Surface:
+ - The cohort name and count (e.g. "PostHog Team has 28,563 members — over the 500 cap.")
+ - Why the cap exists ("we snapshot the audience at create time, and 500 is an agent-side guardrail to keep one interview campaign manageable — the backend itself does not cap the array length")
+ - Their options:
+ - **Narrow the cohort** — describe the subset they actually want (e.g. "engineers only", "active in the last 30 days"). You can offer to write a more specific HogQL filter or create a new, smaller cohort via `cohorts-create`.
+ - **Sample randomly** — confirm a count (e.g. 200) and use `ORDER BY rand() LIMIT <n>` on the cohort query. Make the randomness explicit so they know they're not getting the "top" members.
+ - **Paste a curated list** — they take over and provide emails directly.
+
+ Pick the path with them, then re-run the resolution. Never proceed without an explicit decision.
+
+4. **Tell the user what you resolved.** After resolution, confirm before creating: "Cohort 'X' has N members, resolved to E emails and D distinct IDs (snapshot — won't update if the cohort changes later)." This makes the snapshot semantics visible.
+
### Finding users by behavior
When the user describes who they want to talk to in behavioral terms, find them in the project's own data:
@@ -124,8 +160,8 @@ Once you have the pieces:
```json
{
"topic": "Why trial users churned in week 2",
- "interviewee_cohort": 42,
- "interviewee_emails": ["[email protected]"],
+ "interviewee_emails": ["[email protected]", "[email protected]"],
+ "interviewee_distinct_ids": ["distinct-id-with-no-email"],
"agent_context": "Be warm. The interviewee just churned — don't pitch.",
"questions": [
"What were you hoping PostHog would help with?",
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 7da79cf19693..953e48c0ab59 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -4743,7 +4743,7 @@
}
},
"user-interview-topics-create": {
- "description": "Plan a user interview by recording who you want to target and what product or idea you want to ask them about. `topic` is the free-text description of the question or product area. Targets can be specified as any combination of `interviewee_cohort` (optional cohort identifier), `interviewee_emails` (list of email addresses), and `interviewee_distinct_ids` (list of PostHog distinct IDs) — at least one target must be provided. Pass `agent_context` (free text) to give the voice agent extra background or instructions, and `questions` (list of strings) for the ordered set of questions the agent should work through.",
+ "description": "Plan a user interview by recording who you want to target and what product or idea you want to ask them about. `topic` is the free-text description of the question or product area. Targets are specified as a combination of `interviewee_emails` (list of email addresses) and `interviewee_distinct_ids` (list of PostHog distinct IDs) — at least one of the two must be provided. To target a cohort, resolve cohort members to emails/distinct_ids in the calling agent first (see the planning-user-interviews skill) and pass them explicitly here — topics snapshot their audience at creation time. Pass `agent_context` (free text) to give the voice agent extra background or instructions, and `questions` (list of strings) for the ordered set of questions the agent should work through.",
"category": "User interview topics",
"feature": "user_interviews",
"summary": "Create user interview topic",
@@ -4807,7 +4807,7 @@
"feature_flag": "user-interviews"
},
"user-interview-topics-list": {
- "description": "List planned user interview topics in the current project, newest first. Each result includes the topic, targeting (interviewee_cohort, interviewee_emails, interviewee_distinct_ids), and the voice agent setup (agent_context, questions). Supports `search` for substring match against the topic, and `limit`/`offset` for pagination.",
+ "description": "List planned user interview topics in the current project, newest first. Each result includes the topic, targeting (interviewee_emails, interviewee_distinct_ids), and the voice agent setup (agent_context, questions). Supports `search` for substring match against the topic, and `limit`/`offset` for pagination.",
"category": "User interview topics",
"feature": "user_interviews",
"summary": "List user interview topics",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 34edc49a5f9d..5e31ae234186 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -5224,7 +5224,7 @@
}
},
"user-interview-topics-create": {
- "description": "Plan a user interview by recording who you want to target and what product or idea you want to ask them about. `topic` is the free-text description of the question or product area. Targets can be specified as any combination of `interviewee_cohort` (optional cohort identifier), `interviewee_emails` (list of email addresses), and `interviewee_distinct_ids` (list of PostHog distinct IDs) — at least one target must be provided. Pass `agent_context` (free text) to give the voice agent extra background or instructions, and `questions` (list of strings) for the ordered set of questions the agent should work through.",
+ "description": "Plan a user interview by recording who you want to target and what product or idea you want to ask them about. `topic` is the free-text description of the question or product area. Targets are specified as a combination of `interviewee_emails` (list of email addresses) and `interviewee_distinct_ids` (list of PostHog distinct IDs) — at least one of the two must be provided. To target a cohort, resolve cohort members to emails/distinct_ids in the calling agent first (see the planning-user-interviews skill) and pass them explicitly here — topics snapshot their audience at creation time. Pass `agent_context` (free text) to give the voice agent extra background or instructions, and `questions` (list of strings) for the ordered set of questions the agent should work through.",
"category": "User interview topics",
"feature": "user_interviews",
"summary": "Create user interview topic",
@@ -5288,7 +5288,7 @@
"feature_flag": "user-interviews"
},
"user-interview-topics-list": {
- "description": "List planned user interview topics in the current project, newest first. Each result includes the topic, targeting (interviewee_cohort, interviewee_emails, interviewee_distinct_ids), and the voice agent setup (agent_context, questions). Supports `search` for substring match against the topic, and `limit`/`offset` for pagination.",
+ "description": "List planned user interview topics in the current project, newest first. Each result includes the topic, targeting (interviewee_emails, interviewee_distinct_ids), and the voice agent setup (agent_context, questions). Supports `search` for substring match against the topic, and `limit`/`offset` for pagination.",
"category": "User interview topics",
"feature": "user_interviews",
"summary": "List user interview topics",
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index a3591d202e96..b84a789c3880 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -24774,14 +24774,9 @@ export namespace Schemas {
readonly id: string;
readonly created_by: UserBasic;
readonly created_at: string;
- /**
- * Optional cohort ID identifying who to target. Not enforced as a foreign key.
- * @nullable
- */
- interviewee_cohort?: number | null;
- /** Email addresses of people to interview. May be combined with interviewee_cohort and interviewee_distinct_ids. */
+ /** Email addresses of people to interview. May be combined with interviewee_distinct_ids. */
interviewee_emails?: string[];
- /** PostHog distinct IDs of people to interview. May be combined with interviewee_cohort and interviewee_emails. */
+ /** PostHog distinct IDs of people to interview. May be combined with interviewee_emails. */
interviewee_distinct_ids?: string[];
/** The product, feature, or idea you want to ask interviewees about. */
topic: string;
@@ -30538,14 +30533,9 @@ export namespace Schemas {
readonly id?: string;
readonly created_by?: UserBasic;
readonly created_at?: string;
- /**
- * Optional cohort ID identifying who to target. Not enforced as a foreign key.
- * @nullable
- */
- interviewee_cohort?: number | null;
- /** Email addresses of people to interview. May be combined with interviewee_cohort and interviewee_distinct_ids. */
+ /** Email addresses of people to interview. May be combined with interviewee_distinct_ids. */
interviewee_emails?: string[];
- /** PostHog distinct IDs of people to interview. May be combined with interviewee_cohort and interviewee_emails. */
+ /** PostHog distinct IDs of people to interview. May be combined with interviewee_emails. */
interviewee_distinct_ids?: string[];
/** The product, feature, or idea you want to ask interviewees about. */
topic?: string;
diff --git a/services/mcp/src/generated/user_interviews/api.ts b/services/mcp/src/generated/user_interviews/api.ts
index af831b402109..2a3687484394 100644
--- a/services/mcp/src/generated/user_interviews/api.ts
+++ b/services/mcp/src/generated/user_interviews/api.ts
@@ -9,7 +9,7 @@
import * as zod from 'zod'
/**
- * Planned user interview topics: who we want to target (cohort) and what we want to ask about.
+ * Planned user interview topics: who we want to target and what we want to ask about.
*/
export const UserInterviewTopicsListParams = /* @__PURE__ */ zod.object({
project_id: zod
@@ -26,7 +26,7 @@ export const UserInterviewTopicsListQueryParams = /* @__PURE__ */ zod.object({
})
/**
- * Planned user interview topics: who we want to target (cohort) and what we want to ask about.
+ * Planned user interview topics: who we want to target and what we want to ask about.
*/
export const UserInterviewTopicsCreateParams = /* @__PURE__ */ zod.object({
project_id: zod
@@ -41,22 +41,14 @@ export const userInterviewTopicsCreateBodyIntervieweeEmailsItemMax = 254
export const userInterviewTopicsCreateBodyIntervieweeDistinctIdsItemMax = 400
export const UserInterviewTopicsCreateBody = /* @__PURE__ */ zod.object({
- interviewee_cohort: zod
- .number()
- .nullish()
- .describe('Optional cohort ID identifying who to target. Not enforced as a foreign key.'),
interviewee_emails: zod
.array(zod.string().max(userInterviewTopicsCreateBodyIntervieweeEmailsItemMax))
.optional()
- .describe(
- 'Email addresses of people to interview. May be combined with interviewee_cohort and interviewee_distinct_ids.'
- ),
+ .describe('Email addresses of people to interview. May be combined with interviewee_distinct_ids.'),
interviewee_distinct_ids: zod
.array(zod.string().max(userInterviewTopicsCreateBodyIntervieweeDistinctIdsItemMax))
.optional()
- .describe(
- 'PostHog distinct IDs of people to interview. May be combined with interviewee_cohort and interviewee_emails.'
- ),
+ .describe('PostHog distinct IDs of people to interview. May be combined with interviewee_emails.'),
topic: zod.string().describe('The product, feature, or idea you want to ask interviewees about.'),
agent_context: zod
.string()
diff --git a/services/mcp/src/tools/generated/user_interviews.ts b/services/mcp/src/tools/generated/user_interviews.ts
index 3094b534316a..a1e039aff3ed 100644
--- a/services/mcp/src/tools/generated/user_interviews.ts
+++ b/services/mcp/src/tools/generated/user_interviews.ts
@@ -24,9 +24,6 @@ const userInterviewTopicsCreate = (): ToolBase<typeof UserInterviewTopicsCreateS
handler: async (context: Context, params: z.infer<typeof UserInterviewTopicsCreateSchema>) => {
const projectId = await context.stateManager.getProjectId()
const body: Record<string, unknown> = {}
- if (params.interviewee_cohort !== undefined) {
- body['interviewee_cohort'] = params.interviewee_cohort
- }
if (params.interviewee_emails !== undefined) {
body['interviewee_emails'] = params.interviewee_emails
}