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.

fix(workflows): name the expected syntax when Liquid appears in a hog-templated input (#73162)

Harley Alexanderd0fe1fbf1aeb
diff --git a/posthog/cdp/test/test_validation.py b/posthog/cdp/test/test_validation.py
index 0d017b5a33c9..99aa3a280452 100644
--- a/posthog/cdp/test/test_validation.py
+++ b/posthog/cdp/test/test_validation.py
@@ -1,5 +1,6 @@
import json
+import pytest
from posthog.test.base import APIBaseTest, ClickhouseTestMixin, QueryMatchingTest
from parameterized import parameterized
@@ -375,6 +376,42 @@ class TestHogFunctionValidation(ClickhouseTestMixin, APIBaseTest, QueryMatchingT
assert validated["A"].get("transpiled") is None
assert validated["A"].get("value") == "{inputs.X} + A"
+ @parameterized.expand(
+ [
+ ("string_input", "string", "Hey {{ person.properties.name }}"),
+ (
+ "email_object_input",
+ "native_email",
+ {
+ "to": "{{ person.properties.email }}",
+ "from": "[email protected]",
+ "subject": "Hello",
+ "html": "<p>hi</p>",
+ },
+ ),
+ ]
+ )
+ def test_liquid_syntax_in_hog_templated_input_names_the_expected_syntax(self, _name, item_type, value):
+ # Liquid-style {{ ... }} in a hog-templated field is the dominant authoring mistake
+ # behind template errors, and the transpiler's own message ("Placeholders are not
+ # allowed in this context") never names it - agents bisect blind on it. The error
+ # must state the expected single-curly syntax and call out Liquid.
+ inputs_schema = [{"key": "field", "type": item_type, "required": True}]
+ inputs = {"field": {"value": value}}
+
+ with pytest.raises(ValidationError) as ctx:
+ validate_inputs(inputs_schema, inputs)
+ message = str(ctx.value.detail)
+ assert "{person.properties.email}" in message
+ assert "Liquid" in message
+
+ def test_liquid_templated_input_still_accepts_liquid_syntax(self):
+ inputs_schema = [{"key": "field", "type": "string", "required": True, "templating": "liquid"}]
+ inputs = {"field": {"value": "Hey {{ person.properties.name }}"}}
+
+ validated = validate_inputs(inputs_schema, inputs)
+ assert validated["field"]["value"] == "Hey {{ person.properties.name }}"
+
@parameterized.expand(
[
("person", "{person?.id}"),
diff --git a/posthog/cdp/validation.py b/posthog/cdp/validation.py
index 2cc79a8b3705..4a56b3128831 100644
--- a/posthog/cdp/validation.py
+++ b/posthog/cdp/validation.py
@@ -223,6 +223,16 @@ def transpile_template_code(obj: Any, compiler: JavaScriptCompiler, is_dwh_sourc
return json.dumps(obj)
+def _contains_liquid_style_syntax(value: Any) -> bool:
+ if isinstance(value, str):
+ return "{{" in value
+ if isinstance(value, dict):
+ return any(_contains_liquid_style_syntax(v) for v in value.values())
+ if isinstance(value, list):
+ return any(_contains_liquid_style_syntax(v) for v in value)
+ return False
+
+
@extend_schema_field({"oneOf": [{"type": "boolean"}, {"type": "string", "enum": ["hog", "liquid"]}]})
class _TemplatingChoiceField(serializers.ChoiceField):
"""drf-spectacular 0.29 crashes on sorted() with mixed bool/str choice keys."""
@@ -403,6 +413,19 @@ class InputsItemSerializer(serializers.Serializer):
if "transpiled" in attrs:
del attrs["transpiled"]
except Exception as e:
+ # Liquid-style {{ ... }} in a hog-templated field is the dominant authoring mistake
+ # behind transpile failures, and the compiler's own message ("Placeholders are not
+ # allowed in this context") never names it - callers bisect blind without this hint.
+ if _contains_liquid_style_syntax(value):
+ raise serializers.ValidationError(
+ {
+ "input": (
+ "Invalid template: this field uses single-curly templating like "
+ "{person.properties.email}. Liquid-style {{ ... }} syntax is not "
+ f"supported here. ({str(e)})"
+ )
+ }
+ )
raise serializers.ValidationError({"input": f"Invalid template: {str(e)}"})
return attrs
diff --git a/products/workflows/backend/api/test/test_hog_flow.py b/products/workflows/backend/api/test/test_hog_flow.py
index 7a570c1f048e..f4f5ddb9b817 100644
--- a/products/workflows/backend/api/test/test_hog_flow.py
+++ b/products/workflows/backend/api/test/test_hog_flow.py
@@ -126,6 +126,21 @@ class TestHogFlowAPI(APIBaseTest):
assert "actions" in web_response.json()["results"][0]
assert secret in web_response.content.decode()
+ def test_invalid_action_input_error_carries_the_field_message(self):
+ # A programmatic caller sending a broken function input must get back the validator's
+ # actual message (what is wrong with which field), not a bare code: agents retry blind
+ # on "invalid_input" and thrash. Locks the whole pipeline serializer -> exception
+ # handler envelope.
+ hog_flow, _ = self._create_hog_flow_with_action({"template_id": "template-webhook", "inputs": {}})
+
+ response = self.client.post(f"/api/projects/{self.team.id}/hog_flows", hog_flow, HTTP_X_POSTHOG_CLIENT="mcp")
+
+ assert response.status_code == 400, response.json()
+ body = response.json()
+ assert body["type"] == "validation_error"
+ assert "url" in (body["attr"] or ""), body
+ assert "required" in body["detail"].lower(), body
+
def test_stale_update_is_rejected_with_409(self):
flow_id = self._create_simple_flow()
flow = HogFlow.objects.get(pk=flow_id)