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: Warn when hog function variable syntax doesn't match expected (#62728)

Luke Beltona26b4ea078f1
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 44e75683cd3c..46b40b12c6e9 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -5014,6 +5014,10 @@ snapshots:
hash: v1.k794b7964.4947f06455042031427ae2a5f1677d3cd0f25aacf83b9041fb4a659241bb98c5.BGORqjaiNrbMf3NySbKUf0j8PAE2GdEd4C2l8H5FPCA
scenes-app-hogfunctions-destination--configuration--light:
hash: v1.k794b7964.1f55b872709218aa08caa34a7a759f9c03a61e9037c11a8f4a66c48d4fbfb17d.kOgE7mbNXb-EInqnbC04Jqlm_yTmrQolj9l-lU3kc0M
+ scenes-app-hogfunctions-destination--configuration-with-templating-warning--dark:
+ hash: v1.k794b7964.17c5de6021e1e18cfa86321b50acf3f8e29c985d43e5104a04235b93e9a41f22.rUxwPBD7Pzgos2aEKwQDQAlseJ1xWkqFlScea4eAFLM
+ scenes-app-hogfunctions-destination--configuration-with-templating-warning--light:
+ hash: v1.k794b7964.184f915af5342f2d0f5a7ab80ee223f7488cf3927f7d5b299c178cea88f4661c.kt1bwVo0hMXNkLQHb799UxknBlngVxt_Fc6LZDcCPe4
scenes-app-hogfunctions-destination--logs--dark:
hash: v1.k794b7964.9f6e346b5bdaaa41dc9434d8b787dc48d6843ead5931ab214e180d2aa6e1c54f.FmPRcWiNIOxvN_Gq0lmIpoRe4rZZuhdFbc1gnExmu0k
scenes-app-hogfunctions-destination--logs--light:
diff --git a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputs.tsx b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputs.tsx
index 1fa5b22bc5f5..c0d1de573845 100644
--- a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputs.tsx
+++ b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputs.tsx
@@ -5,7 +5,16 @@ import clsx from 'clsx'
import { useActions, useValues } from 'kea'
import { Suspense, useEffect, useMemo, useRef, useState } from 'react'
-import { IconBrackets, IconGear, IconLock, IconPlus, IconToggleOff, IconTrash, IconX } from '@posthog/icons'
+import {
+ IconBrackets,
+ IconGear,
+ IconLock,
+ IconPlus,
+ IconToggleOff,
+ IconTrash,
+ IconWarning,
+ IconX,
+} from '@posthog/icons'
import {
LemonButton,
LemonCheckbox,
@@ -80,6 +89,7 @@ export type CyclotronJobInputsProps = {
onInputChange?: (key: string, input: CyclotronJobInputType) => void
configuration: CyclotronJobInputConfiguration
errors?: Record<string, string>
+ warnings?: Record<string, string>
parentConfiguration?: CyclotronJobInputConfiguration
onInputSchemaChange?: (schema: CyclotronJobInputSchemaType[]) => void
showSource: boolean
@@ -92,6 +102,7 @@ export function CyclotronJobInputs({
onInputSchemaChange,
onInputChange,
errors,
+ warnings,
showSource,
sampleGlobalsWithInputs,
}: CyclotronJobInputsProps): JSX.Element | null {
@@ -130,6 +141,7 @@ export function CyclotronJobInputs({
showSource={showSource}
sampleGlobalsWithInputs={sampleGlobalsWithInputs}
errors={errors}
+ warnings={warnings}
/>
)
})}
@@ -829,11 +841,13 @@ function CyclotronJobInputWithSchema({
showSource,
sampleGlobalsWithInputs,
errors,
+ warnings,
}: CyclotronJobInputWithSchemaProps): JSX.Element | null {
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id: schema.key })
const [editing, setEditing] = useState(false)
const value = configuration.inputs?.[schema.key] ?? { value: null }
const error = errors?.[schema.key]
+ const warning = warnings?.[schema.key]
const onSchemaChange = (newSchema: CyclotronJobInputSchemaType | null): void => {
let inputsSchema = configuration.inputs_schema || []
@@ -978,6 +992,12 @@ function CyclotronJobInputWithSchema({
sampleGlobalsWithInputs={sampleGlobalsWithInputs}
/>
)}
+ {warning && !value?.secret ? (
+ <div className="flex gap-1 items-start mt-1 text-xs text-warning">
+ <IconWarning className="mt-0.5 shrink-0 text-base" />
+ <span>{warning}</span>
+ </div>
+ ) : null}
</>
</LemonField.Pure>
) : (
diff --git a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.test.ts b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.test.ts
index 9885536d8ef1..c8e7f985f11b 100644
--- a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.test.ts
+++ b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.test.ts
@@ -1,6 +1,6 @@
import { CyclotronJobInputSchemaType } from '~/types'
-import { CyclotronJobInputsValidation } from './CyclotronJobInputsValidation'
+import { CyclotronJobInputsValidation, TEMPLATING_MISMATCH_WARNINGS } from './CyclotronJobInputsValidation'
describe('CyclotronJobInputsValidation', () => {
describe('validate', () => {
@@ -10,6 +10,7 @@ describe('CyclotronJobInputsValidation', () => {
expect(result).toEqual({
valid: true,
errors: {},
+ warnings: {},
})
})
@@ -20,6 +21,7 @@ describe('CyclotronJobInputsValidation', () => {
expect(result).toEqual({
valid: true,
errors: {},
+ warnings: {},
})
})
@@ -348,5 +350,143 @@ describe('CyclotronJobInputsValidation', () => {
expect(result.errors.validObject).toBeUndefined()
})
})
+
+ describe('templating mismatch warnings', () => {
+ const W = TEMPLATING_MISMATCH_WARNINGS
+ const stringSchema = (templating?: 'hog' | 'liquid'): CyclotronJobInputSchemaType[] => [
+ { key: 'identifier_value', type: 'string', label: 'Identifier value', templating: templating as any },
+ ]
+
+ it.each<{ name: string; value: string; templating?: 'hog' | 'liquid'; expected: string | undefined }>([
+ // Bare global path with no braces — literal in both engines, only the suggested brace style differs.
+ {
+ name: 'hog field, bare global path → suggests single braces',
+ value: 'person.properties.email',
+ templating: 'hog',
+ expected: W.unbracedExpressionInHogField('person.properties.email'),
+ },
+ {
+ name: 'templating unset (defaults to hog), bare global path',
+ value: 'person.properties.email',
+ templating: undefined,
+ expected: W.unbracedExpressionInHogField('person.properties.email'),
+ },
+ {
+ name: 'liquid field, bare global path → suggests double braces',
+ value: 'person.properties.email',
+ templating: 'liquid',
+ expected: W.unbracedExpressionInLiquidField('person.properties.email'),
+ },
+ // Wrong-engine brace syntax.
+ {
+ name: 'hog field, liquid double-brace syntax',
+ value: '{{ person.properties.email }}',
+ templating: 'hog',
+ expected: W.liquidSyntaxInHogField,
+ },
+ {
+ name: 'liquid field, hog single-brace syntax referencing a global',
+ value: '{person.properties.email}',
+ templating: 'liquid',
+ expected: W.hogSyntaxInLiquidField,
+ },
+ {
+ name: 'liquid field, embedded hog template in literal text',
+ value: 'email: {person.properties.email}',
+ templating: 'liquid',
+ expected: W.hogSyntaxInLiquidField,
+ },
+ {
+ name: 'liquid field, real hog reference inside a JSON-like value',
+ value: '{"id": {person.properties.email}}',
+ templating: 'liquid',
+ expected: W.hogSyntaxInLiquidField,
+ },
+ // Valid values — no warning.
+ {
+ name: 'hog field, correctly braced expression',
+ value: '{person.properties.email}',
+ templating: 'hog',
+ expected: undefined,
+ },
+ {
+ name: 'hog field, valid embedded hog template in literal text',
+ value: 'email: {person.properties.email}',
+ templating: 'hog',
+ expected: undefined,
+ },
+ {
+ name: 'liquid field, valid double braces',
+ value: '{{ person.properties.email }}',
+ templating: 'liquid',
+ expected: undefined,
+ },
+ {
+ name: 'plain literal / static value',
+ value: '[email protected]',
+ templating: 'hog',
+ expected: undefined,
+ },
+ {
+ name: 'liquid field, braces that are not a global reference',
+ value: '{"key": "value"}',
+ templating: 'liquid',
+ expected: undefined,
+ },
+ {
+ name: 'liquid field, JSON key named after a global (not property access)',
+ value: '{"event": "pageview", "person": "abc"}',
+ templating: 'liquid',
+ expected: undefined,
+ },
+ ])('$name', ({ value, templating, expected }) => {
+ const result = CyclotronJobInputsValidation.validate(
+ { identifier_value: { value, templating } },
+ stringSchema(templating)
+ )
+
+ expect(result.warnings.identifier_value).toBe(expected)
+ })
+
+ it('never blocks save — a warning leaves the result valid with no errors', () => {
+ const result = CyclotronJobInputsValidation.validate(
+ { identifier_value: { value: 'person.properties.email' } },
+ stringSchema()
+ )
+
+ expect(result.valid).toBe(true)
+ expect(result.errors).toEqual({})
+ expect(result.warnings.identifier_value).not.toBeUndefined()
+ })
+
+ it('does not warn when templating is disabled for the field', () => {
+ const result = CyclotronJobInputsValidation.validate(
+ { identifier_value: { value: 'person.properties.email' } },
+ [{ key: 'identifier_value', type: 'string', label: 'Identifier value', templating: false }]
+ )
+
+ expect(result.warnings.identifier_value).toBeUndefined()
+ })
+
+ it('skips secret inputs', () => {
+ const result = CyclotronJobInputsValidation.validate(
+ { identifier_value: { value: 'person.properties.email', secret: true } },
+ stringSchema()
+ )
+
+ expect(result.warnings.identifier_value).toBeUndefined()
+ })
+
+ it('detects mismatches inside dictionary values', () => {
+ const result = CyclotronJobInputsValidation.validate(
+ { attributes: { value: { email: 'person.properties.email' } } },
+ [{ key: 'attributes', type: 'dictionary', label: 'Attributes' }]
+ )
+
+ expect(result.warnings.attributes).toBe(
+ TEMPLATING_MISMATCH_WARNINGS.unbracedExpressionInHogField('person.properties.email')
+ )
+ })
+ })
})
})
diff --git a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.ts b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.ts
index a5b9ba1aff60..1e59608a5715 100644
--- a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.ts
+++ b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.ts
@@ -7,6 +7,93 @@ import { CyclotronJobInputSchemaType, CyclotronJobInputType } from '~/types'
export type CyclotronJobInputsValidationResult = {
valid: boolean
errors: Record<string, string>
+ warnings: Record<string, string>
+}
+
+// Roots of the templating globals available to hog functions. Anchoring the
+// mismatch heuristics on these keeps false positives down — literal braces in
+// JSON/text bodies won't trip them unless they look like a global reference.
+const GLOBAL_ROOTS = 'event|person|groups|inputs|source|project'
+
+// A global root immediately followed by property access (`.field` or `[…]`). Requiring the
+// access form is what distinguishes a real expression (`person.properties.email`) from a
+// literal JSON key that happens to be named after a global (`{"event": "pageview"}`).
+const GLOBAL_REFERENCE = `\\b(${GLOBAL_ROOTS})\\s*[.\\[]`
+
+export const TEMPLATING_MISMATCH_WARNINGS = {
+ // Hog single-brace expression authored in a Liquid field — rendered literally.
+ hogSyntaxInLiquidField:
+ 'This looks like Hog syntax ({…}), but the field uses Liquid templating which expects {{ … }}. It will be sent as literal text — switch the templating engine to Hog, or use {{ … }}.',
+ // Liquid double-brace expression authored in a Hog field.
+ liquidSyntaxInHogField:
+ 'This looks like Liquid syntax ({{ … }}), but the field uses Hog templating which expects { … }. Switch the templating engine to Liquid, or use single braces.',
+ // Bare global path with no braces at all — sent literally by either engine. The
+ // suggested fix differs: Hog wraps in { … }, Liquid in {{ … }}.
+ unbracedExpressionInHogField: (expression: string): string =>
+ `This will be sent as literal text. Did you mean {${expression}}? Wrap it in braces to use the value.`,
+ unbracedExpressionInLiquidField: (expression: string): string =>
+ `This will be sent as literal text. Did you mean {{ ${expression} }}? Wrap it in braces to use the value.`,
+} as const
+
+/**
+ * Detect when a value is authored in the wrong templating syntax for its engine.
+ * These are non-blocking warnings: the value still saves, but it would be sent
+ * literally rather than evaluated (e.g. `person.properties.email` with no braces,
+ * or `{ … }` hog syntax in a Liquid field).
+ */
+const detectTemplatingMismatch = (value: unknown, language: 'hog' | 'liquid'): string | undefined => {
+ if (typeof value !== 'string' || !value) {
+ return
+ }
+
+ // A bare global path with no braces at all is literal in BOTH engines, so check it
+ // regardless of language — only the suggested brace style differs.
+ if (!value.includes('{') && new RegExp(`^(${GLOBAL_ROOTS})(\\.[\\w$]+|\\[[^\\]]+\\])+$`).test(value.trim())) {
+ return language === 'liquid'
+ ? TEMPLATING_MISMATCH_WARNINGS.unbracedExpressionInLiquidField(value.trim())
+ : TEMPLATING_MISMATCH_WARNINGS.unbracedExpressionInHogField(value.trim())
+ }
+
+ if (language === 'liquid') {
+ // Strip valid Liquid ({{ }} / {% %}) first, then look for leftover hog-style
+ // single-brace expressions referencing a global — those render literally.
+ const withoutLiquid = value.replace(/\{\{[\s\S]*?\}\}/g, '').replace(/\{%[\s\S]*?%\}/g, '')
+ if (new RegExp(`\\{[^{}]*${GLOBAL_REFERENCE}[^{}]*\\}`).test(withoutLiquid)) {
+ return TEMPLATING_MISMATCH_WARNINGS.hogSyntaxInLiquidField
+ }
+ return
+ }
+
+ // Hog field
+ if (new RegExp(`\\{\\{[^}]*${GLOBAL_REFERENCE}[^}]*\\}\\}`).test(value)) {
+ return TEMPLATING_MISMATCH_WARNINGS.liquidSyntaxInHogField
+ }
+}
+
+const detectInputWarning = (
+ input: CyclotronJobInputType,
+ inputSchema: CyclotronJobInputSchemaType
+): string | undefined => {
+ if (!input || input.secret) {
+ return
+ }
+ if (inputSchema.templating === false) {
+ return
+ }
+ const language = input.templating ?? 'hog'
+
+ if (['string', 'json'].includes(inputSchema.type)) {
+ return detectTemplatingMismatch(input.value, language)
+ }
+
+ if (inputSchema.type === 'dictionary' && input.value && typeof input.value === 'object') {
+ for (const val of Object.values(input.value)) {
+ const warning = detectTemplatingMismatch(val, language)
+ if (warning) {
+ return warning
+ }
+ }
+ }
}
const validateInput = (input: CyclotronJobInputType, inputSchema: CyclotronJobInputSchemaType): string | undefined => {
@@ -104,6 +191,7 @@ export class CyclotronJobInputsValidation {
inputsSchema: CyclotronJobInputSchemaType[]
): CyclotronJobInputsValidationResult {
const inputErrors: Record<string, string> = {}
+ const inputWarnings: Record<string, string> = {}
inputsSchema?.forEach((inputSchema) => {
const input = inputs[inputSchema.key]
@@ -111,11 +199,17 @@ export class CyclotronJobInputsValidation {
if (error) {
inputErrors[inputSchema.key] = error
}
+ const warning = detectInputWarning(input, inputSchema)
+ if (warning) {
+ inputWarnings[inputSchema.key] = warning
+ }
})
return {
+ // Warnings are intentionally excluded from `valid` — they never block save.
valid: Object.keys(inputErrors).length === 0,
errors: inputErrors,
+ warnings: inputWarnings,
}
}
}
diff --git a/frontend/src/scenes/hog-functions/HogFunctionScene.stories.tsx b/frontend/src/scenes/hog-functions/HogFunctionScene.stories.tsx
index 740567303c5c..9ce21bf0a60d 100644
--- a/frontend/src/scenes/hog-functions/HogFunctionScene.stories.tsx
+++ b/frontend/src/scenes/hog-functions/HogFunctionScene.stories.tsx
@@ -100,9 +100,29 @@ const MOCK_BACKFILLS: RawBatchExportBackfill[] = [
},
]
+const MOCK_HOG_FUNCTION_TEMPLATING_WARNING_ID = '0196b144-1f82-0000-0d0d-a01de54d6750'
+
+// A destination whose `identifier` input is authored without braces, so the value would be
+// sent literally instead of evaluated — this is what surfaces the templating-mismatch warning.
+const MOCK_HOG_FUNCTION_TEMPLATING_WARNING = {
+ ...MOCK_HOG_FUNCTION,
+ id: MOCK_HOG_FUNCTION_TEMPLATING_WARNING_ID,
+ batch_export_id: null,
+ inputs_schema: [
+ { key: 'url', type: 'string', label: 'Webhook URL', secret: false, required: true },
+ { key: 'identifier', type: 'string', label: 'Identifier', secret: false, required: false },
+ ],
+ inputs: {
+ url: { value: 'https://example.com/webhook' },
+ identifier: { value: 'person.properties.email' },
+ },
+}
+
const commonMocks = {
get: {
[`/api/environments/:team_id/hog_functions/${MOCK_HOG_FUNCTION_ID}/`]: MOCK_HOG_FUNCTION,
+ [`/api/environments/:team_id/hog_functions/${MOCK_HOG_FUNCTION_TEMPLATING_WARNING_ID}/`]:
+ MOCK_HOG_FUNCTION_TEMPLATING_WARNING,
'/api/environments/:team_id/hog_functions/': { count: 1, results: [MOCK_HOG_FUNCTION], next: null },
[`/api/environments/:team_id/batch_exports/${MOCK_BATCH_EXPORT_ID}/`]: MOCK_BATCH_EXPORT,
[`/api/environments/:team_id/batch_exports/${MOCK_BATCH_EXPORT_ID}/runs/`]: { results: [], next: null },
@@ -224,6 +244,12 @@ export const Configuration: Story = {
},
}
+export const ConfigurationWithTemplatingWarning: Story = {
+ parameters: {
+ pageUrl: urls.hogFunction(MOCK_HOG_FUNCTION_TEMPLATING_WARNING_ID),
+ },
+}
+
const MOCK_HOG_FUNCTION_LOG_RESULTS = {
results: [
[
diff --git a/frontend/src/scenes/hog-functions/configuration/components/HogFunctionInputs.tsx b/frontend/src/scenes/hog-functions/configuration/components/HogFunctionInputs.tsx
index 5ffd8e7cb45f..7b8abe57f9a5 100644
--- a/frontend/src/scenes/hog-functions/configuration/components/HogFunctionInputs.tsx
+++ b/frontend/src/scenes/hog-functions/configuration/components/HogFunctionInputs.tsx
@@ -18,6 +18,7 @@ export function HogFunctionInputs(): JSX.Element {
showSource,
configuration,
configurationErrors,
+ inputFormWarnings,
sampleGlobalsWithInputs,
usesGroups,
hasGroupsAddon,
@@ -52,6 +53,7 @@ export function HogFunctionInputs(): JSX.Element {
<CyclotronJobInputs
errors={(configurationErrors.inputs ?? {}) as Record<string, string>}
+ warnings={inputFormWarnings}
configuration={{
inputs_schema: newInputs ?? configuration.inputs_schema ?? [],
inputs: configuration.inputs ?? {},
diff --git a/frontend/src/scenes/hog-functions/configuration/hogFunctionConfigurationLogic.tsx b/frontend/src/scenes/hog-functions/configuration/hogFunctionConfigurationLogic.tsx
index 31a5ef2cf4bc..7b112b483abc 100644
--- a/frontend/src/scenes/hog-functions/configuration/hogFunctionConfigurationLogic.tsx
+++ b/frontend/src/scenes/hog-functions/configuration/hogFunctionConfigurationLogic.tsx
@@ -10,7 +10,10 @@ import posthog from 'posthog-js'
import { lemonToast } from '@posthog/lemon-ui'
import api from 'lib/api'
-import { CyclotronJobInputsValidation } from 'lib/components/CyclotronJob/CyclotronJobInputsValidation'
+import {
+ CyclotronJobInputsValidation,
+ CyclotronJobInputsValidationResult,
+} from 'lib/components/CyclotronJob/CyclotronJobInputsValidation'
import { dayjs } from 'lib/dayjs'
import { uuid } from 'lib/utils'
import { deleteWithUndo } from 'lib/utils/deleteWithUndo'
@@ -805,16 +808,19 @@ export const hogFunctionConfigurationLogic = kea<hogFunctionConfigurationLogicTy
},
],
- inputFormErrors: [
+ inputsValidation: [
(s) => [s.configuration],
- (configuration): Record<string, string> | null => {
- const result = CyclotronJobInputsValidation.validate(
- configuration.inputs ?? {},
- configuration.inputs_schema ?? []
- )
-
- return result.valid ? null : result.errors
- },
+ (configuration): CyclotronJobInputsValidationResult =>
+ CyclotronJobInputsValidation.validate(configuration.inputs ?? {}, configuration.inputs_schema ?? []),
+ ],
+ inputFormErrors: [
+ (s) => [s.inputsValidation],
+ (inputsValidation): Record<string, string> | null =>
+ inputsValidation.valid ? null : inputsValidation.errors,
+ ],
+ inputFormWarnings: [
+ (s) => [s.inputsValidation],
+ (inputsValidation): Record<string, string> => inputsValidation.warnings,
],
willReEnableOnSave: [
(s) => [s.configuration, s.hogFunction],
diff --git a/products/workflows/frontend/Workflows/workflowLogic.ts b/products/workflows/frontend/Workflows/workflowLogic.ts
index 01332adcf212..55c553414e93 100644
--- a/products/workflows/frontend/Workflows/workflowLogic.ts
+++ b/products/workflows/frontend/Workflows/workflowLogic.ts
@@ -447,6 +447,7 @@ export const workflowLogic = kea<workflowLogicType>([
valid: true,
schema: null,
errors: {},
+ warnings: {},
}
const schemaValidation = HogFlowActionSchema.safeParse(action)
@@ -513,6 +514,7 @@ export const workflowLogic = kea<workflowLogicType>([
// stricter `from` check) is not clobbered by the generic validator.
result.valid = result.valid && configValidation.valid
result.errors = { ...configValidation.errors, ...result.errors }
+ result.warnings = { ...result.warnings, ...configValidation.warnings }
}
}