8000 feat: surveys on Max AI by lucasheriques · Pull Request #33111 · PostHog/posthog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: surveys on Max AI #33111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

feat: surveys on Max AI #33111

wants to merge 14 commits into from

Conversation

lucasheriques
Copy link
Contributor
@lucasheriques lucasheriques commented Jun 3, 2025

Problem

Closes #32818

Changes

Adds AI survey creation to PostHog's Max tool - users can now create and launch surveys through natural language chat.

What's New

  • AI Survey Creator: New create_survey MaxTool that converts natural language into configured surveys
  • Chat Interface: Integrated directly in Surveys page with smart suggestions
  • One-Step Launch: Create and launch surveys instantly or save as drafts

Key Features

  • Supports all question types (NPS, CSAT, feedback, multiple choice, etc.)
  • Context-aware (uses existing surveys to avoid duplication)
  • Applies team defaults and survey best practices automatically
  • Full validation with detailed error handling

Testing

Navigate to Surveys page and try:

  • "Create an NPS survey for checkout users"
  • "Create a feedback survey about our dashboard"
  • "Create and launch a quick satisfaction survey"

Implementation

  • New MaxTool backend in products/surveys/backend/
  • Pydantic schemas for structured LLM output
  • Frontend MaxTool integration
  • Comprehensive test coverage

Part of the Max AI initiative to streamline PostHog workflows through natural language.

Did you write or update any docs for this change?

  • No docs needed for this change

How did you test this code?

Unit/integration tests for the max too. @kappa90 i'm not that familiar with evals though, maybe we can pair on it and you can show me around? Are they a good fit for this case?

@lucasheriques lucasheriques changed the title feat: surveys on Max feat: surveys on Max AI Jun 3, 2025
Copy link
Contributor
github-actions bot commented Jun 3, 2025

Size Change: 0 B

Total Size: 2.57 MB

ℹ️ View Unchanged
Filename Size
frontend/dist/toolbar.js 2.57 MB

compressed-size-action

@kappa90 kappa90 requested a review from a team June 4, 2025 16:59
Copy link
Contributor
@kappa90 kappa90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works really well! Will review again when it has tests/it's out of draft 🫶

lucasheriques and others added 3 commits June 11, 2025 02:53
< 8000 a href="/PostHog/posthog/pull/33111/commits/61e9f5374db3357d3cfe5685ef9e9e3bd09ad3dd" class="Link--secondary">61e9f53
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 7)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@lucasheriques lucasheriques requested review from kappa90 and a team June 18, 2025 01:26
@lucasheriques lucasheriques self-assigned this Jun 18, 2025
@lucasheriques lucasheriques marked this pull request as ready for review June 18, 2025 01:26
Copy link
Contributor
@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

Implements AI-powered survey creation through Max AI, enabling users to create and launch surveys using natural language chat interactions within PostHog.

  • Added SurveyCreatorTool in products/surveys/backend/max_tools.py with GPT-4 integration for converting natural language to structured survey configurations
  • Defined comprehensive Pydantic schemas in products/surveys/backend/survey_schema.py for validating LLM output and enforcing survey configuration rules
  • Added DEFAULT_SURVEY_APPEARANCE in posthog/constants.py to maintain consistent styling hierarchy (frontend defaults -> team overrides -> LLM overrides)
  • Wrapped Surveys component with SurveysWithMaxTool in frontend/src/scenes/surveys/Surveys.tsx to provide AI chat interface while preserving existing functionality
  • Implemented extensive test suite in products/surveys/backend/test_max_tools.py covering survey creation, validation, and edge cases

10 files reviewed, 9 comments
Edit PR Review Bot Settings | Greptile

@@ -319,3 +319,32 @@ class FlagRequestType(StrEnum):
PERMITTED_FORUM_DOMAINS = ["localhost", "posthog.com"]

INVITE_DAYS_VALIDITY = 3 # number of days for which team invites are valid

# Sync with frontend/src/scenes/surveys/constants.tsx
DEFAULT_SURVEY_APPEARANCE = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider alphabetizing the properties in DEFAULT_SURVEY_APPEARANCE for better maintainability

Comment on lines +71 to +72
thankYouMessageHeader: Optional[str] = Field(default=DEFAULT_SURVEY_APPEARANCE["thankYouMessageHeader"])
thankYouMessageDescription: Optional[str] = Field(default="We appreciate your feedback.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Default thankYouMessageDescription hardcoded to 'We appreciate your feedback' - should use the DEFAULT_SURVEY_APPEARANCE constant like other fields

Suggested change
thankYouMessageHeader: Optional[str] = Field(default=DEFAULT_SURVEY_APPEARANCE["thankYouMessageHeader"])
thankYouMessageDescription: Optional[str] = Field(default="We appreciate your feedback.")
thankYouMessageHeader: Optional[str] = Field(default=DEFAULT_SURVEY_APPEARANCE["thankYouMessageHeader"])
thankYouMessageDescription: Optional[str] = Field(default=DEFAULT_SURVEY_APPEARANCE["thankYouMessageDescription"])

widgetType: Optional[str] = Field(default=DEFAULT_SURVEY_APPEARANCE["widgetType"])
widgetLabel: Optional[str] = Field(default=DEFAULT_SURVEY_APPEARANCE["widgetLabel"])
widgetColor: Optional[str] = Field(default=DEFAULT_SURVEY_APPEARANCE["widgetColor"])
zIndex: Optional[str] = Field(default=DEFAULT_SURVEY_APPEARANCE["zIndex"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: zIndex should be typed as number instead of str to maintain type consistency and prevent invalid values

Comment on lines +44 to +46
## Current Context
Team survey configuration: {team_survey_config}
Existing surveys: {existing_surveys}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Inconsistent format in template variables - using both {team_survey_config} and {existing_surveys} at line 45-46, but then only {team_survey_config} again at line 73. Ensure consistent context injection.

- **PMF**: "How would you feel if you could no longer use [product]?" (Very disappointed/Somewhat disappointed/Not disappointed)
- **Feedback**: "What could we improve about [feature]?" (open text, optional)
Current team survey settings: {team_survey_config}"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Redundant injection of team_survey_config at end of prompt - already included in 'Current Context' section above. Remove line 73 to avoid confusion.

Comment on lines +74 to +76
# Use the proper serializer for validation and creation
from posthog.api.survey import SurveySerializerCreateUpdateOnly
from datetime import datetime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Move these imports to the top of the file with other imports

Suggested change
# Use the proper serializer for validation and creation
from posthog.api.survey import SurveySerializerCreateUpdateOnly
from datetime import datetime
from posthog.api.survey import SurveySerializerCreateUpdateOnly
from datetime import datetime

Comment on lines +79 to +80
if result.should_launch:
survey_data["start_date"] = datetime.now()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Using datetime.now() without timezone awareness could cause issues. Consider using django.utils.timezone.now()

Comment on lines +163 to +164
except Exception:
return "Unable to load existing surveys"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Bare except clause is too broad - specify which exceptions you expect here for better error handling

You are helping create surveys for this PostHog team.

Current context:
- Total surveys: {{{total_surveys_count}}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ask Max to create a survey
3 participants
0