Write Hog functions with PostHog AI
Contents
PostHog AI writes Hog functions for transformations, filters, and realtime destinations using natural language. Describe what you want the function to do, and PostHog AI generates the code with the correct inputs, event handling, and API calls.
How it works
Describe what you need and PostHog AI generates the function code, configures the correct inputs and variables, handles the event structure and property access patterns, and adds the right API calls for destinations like Slack or webhooks.
You can iterate on the generated code by asking follow-up questions like "add a filter for internal IPs" or "also send the user's email in the Slack message."
Function types PostHog AI can write
| Type | What it does |
|---|---|
| Transformation | Adds, modifies, or removes event properties before they're stored |
| Filter | Drops events that match specific conditions |
| Destination | Sends event data to an external service |
Try it
Select a prompt to try it out in the PostHog app:
Create a Hog function that filters out internal traffic by IPParse event timestamps into day, week, and month propertiesDrop events where test_mode is true or the environment is stagingWrite a transformation that adds a user_tier property based on plan typeCreate a destination function that sends high-value events to Slack
Tips for better results
- Describe the input and output – "Take
$pageviewevents and add apage_categoryproperty based on the URL path" gives PostHog AI enough context to write the transformation - Name specific events and properties – Reference your actual event names (like
purchase_completed) and properties (likeplan_type) so the generated code matches your data - Specify the destination – For destination functions, name the service (Slack, webhook, email) and describe what data to send
- Include edge cases – "Handle cases where
user_emailis null" helps PostHog AI write more robust code - Describe the logic, not the implementation – "Categorize pages into marketing, product, and docs based on URL prefix" lets PostHog AI choose the right approach
Get started
To start writing Hog functions with PostHog AI, set up PostHog AI.