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): point UUID-shaped template_id at template_uuid (#73163)

Harley Alexander1dc7ebab1d81
diff --git a/products/workflows/backend/api/hog_flow.py b/products/workflows/backend/api/hog_flow.py
index 82710347ca23..44ab362b2333 100644
--- a/products/workflows/backend/api/hog_flow.py
+++ b/products/workflows/backend/api/hog_flow.py
@@ -188,6 +188,41 @@ def _first_error_string(detail: Any) -> Optional[str]:
return None
+# The literal template_id each fixed-template node type requires. A saved library template
+# (from workflows-list-email-templates) is referenced via config.template_uuid, never here -
+# putting its UUID in template_id is the dominant authoring mistake on these nodes.
+_FIXED_TEMPLATE_IDS = {
+ "function_email": "template-email",
+ "function_sms": "template-twilio",
+ "function_push": "template-native-push",
+}
+
+
+def _looks_like_uuid(value: str) -> bool:
+ try:
+ uuid_mod.UUID(value)
+ return True
+ except (ValueError, AttributeError, TypeError):
+ return False
+
+
+def _describe_unknown_template(action: dict, template_id: str) -> str:
+ fixed_id = _FIXED_TEMPLATE_IDS.get(action.get("type", ""))
+ if fixed_id and _looks_like_uuid(template_id):
+ return (
+ f"Template not found. template_id must be the literal '{fixed_id}' for this step type. "
+ "To use a saved template from the library, set config.template_uuid to its UUID instead."
+ )
+ if fixed_id:
+ return f"Template not found. template_id must be the literal '{fixed_id}' for this step type."
+ if _looks_like_uuid(template_id):
+ return (
+ "Template not found. Function steps reference a destination template id like "
+ "'template-webhook' (discover them with the template catalog), not a UUID."
+ )
+ return "Template not found"
+
+
def _describe_action_errors(errors: list[Any], actions: list[dict]) -> str:
# The many=True error list mirrors the actions list, with {} entries for valid actions. Raising it
# as-is gets flattened by the exception handler to that first empty dict, so the client sees "{}".
@@ -586,7 +621,7 @@ class HogFlowActionSerializer(serializers.Serializer):
template = HogFunctionTemplate.get_template(template_id)
if not template:
if strict:
- raise serializers.ValidationError({"template_id": "Template not found"})
+ raise serializers.ValidationError({"template_id": _describe_unknown_template(data, template_id)})
else:
input_schema = template.inputs_schema
inputs = data.get("config", {}).get("inputs", {})
diff --git a/products/workflows/backend/api/test/test_hog_flow.py b/products/workflows/backend/api/test/test_hog_flow.py
index f4f5ddb9b817..22bd99b8619d 100644
--- a/products/workflows/backend/api/test/test_hog_flow.py
+++ b/products/workflows/backend/api/test/test_hog_flow.py
@@ -141,6 +141,37 @@ class TestHogFlowAPI(APIBaseTest):
assert "url" in (body["attr"] or ""), body
assert "required" in body["detail"].lower(), body
+ @parameterized.expand(
+ [
+ (
+ "uuid_in_email_template_id",
+ "function_email",
+ "0199aabb-ccdd-0000-1122-334455667788",
+ ["template-email", "template_uuid"],
+ ),
+ (
+ "uuid_in_generic_function",
+ "function",
+ "0199aabb-ccdd-0000-1122-334455667788",
+ ["template-webhook", "not a UUID"],
+ ),
+ ]
+ )
+ def test_unknown_template_id_error_names_the_expected_form(self, _name, action_type, template_id, fragments):
+ # Agents keep putting saved-email-template UUIDs (from the template library) into
+ # config.template_id, where only the fixed literal is valid - the bare "Template not
+ # found" left them retrying formats blind. The error must name the literal and point
+ # UUID-holders at config.template_uuid.
+ hog_flow, action = self._create_hog_flow_with_action({"template_id": template_id, "inputs": {}})
+ action["type"] = action_type
+
+ 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()
+ detail = response.json()["detail"]
+ for fragment in fragments:
+ assert fragment in detail, (fragment, detail)
+
def test_stale_update_is_rejected_with_409(self):
flow_id = self._create_simple_flow()
flow = HogFlow.objects.get(pk=flow_id)