Write Hog functions with PostHog AI

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

TypeWhat it does
TransformationAdds, modifies, or removes event properties before they're stored
FilterDrops events that match specific conditions
DestinationSends event data to an external service

Try it

Select a prompt to try it out in the PostHog app:

Tips for better results

  • Describe the input and output – "Take $pageview events and add a page_category property 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 (like plan_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_email is 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.

Community questions

Was this page useful?

Questions about this page? or post a community question.