: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(alerts): expose the SQL alert label column in every mode (#65158)
Vasco de Krijgerdcac5d764d47
diff --git a/frontend/src/lib/components/Alerts/alertFormLogic.test.ts b/frontend/src/lib/components/Alerts/alertFormLogic.test.tsindex ec4498e2a074..315a50ca1486 100644--- a/frontend/src/lib/components/Alerts/alertFormLogic.test.ts+++ b/frontend/src/lib/components/Alerts/alertFormLogic.test.ts@@ -317,7 +317,7 @@ describe('alertFormLogic', () => {it.each([{- name: 'prefills the single numeric column when none is picked (no label in last-row mode)',+ name: 'prefills the value column and the first non-evaluated column as label (last-row mode)',config: {},insightData: {columns: ['day', 'count'],@@ -327,28 +327,28 @@ describe('alertFormLogic', () => {],},expectedColumn: 'count',- expectedLabelColumn: undefined,+ expectedLabelColumn: 'day',},{- name: 'keeps an explicit pick',+ name: 'keeps an explicit pick and labels by the other column',config: { column: 'a' },insightData: { columns: ['a', 'b'], results: [[1, 2]] },expectedColumn: 'a',- expectedLabelColumn: undefined,+ expectedLabelColumn: 'b',},{name: 'prefills the last numeric column when several are numeric',config: {},insightData: { columns: ['a', 'b'], results: [[1, 2]] },expectedColumn: 'b',- expectedLabelColumn: undefined,+ expectedLabelColumn: 'a',},{name: 'skips a trailing non-numeric column when picking the last numeric one',config: {},insightData: { columns: ['value', 'day'], results: [[5, '2026-06-01']] },expectedColumn: 'value',- expectedLabelColumn: undefined,+ expectedLabelColumn: 'day',},{name: 'does not prefill when no column is numeric',@@ -371,6 +371,13 @@ describe('alertFormLogic', () => {expectedColumn: 'count',expectedLabelColumn: 'day',},+ {+ name: 'prefills the label in first-row mode too (all modes unified)',+ config: { evaluation: 'first_row' },+ insightData: { columns: ['day', 'count'], results: [['2026-06-01', 1]] },+ expectedColumn: 'count',+ expectedLabelColumn: 'day',+ },{name: 'keeps an explicit label pick',config: { evaluation: 'any_row', label_column: 'a' },diff --git a/frontend/src/lib/components/Alerts/alertFormLogic.ts b/frontend/src/lib/components/Alerts/alertFormLogic.tsindex aa119fb9ae13..dd3057856248 100644--- a/frontend/src/lib/components/Alerts/alertFormLogic.ts+++ b/frontend/src/lib/components/Alerts/alertFormLogic.ts@@ -436,10 +436,11 @@ export const alertFormLogic = kea<alertFormLogicType>([? numericColumns[numericColumns.length - 1]: null,],- /** Unset SQL config fields to materialize: the evaluated column (last numeric) and, in- * any-row mode, the label (first column that isn't evaluated — the backend fallback).- * Computed together so prefilling lands in a single form write with no ordering- * between the fields. Null when there's nothing to fill. */+ /** Unset SQL config fields to materialize: the evaluated column (last numeric) and the+ * label (first column that isn't evaluated — the backend fallback). Both apply in every+ * evaluation mode: the label names the evaluated row(s) in breach messages regardless of+ * last/first/any-row. Computed together so prefilling lands in a single form write with+ * no ordering between the fields. Null when there's nothing to fill. */hogqlConfigPrefill: [(s) => [s.hogqlResultColumns,@@ -459,7 +460,7 @@ export const alertFormLogic = kea<alertFormLogicType>([patch.column = suggestedColumn}const evaluated = config.column ?? suggestedColumn- if (config.evaluation === 'any_row' && config.label_column == null && evaluated != null) {+ if (config.label_column == null && evaluated != null) {const label = resultColumns?.find((column) => column !== evaluated)if (label != null) {patch.label_column = labeldiff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 10d764b3da7b..6ae25b19a7f7 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -23327,7 +23327,7 @@"description": "How to read the result rows — an explicit choice, no implicit default."},"label_column": {- "description": "In `any_row` mode, the column whose value labels each row in breach messages. When unset, the first non-evaluated column is used, falling back to the row number.",+ "description": "Column whose value labels the evaluated row(s) in breach messages: every row in `any_row` mode, or the single evaluated row in `last_row`/`first_row`. When unset, the first non-evaluated column is used, falling back to the row number (any_row) or the value column name (last_row/first_row).","type": ["string", "null"]},"type": {diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.tsindex dd07c04ec403..1060bdba5339 100644--- a/frontend/src/queries/schema/schema-general.ts+++ b/frontend/src/queries/schema/schema-general.ts@@ -4847,8 +4847,10 @@ export interface HogQLAlertConfig {column?: string | null/** How to read the result rows — an explicit choice, no implicit default. */evaluation: HogQLAlertEvaluation- /** In `any_row` mode, the column whose value labels each row in breach messages.- * When unset, the first non-evaluated column is used, falling back to the row number. */+ /** Column whose value labels the evaluated row(s) in breach messages: every row in `any_row`+ * mode, or the single evaluated row in `last_row`/`first_row`. When unset, the first+ * non-evaluated column is used, falling back to the row number (any_row) or the value column+ * name (last_row/first_row). */label_column?: string | null}diff --git a/posthog/schema.py b/posthog/schema.pyindex 09296bdf8d20..4595f04c7c3b 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -5340,9 +5340,11 @@ class HogQLAlertConfig(BaseModel):label_column: str | None = Field(default=None,description=(- "In `any_row` mode, the column whose value labels each row in breach"- " messages. When unset, the first non-evaluated column is used, falling"- " back to the row number."+ "Column whose value labels the evaluated row(s) in breach messages: every"+ " row in `any_row` mode, or the single evaluated row in"+ " `last_row`/`first_row`. When unset, the first non-evaluated column is"+ " used, falling back to the row number (any_row) or the value column name"+ " (last_row/first_row)."),)type: Literal["HogQLAlertConfig"] = "HogQLAlertConfig"diff --git a/products/alerts/backend/api/alert.py b/products/alerts/backend/api/alert.pyindex fa9cd623a411..530497f77b7d 100644--- a/products/alerts/backend/api/alert.py+++ b/products/alerts/backend/api/alert.py@@ -225,7 +225,7 @@ class AlertSerializer(SearchMatchTypeSerializerMixin, serializers.ModelSerialize"interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to ""the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, ""'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and "- "label_column (labels rows in breach messages for any_row)."+ "label_column (names the evaluated row(s) in breach messages, in every evaluation mode)."),)detector_config = DetectorConfigField(required=False, allow_null=True)diff --git a/products/alerts/backend/evaluation/comparator.py b/products/alerts/backend/evaluation/comparator.pyindex 0b48227e7712..8bbb197e8ab1 100644--- a/products/alerts/backend/evaluation/comparator.py+++ b/products/alerts/backend/evaluation/comparator.py@@ -129,7 +129,7 @@ def evaluate_threshold(condition.type,subject=result.subject,framed=result.framed,- include_series=result.is_breakdown,+ include_series=result.is_breakdown or result.include_series_label,interval_type=result.interval_type,series=s.label,is_current_interval=s.is_current_interval,diff --git a/products/alerts/backend/evaluation/contract.py b/products/alerts/backend/evaluation/contract.pyindex 4ca264987558..1fb6cdab32b5 100644--- a/products/alerts/backend/evaluation/contract.py+++ b/products/alerts/backend/evaluation/contract.py@@ -44,6 +44,10 @@ class ExtractionResult:# any-row SQL alerts use this so the notification names all violating rows. Trends breakdowns# keep first-breach-only for parity with their historical messages.aggregate_breaches: bool = False+ # Name the (single) series in the breach message even when it isn't a breakdown — single-row SQL+ # alerts set this so a resolved label column surfaces, e.g. "(Burn rate 24h)". Breakdowns already+ # name every row via ``is_breakdown``; this covers the one-series case where the name is meaningful.+ include_series_label: bool = Falsedef zero_sentinel_series() -> ComparableSeries:diff --git a/products/alerts/backend/evaluation/hogql.py b/products/alerts/backend/evaluation/hogql.pyindex e9b65f0c157a..7ba9564b17d4 100644--- a/products/alerts/backend/evaluation/hogql.py+++ b/products/alerts/backend/evaluation/hogql.py@@ -44,6 +44,7 @@ class HogQLExtractor:The head is unaffected by result truncation and pairs with a user ``LIMIT``, so this isthe mode for queries that would otherwise return very many rows.- ``any_row``: every row is checked and fires if any value breaches, labeling each row.+ In every mode the label column (the METRIC column in the preview) names the evaluated row(s).The shared comparator interprets the resulting series either way.PREVIEW MIRROR CONTRACT: the configure-time preview re-implements this extractor's decision@@ -54,7 +55,11 @@ class HogQLExtractor:1. value-column resolution: explicit ``column`` -> single column -> single numeric column2. numeric classification: most recent non-None cell decides; bools are not numeric3. ``None`` cells evaluate as 0- 4. label-column resolution: explicit -> first non-evaluated column -> row number+ 4. label-column resolution: explicit -> first non-evaluated column (the mirror reproduces+ this). The fallback when a row has no label cell differs by surface and is NOT mirrored:+ the preview falls back to the row number (it shows every row, so numbering keeps them+ distinct), whereas this extractor's single evaluated row (last_row/first_row) falls back+ to the value column name — there's only one row, so a number carries no information.5. empty result evaluates as 0 (zero sentinel)6. any-row cap: ``ANY_ROW_MAX_ROWS`` (mirrored as ``HOGQL_ANY_ROW_MAX_ROWS``)7. anchor row: ``last_row`` reads the tail, ``first_row`` the head; both yield (previous, current)@@ -139,9 +144,23 @@ class HogQLExtractor:raise AlertExtractionError("Relative alerts on SQL insights need at least two rows (current and previous).")points = [SeriesPoint(date=None, value=v) for v in values]- series_label = column_names[value_index] if column_names and value_index < len(column_names) else "result"+ value_column_name = column_names[value_index] if column_names and value_index < len(column_names) else "result"+ # Label the evaluated row by its label column (the METRIC column shown in the preview),+ # falling back to the value column name when the result has no distinct label column.+ label_index = _resolve_label_column_index(config.label_column, column_names, value_index, rows)+ anchor_row = rows[0] if evaluation == HogQLAlertEvaluation.FIRST_ROW else rows[-1]+ label_cell = _label_cell(anchor_row, label_index)+ series_label = label_cell if label_cell is not None else value_column_namesingle = ComparableSeries(label=series_label, points=points, current_index=len(points) - 1)- return ExtractionResult(series=[single], is_breakdown=False, subject=_HOGQL_SUBJECT, framed=False)+ # Surface the label in the breach message only when it's a real label cell — the value-column+ # fallback would just read "The SQL insight value (value) (...)", which adds nothing.+ return ExtractionResult(+ series=[single],+ is_breakdown=False,+ subject=_HOGQL_SUBJECT,+ framed=False,+ include_series_label=label_cell is not None,+ )def _resolve_value_column_index(configured: str | None, column_names: list[str] | None, rows: list) -> int:@@ -195,12 +214,18 @@ def _resolve_label_column_index(return None-def _label_for_row(row: Any, index: int, label_index: int | None) -> str:+def _label_cell(row: Any, label_index: int | None) -> str | None:+ # None when there's no usable label cell — the caller picks the mode-specific fallback.if label_index is not None and isinstance(row, list | tuple) and label_index < len(row):cell = row[label_index]if cell is not None:return str(cell)- return f"row {index + 1}"+ return None+++def _label_for_row(row: Any, index: int, label_index: int | None) -> str:+ cell = _label_cell(row, label_index)+ return cell if cell is not None else f"row {index + 1}"def _row_width(rows: list) -> int:diff --git a/products/alerts/backend/evaluation/test/test_hogql_extractor.py b/products/alerts/backend/evaluation/test/test_hogql_extractor.pyindex 193b5d232537..0ba50983d152 100644--- a/products/alerts/backend/evaluation/test/test_hogql_extractor.py+++ b/products/alerts/backend/evaluation/test/test_hogql_extractor.py@@ -122,7 +122,8 @@ def test_single_numeric_column_heuristic_skips_date_column():rows = [["2024-01-01", 10], ["2024-01-02", 42]]result = _extract(rows, columns=["day", "value"])assert [p.value for p in result.series[0].points] == [10.0, 42.0]- assert result.series[0].label == "value"+ # The first non-evaluated column labels the evaluated (last) row — here the day.+ assert result.series[0].label == "2024-01-02"@pytest.mark.parametrize(@@ -141,7 +142,8 @@ def test_explicit_column_pick():rows = [["2024-01-01", 1, 10], ["2024-01-02", 2, 42]]result = _extract(rows, columns=["day", "errors", "total"], config={"type": "HogQLAlertConfig", "column": "total"})assert [p.value for p in result.series[0].points] == [10.0, 42.0]- assert result.series[0].label == "total"+ # Evaluates "total"; the label auto-derives to the first non-evaluated column ("day").+ assert result.series[0].label == "2024-01-02"def test_explicit_column_not_in_result_raises():@@ -179,6 +181,20 @@ def test_absolute_alert_breaches_on_last_row():assert evaluation.breaches[0] == "The SQL insight value (200.0) is more than upper threshold (100.0)"+def test_single_row_breach_message_names_the_label():+ # A resolved label column surfaces in the threshold breach message, like any-row does.+ result = _extract([["Burn rate 1h", 10], ["Burn rate 24h", 200]], columns=["metric", "value"])+ evaluation = evaluate_threshold(result, ABSOLUTE, _threshold(upper=100))+ assert evaluation.breaches == ["The SQL insight value (Burn rate 24h) (200.0) is more than upper threshold (100.0)"]+++def test_single_row_breach_message_omits_label_without_a_label_column():+ # No distinct label column → value-column fallback isn't surfaced (no redundant "(value)").+ result = _extract([[10], [200]], columns=["value"])+ evaluation = evaluate_threshold(result, ABSOLUTE, _threshold(upper=100))+ assert evaluation.breaches == ["The SQL insight value (200.0) is more than upper threshold (100.0)"]++def test_relative_alert_needs_two_rows():with pytest.raises(AlertExtractionError, match="at least two rows"):_extract([[5]], condition_type=AlertConditionType.RELATIVE_INCREASE)@@ -217,6 +233,35 @@ def test_first_row_has_no_cap():assert result.series[0].points[result.series[0].current_index].value == 0.0 # row 0+ "evaluation,expected_label",+ [+ ("last_row", "Burn rate 24h"), # tail row is the evaluated one+ ("first_row", "Burn rate 1h"), # head row is the evaluated one+ ],+)+def test_single_row_labels_evaluated_row_by_label_column(evaluation, expected_label):+ # The label column names the evaluated row (tail for last_row, head for first_row) in breach messages.+ rows = [["Burn rate 1h", 0.93], ["Burn rate 24h", 1.03]]+ result = _extract(+ rows,+ columns=["metric", "value"],+ config={"type": "HogQLAlertConfig", "evaluation": evaluation, "label_column": "metric"},+ )+ assert result.series[0].label == expected_label+++def test_single_row_label_falls_back_to_value_column_when_single_column():+ # No distinct label column to derive from → fall back to the value column name, not "row N".+ result = _extract([[10], [42]], columns=["value"])+ assert result.series[0].label == "value"+++def test_single_row_missing_label_column_raises():+ with pytest.raises(AlertExtractionError, match="label column"):+ _extract([["a", 1]], columns=["metric", "value"], config={"type": "HogQLAlertConfig", "label_column": "gone"})++def test_any_row_breaches_on_any_value_with_row_label():rows = [["US", 0.1], ["DE", 0.4], ["FR", 0.2]]result = _extract(diff --git a/products/alerts/frontend/components/editAlertModal/AlertDefinitionFields.tsx b/products/alerts/frontend/components/editAlertModal/AlertDefinitionFields.tsxindex fb499338fe1f..f8b9b3ce1594 100644--- a/products/alerts/frontend/components/editAlertModal/AlertDefinitionFields.tsx+++ b/products/alerts/frontend/components/editAlertModal/AlertDefinitionFields.tsx@@ -5,7 +5,6 @@ import { LemonSelect, Tooltip } from '@posthog/lemon-ui'import { AlertFormType } from 'lib/components/Alerts/alertFormLogic'import { HogQLAlertPreview } from 'lib/components/Alerts/hogqlAlertPreview'-import { isAnyRowHogQLConfig } from 'lib/components/Alerts/types'import { LemonField } from 'lib/lemon-ui/LemonField'import { alphabet } from 'lib/utils/strings'@@ -77,7 +76,6 @@ export function HogQLDefinitionFields({onSetAlertFormValue: <K extends keyof AlertFormType>(key: K, value: AlertFormType[K]) => void}): JSX.Element {const hasMultipleColumns = (hogqlColumns?.length ?? 0) > 1- const isAnyRow = isAnyRowHogQLConfig(alertForm.config)return (<><div className="flex gap-3 items-center">@@ -133,9 +131,9 @@ export function HogQLDefinitionFields({)}</Group></div>- {isAnyRow && hasMultipleColumns && (+ {hasMultipleColumns && (<div className="flex gap-3 items-center">- <Tooltip title="Names the breaching row in notifications and the check history.">+ <Tooltip title="Names the evaluated row in notifications and the check history."><div className="flex items-center gap-1">Labeled by <IconInfo className="text-muted" /></div>diff --git a/products/alerts/frontend/generated/api.schemas.ts b/products/alerts/frontend/generated/api.schemas.tsindex 9b6cb11454cb..08fee0eb14ab 100644--- a/products/alerts/frontend/generated/api.schemas.ts+++ b/products/alerts/frontend/generated/api.schemas.ts@@ -208,7 +208,7 @@ export interface HogQLAlertConfigApi {column?: string | null/** How to read the result rows — an explicit choice, no implicit default. */evaluation: HogQLAlertEvaluationApi- /** In `any_row` mode, the column whose value labels each row in breach messages. When unset, the first non-evaluated column is used, falling back to the row number. */+ /** Column whose value labels the evaluated row(s) in breach messages: every row in `any_row` mode, or the single evaluated row in `last_row`/`first_row`. When unset, the first non-evaluated column is used, falling back to the row number (any_row) or the value column name (last_row/first_row). */label_column?: string | nulltype: HogQLAlertConfigApiType}@@ -495,7 +495,7 @@ export interface AlertApi {* @nullable*/readonly checks_total: number | null- /** Per-insight-kind alert configuration, discriminated by `type`. TrendsAlertConfig: series_index (which series to monitor) and check_ongoing_interval (whether to check the current incomplete interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, 'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and label_column (labels rows in breach messages for any_row). */+ /** Per-insight-kind alert configuration, discriminated by `type`. TrendsAlertConfig: series_index (which series to monitor) and check_ongoing_interval (whether to check the current incomplete interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, 'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and label_column (names the evaluated row(s) in breach messages, in every evaluation mode). */config?: AlertConfigUnionApi | nulldetector_config?: DetectorConfigApi | null/** How often the alert is checked: every 15 minutes (Boost+), hourly, daily, weekly, or monthly.@@ -576,7 +576,7 @@ export interface PatchedAlertApi {* @nullable*/readonly checks_total?: number | null- /** Per-insight-kind alert configuration, discriminated by `type`. TrendsAlertConfig: series_index (which series to monitor) and check_ongoing_interval (whether to check the current incomplete interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, 'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and label_column (labels rows in breach messages for any_row). */+ /** Per-insight-kind alert configuration, discriminated by `type`. TrendsAlertConfig: series_index (which series to monitor) and check_ongoing_interval (whether to check the current incomplete interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, 'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and label_column (names the evaluated row(s) in breach messages, in every evaluation mode). */config?: AlertConfigUnionApi | nulldetector_config?: DetectorConfigApi | null/** How often the alert is checked: every 15 minutes (Boost+), hourly, daily, weekly, or monthly.diff --git a/products/alerts/mcp/tools.yaml b/products/alerts/mcp/tools.yamlindex 8aaada37b5d6..e4a298f39683 100644--- a/products/alerts/mcp/tools.yaml+++ b/products/alerts/mcp/tools.yaml@@ -34,9 +34,9 @@ tools:(query ordered oldest->newest, the last row is the current value), 'first_row' (query orderednewest->oldest, the first row is the current value — pair with a LIMIT, and it is unaffected by resulttruncation), or 'any_row' (every row is checked and the alert fires if any value breaches; absolute_value- condition only; label_column labels rows in breach messages). Label values appear in delivered notifications- — avoid label columns containing PII. Anomaly detection (detector_config) is only supported for trends- insights.+ condition only). label_column names the evaluated row(s) in breach messages in every evaluation mode+ (defaults to the first non-evaluated column). Label values appear in delivered notifications — avoid label+ columns containing PII. Anomaly detection (detector_config) is only supported for trends insights.Note: subscribed_users only controls email recipients. For Slack, HTTPS webhook, or Discord delivery, seethe recipe on cdp-functions-create — it covers integration lookup (integrations-channels-retrieve), dedupediff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 7e6a2f4f1d7c..b7cae4d49df4 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -757,7 +757,7 @@"feature_flag": "agent-platform"},"alert-create": {- "description": "Create a new alert on an insight. Alerts can use either threshold-based conditions or anomaly detection. For threshold alerts: set condition (absolute_value, relative_increase, relative_decrease) and threshold configuration with bounds — at least one of lower or upper is required (omit detector_config). For anomaly detection: set detector_config with a detector type (zscore, mad, iqr, threshold, copod, ecod, hbos, isolation_forest, knn, lof, ocsvm, pca) and parameters like threshold (sensitivity 0-1, default 0.9) and window size. Ensemble detectors combine 2+ sub-detectors with AND/OR logic. Requires an insight ID and at least one subscribed user.\nThe config type must match the insight kind. Trends insights: TrendsAlertConfig (series_index, check_ongoing_interval). SQL/HogQL insights: HogQLAlertConfig — column picks which result column to evaluate (defaults to the single numeric column), evaluation is required and selects how rows are read: 'last_row' (query ordered oldest->newest, the last row is the current value), 'first_row' (query ordered newest->oldest, the first row is the current value — pair with a LIMIT, and it is unaffected by result truncation), or 'any_row' (every row is checked and the alert fires if any value breaches; absolute_value condition only; label_column labels rows in breach messages). Label values appear in delivered notifications — avoid label columns containing PII. Anomaly detection (detector_config) is only supported for trends insights.\nNote: subscribed_users only controls email recipients. For Slack, HTTPS webhook, or Discord delivery, see the recipe on cdp-functions-create — it covers integration lookup (integrations-channels-retrieve), dedupe (cdp-functions-list filtered by alert id, limit=1000), and the exact filters/inputs shape to pass.",+ "description": "Create a new alert on an insight. Alerts can use either threshold-based conditions or anomaly detection. For threshold alerts: set condition (absolute_value, relative_increase, relative_decrease) and threshold configuration with bounds — at least one of lower or upper is required (omit detector_config). For anomaly detection: set detector_config with a detector type (zscore, mad, iqr, threshold, copod, ecod, hbos, isolation_forest, knn, lof, ocsvm, pca) and parameters like threshold (sensitivity 0-1, default 0.9) and window size. Ensemble detectors combine 2+ sub-detectors with AND/OR logic. Requires an insight ID and at least one subscribed user.\nThe config type must match the insight kind. Trends insights: TrendsAlertConfig (series_index, check_ongoing_interval). SQL/HogQL insights: HogQLAlertConfig — column picks which result column to evaluate (defaults to the single numeric column), evaluation is required and selects how rows are read: 'last_row' (query ordered oldest->newest, the last row is the current value), 'first_row' (query ordered newest->oldest, the first row is the current value — pair with a LIMIT, and it is unaffected by result truncation), or 'any_row' (every row is checked and the alert fires if any value breaches; absolute_value condition only). label_column names the evaluated row(s) in breach messages in every evaluation mode (defaults to the first non-evaluated column). Label values appear in delivered notifications — avoid label columns containing PII. Anomaly detection (detector_config) is only supported for trends insights.\nNote: subscribed_users only controls email recipients. For Slack, HTTPS webhook, or Discord delivery, see the recipe on cdp-functions-create — it covers integration lookup (integrations-channels-retrieve), dedupe (cdp-functions-list filtered by alert id, limit=1000), and the exact filters/inputs shape to pass.","category": "Alerts","feature": "alerts","summary": "Create alert",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex 31f3b7eb6eab..db4307f52a38 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -787,7 +787,7 @@}},"alert-create": {- "description": "Create a new alert on an insight. Alerts can use either threshold-based conditions or anomaly detection. For threshold alerts: set condition (absolute_value, relative_increase, relative_decrease) and threshold configuration with bounds — at least one of lower or upper is required (omit detector_config). For anomaly detection: set detector_config with a detector type (zscore, mad, iqr, threshold, copod, ecod, hbos, isolation_forest, knn, lof, ocsvm, pca) and parameters like threshold (sensitivity 0-1, default 0.9) and window size. Ensemble detectors combine 2+ sub-detectors with AND/OR logic. Requires an insight ID and at least one subscribed user.\nThe config type must match the insight kind. Trends insights: TrendsAlertConfig (series_index, check_ongoing_interval). SQL/HogQL insights: HogQLAlertConfig — column picks which result column to evaluate (defaults to the single numeric column), evaluation is required and selects how rows are read: 'last_row' (query ordered oldest->newest, the last row is the current value), 'first_row' (query ordered newest->oldest, the first row is the current value — pair with a LIMIT, and it is unaffected by result truncation), or 'any_row' (every row is checked and the alert fires if any value breaches; absolute_value condition only; label_column labels rows in breach messages). Label values appear in delivered notifications — avoid label columns containing PII. Anomaly detection (detector_config) is only supported for trends insights.\nNote: subscribed_users only controls email recipients. For Slack, HTTPS webhook, or Discord delivery, see the recipe on cdp-functions-create — it covers integration lookup (integrations-channels-retrieve), dedupe (cdp-functions-list filtered by alert id, limit=1000), and the exact filters/inputs shape to pass.",+ "description": "Create a new alert on an insight. Alerts can use either threshold-based conditions or anomaly detection. For threshold alerts: set condition (absolute_value, relative_increase, relative_decrease) and threshold configuration with bounds — at least one of lower or upper is required (omit detector_config). For anomaly detection: set detector_config with a detector type (zscore, mad, iqr, threshold, copod, ecod, hbos, isolation_forest, knn, lof, ocsvm, pca) and parameters like threshold (sensitivity 0-1, default 0.9) and window size. Ensemble detectors combine 2+ sub-detectors with AND/OR logic. Requires an insight ID and at least one subscribed user.\nThe config type must match the insight kind. Trends insights: TrendsAlertConfig (series_index, check_ongoing_interval). SQL/HogQL insights: HogQLAlertConfig — column picks which result column to evaluate (defaults to the single numeric column), evaluation is required and selects how rows are read: 'last_row' (query ordered oldest->newest, the last row is the current value), 'first_row' (query ordered newest->oldest, the first row is the current value — pair with a LIMIT, and it is unaffected by result truncation), or 'any_row' (every row is checked and the alert fires if any value breaches; absolute_value condition only). label_column names the evaluated row(s) in breach messages in every evaluation mode (defaults to the first non-evaluated column). Label values appear in delivered notifications — avoid label columns containing PII. Anomaly detection (detector_config) is only supported for trends insights.\nNote: subscribed_users only controls email recipients. For Slack, HTTPS webhook, or Discord delivery, see the recipe on cdp-functions-create — it covers integration lookup (integrations-channels-retrieve), dedupe (cdp-functions-list filtered by alert id, limit=1000), and the exact filters/inputs shape to pass.","category": "Alerts","feature": "alerts","summary": "Create alert",diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex ea7047dadd9c..6aaeb6e8f0b9 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -8681,7 +8681,7 @@ export namespace Schemas {column?: string | null;/** How to read the result rows — an explicit choice, no implicit default. */evaluation: HogQLAlertEvaluation;- /** In `any_row` mode, the column whose value labels each row in breach messages. When unset, the first non-evaluated column is used, falling back to the row number. */+ /** Column whose value labels the evaluated row(s) in breach messages: every row in `any_row` mode, or the single evaluated row in `last_row`/`first_row`. When unset, the first non-evaluated column is used, falling back to the row number (any_row) or the value column name (last_row/first_row). */label_column?: string | null;type: HogQLAlertConfigType;}@@ -8938,7 +8938,7 @@ export namespace Schemas {* @nullable*/readonly checks_total: number | null;- /** Per-insight-kind alert configuration, discriminated by `type`. TrendsAlertConfig: series_index (which series to monitor) and check_ongoing_interval (whether to check the current incomplete interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, 'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and label_column (labels rows in breach messages for any_row). */+ /** Per-insight-kind alert configuration, discriminated by `type`. TrendsAlertConfig: series_index (which series to monitor) and check_ongoing_interval (whether to check the current incomplete interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, 'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and label_column (names the evaluated row(s) in breach messages, in every evaluation mode). */config?: AlertConfigUnion | null;detector_config?: DetectorConfig | null;/** How often the alert is checked: every 15 minutes (Boost+), hourly, daily, weekly, or monthly.@@ -34066,7 +34066,7 @@ export namespace Schemas {* @nullable*/readonly checks_total?: number | null;- /** Per-insight-kind alert configuration, discriminated by `type`. TrendsAlertConfig: series_index (which series to monitor) and check_ongoing_interval (whether to check the current incomplete interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, 'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and label_column (labels rows in breach messages for any_row). */+ /** Per-insight-kind alert configuration, discriminated by `type`. TrendsAlertConfig: series_index (which series to monitor) and check_ongoing_interval (whether to check the current incomplete interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, 'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and label_column (names the evaluated row(s) in breach messages, in every evaluation mode). */config?: AlertConfigUnion | null;detector_config?: DetectorConfig | null;/** How often the alert is checked: every 15 minutes (Boost+), hourly, daily, weekly, or monthly.diff --git a/services/mcp/src/generated/alerts/api.ts b/services/mcp/src/generated/alerts/api.tsindex 8e07d2b0fd17..93b4532f051f 100644--- a/services/mcp/src/generated/alerts/api.ts+++ b/services/mcp/src/generated/alerts/api.ts@@ -151,7 +151,7 @@ export const AlertsCreateBody = /* @__PURE__ */ zod.object({.union([zod.string(), zod.null()]).optional().describe(- 'In `any_row` mode, the column whose value labels each row in breach messages. When unset, the first non-evaluated column is used, falling back to the row number.'+ 'Column whose value labels the evaluated row(s) in breach messages: every row in `any_row` mode, or the single evaluated row in `last_row`/`first_row`. When unset, the first non-evaluated column is used, falling back to the row number (any_row) or the value column name (last_row/first_row).'),type: zod.enum(['HogQLAlertConfig']).default(alertsCreateBodyConfigOneTwoTypeDefault),}),@@ -163,7 +163,7 @@ export const AlertsCreateBody = /* @__PURE__ */ zod.object({]).optional().describe(- "Per-insight-kind alert configuration, discriminated by `type`. TrendsAlertConfig: series_index (which series to monitor) and check_ongoing_interval (whether to check the current incomplete interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, 'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and label_column (labels rows in breach messages for any_row)."+ "Per-insight-kind alert configuration, discriminated by `type`. TrendsAlertConfig: series_index (which series to monitor) and check_ongoing_interval (whether to check the current incomplete interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, 'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and label_column (names the evaluated row(s) in breach messages, in every evaluation mode)."),detector_config: zod.union([@@ -1427,7 +1427,7 @@ export const AlertsPartialUpdateBody = /* @__PURE__ */ zod.object({.union([zod.string(), zod.null()]).optional().describe(- 'In `any_row` mode, the column whose value labels each row in breach messages. When unset, the first non-evaluated column is used, falling back to the row number.'+ 'Column whose value labels the evaluated row(s) in breach messages: every row in `any_row` mode, or the single evaluated row in `last_row`/`first_row`. When unset, the first non-evaluated column is used, falling back to the row number (any_row) or the value column name (last_row/first_row).'),type: zod.enum(['HogQLAlertConfig']).default(alertsPartialUpdateBodyConfigOneTwoTypeDefault),}),@@ -1439,7 +1439,7 @@ export const AlertsPartialUpdateBody = /* @__PURE__ */ zod.object({]).optional().describe(- "Per-insight-kind alert configuration, discriminated by `type`. TrendsAlertConfig: series_index (which series to monitor) and check_ongoing_interval (whether to check the current incomplete interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, 'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and label_column (labels rows in breach messages for any_row)."+ "Per-insight-kind alert configuration, discriminated by `type`. TrendsAlertConfig: series_index (which series to monitor) and check_ongoing_interval (whether to check the current incomplete interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, 'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and label_column (names the evaluated row(s) in breach messages, in every evaluation mode)."),detector_config: zod.union([diff --git a/services/mcp/src/generated/signals/api.ts b/services/mcp/src/generated/signals/api.tsindex 3db84245be9d..bd4d7f721a59 100644--- a/services/mcp/src/generated/signals/api.ts+++ b/services/mcp/src/generated/signals/api.ts@@ -3,7 +3,7 @@* MCP service uses these Zod schemas for generated tool handlers.* To regenerate: hogli build:openapi*- * PostHog API - MCP 21 enabled ops+ * PostHog API - MCP 22 enabled ops* OpenAPI spec version: 1.0.0*/import * as zod from 'zod'diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/alert-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/alert-create.jsonindex 862dc11a3017..fa3e358725a3 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/alert-create.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/alert-create.json@@ -81,7 +81,7 @@"type": "null"}],- "description": "In `any_row` mode, the column whose value labels each row in breach messages. When unset, the first non-evaluated column is used, falling back to the row number."+ "description": "Column whose value labels the evaluated row(s) in breach messages: every row in `any_row` mode, or the single evaluated row in `last_row`/`first_row`. When unset, the first non-evaluated column is used, falling back to the row number (any_row) or the value column name (last_row/first_row)."},"type": {"default": "HogQLAlertConfig",@@ -99,7 +99,7 @@"type": "null"}],- "description": "Per-insight-kind alert configuration, discriminated by `type`. TrendsAlertConfig: series_index (which series to monitor) and check_ongoing_interval (whether to check the current incomplete interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, 'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and label_column (labels rows in breach messages for any_row)."+ "description": "Per-insight-kind alert configuration, discriminated by `type`. TrendsAlertConfig: series_index (which series to monitor) and check_ongoing_interval (whether to check the current incomplete interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, 'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and label_column (names the evaluated row(s) in breach messages, in every evaluation mode)."},"detector_config": {"anyOf": [diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/alert-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/alert-update.jsonindex 9c4169351ab0..049dd5270a63 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/alert-update.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/alert-update.json@@ -81,7 +81,7 @@"type": "null"}],- "description": "In `any_row` mode, the column whose value labels each row in breach messages. When unset, the first non-evaluated column is used, falling back to the row number."+ "description": "Column whose value labels the evaluated row(s) in breach messages: every row in `any_row` mode, or the single evaluated row in `last_row`/`first_row`. When unset, the first non-evaluated column is used, falling back to the row number (any_row) or the value column name (last_row/first_row)."},"type": {"default": "HogQLAlertConfig",@@ -99,7 +99,7 @@"type": "null"}],- "description": "Per-insight-kind alert configuration, discriminated by `type`. TrendsAlertConfig: series_index (which series to monitor) and check_ongoing_interval (whether to check the current incomplete interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, 'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and label_column (labels rows in breach messages for any_row)."+ "description": "Per-insight-kind alert configuration, discriminated by `type`. TrendsAlertConfig: series_index (which series to monitor) and check_ongoing_interval (whether to check the current incomplete interval). HogQLAlertConfig (SQL insights): column (which result column to evaluate, defaults to the single numeric column), evaluation ('last_row' checks the latest value of an oldest->newest query, 'first_row' checks the first value of a newest->oldest query, 'any_row' fires if any row breaches), and label_column (names the evaluated row(s) in breach messages, in every evaluation mode)."},"detector_config": {"anyOf": [