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(workflows): design-first email authoring for MCP agents (#78879)

Harley Alexander25a7d4d6ab01
diff --git a/products/workflows/mcp/email_templates.yaml b/products/workflows/mcp/email_templates.yaml
index 726f290d4635..0070dc70a773 100644
--- a/products/workflows/mcp/email_templates.yaml
+++ b/products/workflows/mcp/email_templates.yaml
@@ -30,6 +30,8 @@ tools:
works throughout — Liquid tags, apostrophes, and emoji are ordinary JSON characters, so pass the design
inline exactly as authored. Then call workflows-show-email-template and share the _posthogUrl link with the
user.
+ exclude_params:
+ - content.email.html
response:
exclude:
- content
@@ -139,6 +141,8 @@ tools:
back the complete content.email with your edited design. The server re-renders the sent email from the
design on save. After updating, call workflows-show-email-template so the user sees the result, and share
the returned _posthogUrl edit link.
+ exclude_params:
+ - content.email.html
response:
exclude:
- content
diff --git a/products/workflows/skills/building-workflows/SKILL.md b/products/workflows/skills/building-workflows/SKILL.md
index f0cfa3b1f4b4..2d66f1773378 100644
--- a/products/workflows/skills/building-workflows/SKILL.md
+++ b/products/workflows/skills/building-workflows/SKILL.md
@@ -96,14 +96,13 @@ Event trigger, wait 1 day, send email, exit. Note: exactly one `trigger`, every
"type": "function_email",
"config": {
"template_id": "template-email",
+ "template_uuid": "<uuid returned by workflows-create-email-template>",
"message_category_type": "marketing",
"inputs": {
"email": {
"value": {
"to": { "email": "{person.properties.email}", "name": "" },
- "from": { "email": "[email protected]", "name": "Example" },
- "subject": "Don't forget to finish setting up",
- "html": "<p>Hi {person.properties.first_name}, …</p>"
+ "from": { "email": "[email protected]", "name": "Example" }
}
}
}
@@ -124,7 +123,16 @@ Event trigger, wait 1 day, send email, exit. Note: exactly one `trigger`, every
}
```
-For anything beyond a placeholder email body, author the design with the **`designing-email-templates`** skill and reference the template. Don't hand-write production email HTML here.
+Email bodies come from the template library, not hand-written html:
+
+1. **Reuse first.** List the library with `workflows-list-email-templates` and pick a template that fits. A drip campaign typically references one base template (say, a branded announcement) from every email step.
+2. **Create only if nothing fits.** Author a new template design-first with the **`designing-email-templates`** skill: compose the `design`, omit `html` (the server renders html from the design).
+3. **Reference it** by putting the template's UUID in each step's `config.template_uuid`, as above. The save snapshots the template's subject, text, html, and design into the step.
+4. **Differentiate per step** with `workflows-patch-action-email` design operations - each step's snapshot is edited independently, so five steps from one base template can each carry their own content.
+
+The snapshot is one-way: editing the library template later does not change steps that already referenced it, and patching a step never touches the library template. If a user expects a template edit to flow into their workflows, correct that - the steps keep their copies, and each one is updated with `workflows-patch-action-email`.
+
+Always give templates a real plain-text `text` alongside the design: clients that block rich content show only `text`, so filler like "placeholder" reaches real inboxes.
## Hard rules to surface to the user, not work around
diff --git a/products/workflows/skills/designing-email-templates/SKILL.md b/products/workflows/skills/designing-email-templates/SKILL.md
index 3aad8e35bd52..363df0abef6d 100644
--- a/products/workflows/skills/designing-email-templates/SKILL.md
+++ b/products/workflows/skills/designing-email-templates/SKILL.md
@@ -62,7 +62,8 @@ Call `workflows-create-email-template` with:
```
- `subject` is required for email templates.
-- Always provide `text` — it's the fallback for clients that block rich content and improves deliverability.
+- Always author the `design` and omit `html` - the server renders html from the design. Sending hand-written html without a design produces an email the visual editor can only show as one raw block.
+- Always provide `text` as a real plain-text rendering of the message - clients that block rich content show only `text`, so filler like "placeholder" reaches real inboxes, and a text part that doesn't match the html hurts deliverability.
- The tool result returns an edit link into the PostHog library.
- After creating (or updating), call `workflows-show-email-template` — it renders an inline preview so the user sees the result.
@@ -95,5 +96,5 @@ Edit it with `workflows-patch-action-email`: the same design operations as `work
- List what exists with `workflows-list-email-templates` (metadata only; fetch one for its content).
- When the user asks to see a template, call `workflows-show-email-template` — it renders an inline preview.
-- Reference a template from a workflow's `function_email` action, or start a broadcast from it in the PostHog UI.
+- Reference a template from a workflow's `function_email` action (its UUID in `config.template_uuid`), or start a broadcast from it in the PostHog UI. The step takes a snapshot of the template's body at save - editing the library template later does not change steps that already used it. To change a step's email, patch that step with `workflows-patch-action-email`.
- Templates are soft-deleted by setting `deleted: true` via `workflows-update-email-template`.
diff --git a/services/mcp/src/generated/cdp_functions/api.ts b/services/mcp/src/generated/cdp_functions/api.ts
index f8f8fc5cd070..c31c67a4ee29 100644
--- a/services/mcp/src/generated/cdp_functions/api.ts
+++ b/services/mcp/src/generated/cdp_functions/api.ts
@@ -148,10 +148,7 @@ export const HogFunctionsCreateBody = /* @__PURE__ */ zod.object({
events: zod.array(zod.record(zod.string(), zod.unknown())).optional(),
data_warehouse: zod.array(zod.record(zod.string(), zod.unknown())).optional(),
properties: zod.array(zod.record(zod.string(), zod.unknown())).optional(),
- bytecode: zod.unknown().optional(),
- transpiled: zod.unknown().optional(),
filter_test_accounts: zod.boolean().optional(),
- bytecode_error: zod.string().optional(),
})
.optional()
.describe('Event filters that control which events trigger this function.'),
@@ -165,10 +162,6 @@ export const HogFunctionsCreateBody = /* @__PURE__ */ zod.object({
.describe('Time-to-live in seconds for the masking cache (60–86400).'),
threshold: zod.number().nullish().describe('Optional threshold count before masking applies.'),
hash: zod.string().describe('Hog expression used to compute the masking hash.'),
- bytecode: zod
- .unknown()
- .optional()
- .describe('Compiled bytecode for the hash expression. Auto-generated.'),
}),
zod.null(),
])
@@ -402,10 +395,7 @@ export const HogFunctionsPartialUpdateBody = /* @__PURE__ */ zod.object({
events: zod.array(zod.record(zod.string(), zod.unknown())).optional(),
data_warehouse: zod.array(zod.record(zod.string(), zod.unknown())).optional(),
properties: zod.array(zod.record(zod.string(), zod.unknown())).optional(),
- bytecode: zod.unknown().optional(),
- transpiled: zod.unknown().optional(),
filter_test_accounts: zod.boolean().optional(),
- bytecode_error: zod.string().optional(),
})
.optional()
.describe('Event filters that control which events trigger this function.'),
@@ -419,10 +409,6 @@ export const HogFunctionsPartialUpdateBody = /* @__PURE__ */ zod.object({
.describe('Time-to-live in seconds for the masking cache (60–86400).'),
threshold: zod.number().nullish().describe('Optional threshold count before masking applies.'),
hash: zod.string().describe('Hog expression used to compute the masking hash.'),
- bytecode: zod
- .unknown()
- .optional()
- .describe('Compiled bytecode for the hash expression. Auto-generated.'),
}),
zod.null(),
])
diff --git a/services/mcp/src/generated/email_templates/api.ts b/services/mcp/src/generated/email_templates/api.ts
index fbf88052a6af..1bbe26d96411 100644
--- a/services/mcp/src/generated/email_templates/api.ts
+++ b/services/mcp/src/generated/email_templates/api.ts
@@ -62,12 +62,6 @@ export const MessagingTemplatesCreateBody = /* @__PURE__ */ zod.object({
.string()
.optional()
.describe("Plain-text fallback body for clients that can't render the email."),
- html: zod
- .string()
- .optional()
- .describe(
- "Rendered email body — derived from the design at save time. The visual editor's save path supplies it directly; omit it otherwise."
- ),
design: zod
.object({
counters: zod
@@ -170,12 +164,6 @@ export const MessagingTemplatesPartialUpdateBody = /* @__PURE__ */ zod.object({
.string()
.optional()
.describe("Plain-text fallback body for clients that can't render the email."),
- html: zod
- .string()
- .optional()
- .describe(
- "Rendered email body — derived from the design at save time. The visual editor's save path supplies it directly; omit it otherwise."
- ),
design: zod
.object({
counters: zod
diff --git a/services/mcp/src/generated/error_tracking_alerts/api.ts b/services/mcp/src/generated/error_tracking_alerts/api.ts
index 20b8778d03a8..769dffea43fb 100644
--- a/services/mcp/src/generated/error_tracking_alerts/api.ts
+++ b/services/mcp/src/generated/error_tracking_alerts/api.ts
@@ -148,10 +148,7 @@ export const HogFunctionsCreateBody = /* @__PURE__ */ zod.object({
events: zod.array(zod.record(zod.string(), zod.unknown())).optional(),
data_warehouse: zod.array(zod.record(zod.string(), zod.unknown())).optional(),
properties: zod.array(zod.record(zod.string(), zod.unknown())).optional(),
- bytecode: zod.unknown().optional(),
- transpiled: zod.unknown().optional(),
filter_test_accounts: zod.boolean().optional(),
- bytecode_error: zod.string().optional(),
})
.optional()
.describe('Event filters that control which events trigger this function.'),
@@ -165,10 +162,6 @@ export const HogFunctionsCreateBody = /* @__PURE__ */ zod.object({
.describe('Time-to-live in seconds for the masking cache (60–86400).'),
threshold: zod.number().nullish().describe('Optional threshold count before masking applies.'),
hash: zod.string().describe('Hog expression used to compute the masking hash.'),
- bytecode: zod
- .unknown()
- .optional()
- .describe('Compiled bytecode for the hash expression. Auto-generated.'),
}),
zod.null(),
])
@@ -393,10 +386,7 @@ export const HogFunctionsPartialUpdateBody = /* @__PURE__ */ zod.object({
events: zod.array(zod.record(zod.string(), zod.unknown())).optional(),
data_warehouse: zod.array(zod.record(zod.string(), zod.unknown())).optional(),
properties: zod.array(zod.record(zod.string(), zod.unknown())).optional(),
- bytecode: zod.unknown().optional(),
- transpiled: zod.unknown().optional(),
filter_test_accounts: zod.boolean().optional(),
- bytecode_error: zod.string().optional(),
})
.optional()
.describe('Event filters that control which events trigger this function.'),
@@ -410,10 +400,6 @@ export const HogFunctionsPartialUpdateBody = /* @__PURE__ */ zod.object({
.describe('Time-to-live in seconds for the masking cache (60–86400).'),
threshold: zod.number().nullish().describe('Optional threshold count before masking applies.'),
hash: zod.string().describe('Hog expression used to compute the masking hash.'),
- bytecode: zod
- .unknown()
- .optional()
- .describe('Compiled bytecode for the hash expression. Auto-generated.'),
}),
zod.null(),
])
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/cdp-functions-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/cdp-functions-create.json
index 4ae398758423..ba7b0e4e5f8f 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/cdp-functions-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/cdp-functions-create.json
@@ -35,10 +35,6 @@
},
"type": "array"
},
- "bytecode": {},
- "bytecode_error": {
- "type": "string"
- },
"data_warehouse": {
"items": {
"additionalProperties": {},
@@ -77,8 +73,7 @@
"description": "* `events` - events\n* `person-updates` - person-updates\n* `data-warehouse-table` - data-warehouse-table",
"enum": ["events", "person-updates", "data-warehouse-table"],
"type": "string"
- },
- "transpiled": {}
+ }
},
"type": "object"
},
@@ -382,9 +377,6 @@
"anyOf": [
{
"properties": {
- "bytecode": {
- "description": "Compiled bytecode for the hash expression. Auto-generated."
- },
"hash": {
"description": "Hog expression used to compute the masking hash.",
"type": "string"
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/cdp-functions-partial-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/cdp-functions-partial-update.json
index 681b6419f4ef..787e8ae96399 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/cdp-functions-partial-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/cdp-functions-partial-update.json
@@ -41,10 +41,6 @@
},
"type": "array"
},
- "bytecode": {},
- "bytecode_error": {
- "type": "string"
- },
"data_warehouse": {
"items": {
"additionalProperties": {},
@@ -83,8 +79,7 @@
"description": "* `events` - events\n* `person-updates` - person-updates\n* `data-warehouse-table` - data-warehouse-table",
"enum": ["events", "person-updates", "data-warehouse-table"],
"type": "string"
- },
- "transpiled": {}
+ }
},
"type": "object"
},
@@ -392,9 +387,6 @@
"anyOf": [
{
"properties": {
- "bytecode": {
- "description": "Compiled bytecode for the hash expression. Auto-generated."
- },
"hash": {
"description": "Hog expression used to compute the masking hash.",
"type": "string"
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-alerts-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-alerts-create.json
index 1b7f47d262aa..ac47dd9e485c 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-alerts-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-alerts-create.json
@@ -35,10 +35,6 @@
},
"type": "array"
},
- "bytecode": {},
- "bytecode_error": {
- "type": "string"
- },
"data_warehouse": {
"items": {
"additionalProperties": {},
@@ -77,8 +73,7 @@
"description": "* `events` - events\n* `person-updates` - person-updates\n* `data-warehouse-table` - data-warehouse-table",
"enum": ["events", "person-updates", "data-warehouse-table"],
"type": "string"
- },
- "transpiled": {}
+ }
},
"type": "object"
},
@@ -382,9 +377,6 @@
"anyOf": [
{
"properties": {
- "bytecode": {
- "description": "Compiled bytecode for the hash expression. Auto-generated."
- },
"hash": {
"description": "Hog expression used to compute the masking hash.",
"type": "string"
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-alerts-partial-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-alerts-partial-update.json
index 752638b8377d..30e644bdcafa 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-alerts-partial-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-alerts-partial-update.json
@@ -41,10 +41,6 @@
},
"type": "array"
},
- "bytecode": {},
- "bytecode_error": {
- "type": "string"
- },
"data_warehouse": {
"items": {
"additionalProperties": {},
@@ -83,8 +79,7 @@
"description": "* `events` - events\n* `person-updates` - person-updates\n* `data-warehouse-table` - data-warehouse-table",
"enum": ["events", "person-updates", "data-warehouse-table"],
"type": "string"
- },
- "transpiled": {}
+ }
},
"type": "object"
},
@@ -392,9 +387,6 @@
"anyOf": [
{
"properties": {
- "bytecode": {
- "description": "Compiled bytecode for the hash expression. Auto-generated."
- },
"hash": {
"description": "Hog expression used to compute the masking hash.",
"type": "string"
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/workflows-create-email-template.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/workflows-create-email-template.json
index 49dc68fc7ddc..dbd860a6fac9 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/workflows-create-email-template.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/workflows-create-email-template.json
@@ -66,10 +66,6 @@
"required": ["schemaVersion", "body"],
"type": "object"
},
- "html": {
- "description": "Rendered email body — derived from the design at save time. The visual editor's save path supplies it directly; omit it otherwise.",
- "type": "string"
- },
"subject": {
"description": "Email subject line. Supports Liquid templating. Required for email-type templates.",
"type": "string"
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/workflows-update-email-template.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/workflows-update-email-template.json
index 8460643cc954..91d43313d24e 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/workflows-update-email-template.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/workflows-update-email-template.json
@@ -66,10 +66,6 @@
"required": ["schemaVersion", "body"],
"type": "object"
},
- "html": {
- "description": "Rendered email body — derived from the design at save time. The visual editor's save path supplies it directly; omit it otherwise.",
- "type": "string"
- },
"subject": {
"description": "Email subject line. Supports Liquid templating. Required for email-type templates.",
"type": "string"
diff --git a/tools/openapi-codegen/src/exclusions.mjs b/tools/openapi-codegen/src/exclusions.mjs
index 526a12cb9519..f3a915dc6d3c 100644
--- a/tools/openapi-codegen/src/exclusions.mjs
+++ b/tools/openapi-codegen/src/exclusions.mjs
@@ -66,6 +66,18 @@ function excludePath(spec, parentObj, parentKey, segments) {
return
}
+ // oneOf/anyOf/allOf wrap the object schema without consuming a path segment —
+ // e.g. a nullable nested serializer renders as oneOf: [$ref, {type: null}]
+ for (const variantKey of ['oneOf', 'anyOf', 'allOf']) {
+ const variants = schema[variantKey]
+ if (!Array.isArray(variants)) {
+ continue
+ }
+ for (let i = 0; i < variants.length; i++) {
+ excludePath(spec, variants, i, segments)
+ }
+ }
+
if (tail.length === 0) {
if (schema.properties?.[head]) {
delete schema.properties[head]
diff --git a/tools/openapi-codegen/tests/exclusions.test.mjs b/tools/openapi-codegen/tests/exclusions.test.mjs
index 12bd3b519bad..501dd8585b68 100644
--- a/tools/openapi-codegen/tests/exclusions.test.mjs
+++ b/tools/openapi-codegen/tests/exclusions.test.mjs
@@ -154,6 +154,69 @@ describe('applyNestedExclusions', () => {
expect(configProps).toHaveProperty('keep')
})
+ it('descends into oneOf variants (nullable nested serializer)', () => {
+ // drf-spectacular renders a nullable nested serializer as oneOf: [$ref, {type: null}],
+ // the shape of content.email on message templates.
+ const spec = {
+ paths: {
+ '/api/templates/': {
+ post: {
+ operationId: 'templates_create',
+ requestBody: {
+ content: {
+ 'application/json': {
+ schema: {
+ type: 'object',
+ properties: {
+ content: {
+ type: 'object',
+ properties: {
+ email: {
+ oneOf: [
+ { $ref: '#/components/schemas/EmailTemplate' },
+ { type: 'null' },
+ ],
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ components: {
+ schemas: {
+ EmailTemplate: {
+ type: 'object',
+ properties: {
+ subject: { type: 'string' },
+ html: { type: 'string' },
+ design: { type: 'object' },
+ },
+ },
+ },
+ },
+ }
+
+ applyNestedExclusions(spec, new Map([['templates_create', ['content.email.html']]]))
+
+ // Shared component schema must be untouched
+ expect(spec.components.schemas.EmailTemplate.properties).toHaveProperty('html')
+
+ const emailSchema =
+ spec.paths['/api/templates/'].post.requestBody.content['application/json'].schema.properties.content
+ .properties.email
+ const objectVariant = emailSchema.oneOf.find((v) => v.type === 'object')
+ expect(objectVariant).not.toHaveProperty('$ref')
+ expect(objectVariant.properties).not.toHaveProperty('html')
+ expect(objectVariant.properties).toHaveProperty('subject')
+ expect(objectVariant.properties).toHaveProperty('design')
+ expect(emailSchema.oneOf.find((v) => v.type === 'null')).toBeTruthy()
+ })
+
it('resolves $ref at the request body level', () => {
const spec = {
paths: {