: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
chore(insights): stop agents rendering %% on SQL insight axes (#89100)
Sam Pennington64cdcd9c4522
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 8619c7445a13..51c33cb61e94 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -2208,12 +2208,12 @@"type": "string"},"style": {- "description": "Number formatting style.\n- `none` — no formatting.\n- `number` — thousands separators (e.g. `1,234`).\n- `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — render the value as a percentage.",+ "description": "Number formatting style.\n- `none` — no formatting.\n- `number` — thousands separators (e.g. `1,234`).\n- `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — multiply the value by 100 and append a `%` sign, so pass a 0-1 ratio (`a / b`, not `100.0 * a / b`). Never pair it with a `%` suffix, which renders `47.3%%`.","enum": ["none", "number", "short", "percent"],"type": "string"},"suffix": {- "description": "Text appended to each value (e.g. `%` or ` ms`).",+ "description": "Text appended to each value (e.g. ` ms`). Leave unset when `style` is `percent`, which already appends the `%` sign.","type": "string"}},diff --git a/frontend/src/queries/schema/schema-assistant-queries.ts b/frontend/src/queries/schema/schema-assistant-queries.tsindex 8681063038b2..54a39e9152dc 100644--- a/frontend/src/queries/schema/schema-assistant-queries.ts+++ b/frontend/src/queries/schema/schema-assistant-queries.ts@@ -1828,14 +1828,14 @@ export interface AssistantDataVisualizationAxisDisplaySettings {export interface AssistantDataVisualizationAxisFormatting {/** Text prepended to each value (e.g. `$`). */prefix?: string- /** Text appended to each value (e.g. `%` or ` ms`). */+ /** Text appended to each value (e.g. ` ms`). Leave unset when `style` is `percent`, which already appends the `%` sign. */suffix?: string/*** Number formatting style.* - `none` — no formatting.* - `number` — thousands separators (e.g. `1,234`).* - `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).- * - `percent` — render the value as a percentage.+ * - `percent` — multiply the value by 100 and append a `%` sign, so pass a 0-1 ratio (`a / b`, not `100.0 * a / b`). Never pair it with a `%` suffix, which renders `47.3%%`.*/style?: 'none' | 'number' | 'short' | 'percent'/** Number of decimal places to display. */diff --git a/posthog/schema.py b/posthog/schema.pyindex 06f2f2d286e7..abbad6a784c7 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -491,11 +491,18 @@ class AssistantDataVisualizationAxisFormatting(BaseModel):description=("Number formatting style.\n- `none` — no formatting.\n- `number` —"" thousands separators (e.g. `1,234`).\n- `short` — abbreviated large"- " numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — render the value as a"- " percentage."+ " numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — multiply the value by 100"+ " and append a `%` sign, so pass a 0-1 ratio (`a / b`, not `100.0 * a /"+ " b`). Never pair it with a `%` suffix, which renders `47.3%%`."+ ),+ )+ suffix: str | None = Field(+ default=None,+ description=(+ "Text appended to each value (e.g. ` ms`). Leave unset when `style` is"+ " `percent`, which already appends the `%` sign."),)- suffix: str | None = Field(default=None, description="Text appended to each value (e.g. `%` or ` ms`).")class AssistantDataVisualizationAxisSettings(BaseModel):diff --git a/products/product_analytics/skills/formatting-insight-axes/SKILL.md b/products/product_analytics/skills/formatting-insight-axes/SKILL.mdindex 00110abde4bd..135157273cff 100644--- a/products/product_analytics/skills/formatting-insight-axes/SKILL.md+++ b/products/product_analytics/skills/formatting-insight-axes/SKILL.md@@ -1,20 +1,28 @@---name: formatting-insight-axesdescription: >- Pick the right y-axis unit when creating or updating a TrendsQuery insight- via `posthog:insight-create` or `posthog:insight-update`. Use when the agent- is about to add a `formula` purely to convert units (e.g. dividing seconds- by 60 to display minutes), when a `math_property` is a duration, currency,- ratio, or large count, or whenever the user mentions "format the y-axis",- "duration", "seconds", "minutes", "hours", "milliseconds", "ms",- "percentage", "currency", "decimals", "axis label", or "axis unit" in the- context of a graph insight.+ Pick the right y-axis unit when creating or updating an insight via+ `posthog:insight-create` or `posthog:insight-update` — both TrendsQuery+ (`trendsFilter.aggregationAxisFormat`) and SQL insights+ (`DataVisualizationNode`, `chartSettings.yAxis[].settings.formatting`).+ Use when the agent is about to add a `formula` purely to convert units+ (e.g. dividing seconds by 60 to display minutes), when a `math_property`+ or SQL column is a duration, currency, ratio, or large count, or whenever+ the user mentions "format the y-axis", "duration", "seconds", "minutes",+ "hours", "milliseconds", "ms", "percentage", "%%", "currency", "decimals",+ "axis label", or "axis unit" in the context of a graph insight.---# Formatting insight axes-PostHog renders TrendsQuery insights with a built-in axis formatter. Use it-instead of contorting `formula` or `aggregationAxisPostfix` to fake units.+PostHog renders insights with a built-in axis formatter. Use it instead of+contorting the query or a literal prefix/postfix to fake units.++The two insight kinds configure it in different places:++- **TrendsQuery** — `trendsFilter.aggregationAxisFormat` (this page, below)+- **SQL insights** (`DataVisualizationNode`) — per-column+ `settings.formatting` (see [SQL insights](#sql-insights-datavisualizationnode))## The anti-pattern@@ -172,11 +180,47 @@ and move on.}```+## SQL insights (DataVisualizationNode)++SQL insights have no `trendsFilter`.+Formatting is per column, on `chartSettings.yAxis[].settings.formatting` for a chart and top-level `tableSettings.columns[].settings.formatting` for a table.++```json+{+ "kind": "DataVisualizationNode",+ "source": { "kind": "HogQLQuery", "query": "SELECT week, conversion_rate FROM ..." },+ "display": "ActionsLineGraph",+ "chartSettings": {+ "xAxis": { "column": "week" },+ "yAxis": [+ {+ "column": "conversion_rate",+ "settings": { "formatting": { "style": "percent", "decimalPlaces": 1 } }+ }+ ]+ }+}+```++`style` is `none`, `number`, `short`, or `percent` — no `duration` or `currency`.+Express those with `prefix` / `suffix`, or in the SQL itself.++`percent` both appends the `%` sign and multiplies the value by 100 (like the trends `percentage_scaled` format; there is no unscaled variant).+So feed it a 0-1 ratio and leave `suffix` unset — pick one shape, never a mix:++| SQL returns | `formatting` | Renders |+| --------------------------------- | -------------------------------------------------------- | ------- |+| a 0-1 ratio (`a / b`) | `{"style": "percent", "decimalPlaces": 1}` | `47.3%` |+| 0-100 (`round(100.0 * a / b, 1)`) | `{"style": "number", "suffix": "%", "decimalPlaces": 1}` | `47.3%` |++A mix renders broken: `style: "percent"` plus a `"%"` suffix gives `47.3%%`, and `percent` on an already-scaled 0-100 column gives `4730%`.+Prefer the ratio form — it keeps the `100.0 *` out of the query, so the stored column stays a plain ratio for anything else that reads it.+## Updating an existing insight-If you are updating an insight and notice it already uses the-`formula`/`postfix` anti-pattern, fix it in the same `posthog:insight-update`-call — drop the divide-by-N, drop the `aggregationAxisPostfix`, and set the-matching `aggregationAxisFormat`. The series values stay the same, only the-labels change. Do not go scanning unrelated insights for this pattern —-fix only the ones you are already touching.+If an insight you are already editing uses one of these anti-patterns — a+trends `formula`/`postfix` pair, or a SQL column with both `style: "percent"`+and a `"%"` suffix — fix it in the same `posthog:insight-update` call: drop the+divide-by-N or `100.0 *` and the literal `%`, and let the format own the unit.+Values stay the same, only labels change. Do not scan unrelated insights — fix+only the ones you are already touching.diff --git a/services/mcp/src/tools/generated/product_analytics.ts b/services/mcp/src/tools/generated/product_analytics.tsindex 538274f7caeb..d3eb52dfd6cb 100644--- a/services/mcp/src/tools/generated/product_analytics.ts+++ b/services/mcp/src/tools/generated/product_analytics.ts@@ -70,10 +70,15 @@ const AssistantDataVisualizationAxisFormatting = z.object({style: z.enum(['none', 'number', 'short', 'percent']).describe(- 'Number formatting style.\n- `none` — no formatting.\n- `number` — thousands separators (e.g. `1,234`).\n- `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — render the value as a percentage.'+ 'Number formatting style.\n- `none` — no formatting.\n- `number` — thousands separators (e.g. `1,234`).\n- `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — multiply the value by 100 and append a `%` sign, so pass a 0-1 ratio (`a / b`, not `100.0 * a / b`). Never pair it with a `%` suffix, which renders `47.3%%`.'+ )+ .optional(),+ suffix: z+ .string()+ .describe(+ 'Text appended to each value (e.g. ` ms`). Leave unset when `style` is `percent`, which already appends the `%` sign.').optional(),- suffix: z.string().describe('Text appended to each value (e.g. `%` or ` ms`).').optional(),})const AssistantDataVisualizationAxisSettings = z.object({diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/insight-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/insight-create.jsonindex 4ff823870431..43a428c6570f 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/insight-create.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/insight-create.json@@ -213,12 +213,12 @@"type": "string"},"style": {- "description": "Number formatting style.\n- `none` — no formatting.\n- `number` — thousands separators (e.g. `1,234`).\n- `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — render the value as a percentage.",+ "description": "Number formatting style.\n- `none` — no formatting.\n- `number` — thousands separators (e.g. `1,234`).\n- `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — multiply the value by 100 and append a `%` sign, so pass a 0-1 ratio (`a / b`, not `100.0 * a / b`). Never pair it with a `%` suffix, which renders `47.3%%`.","enum": ["none", "number", "short", "percent"],"type": "string"},"suffix": {- "description": "Text appended to each value (e.g. `%` or ` ms`).",+ "description": "Text appended to each value (e.g. ` ms`). Leave unset when `style` is `percent`, which already appends the `%` sign.","type": "string"}},@@ -286,12 +286,12 @@"type": "string"},"style": {- "description": "Number formatting style.\n- `none` — no formatting.\n- `number` — thousands separators (e.g. `1,234`).\n- `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — render the value as a percentage.",+ "description": "Number formatting style.\n- `none` — no formatting.\n- `number` — thousands separators (e.g. `1,234`).\n- `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — multiply the value by 100 and append a `%` sign, so pass a 0-1 ratio (`a / b`, not `100.0 * a / b`). Never pair it with a `%` suffix, which renders `47.3%%`.","enum": ["none", "number", "short", "percent"],"type": "string"},"suffix": {- "description": "Text appended to each value (e.g. `%` or ` ms`).",+ "description": "Text appended to each value (e.g. ` ms`). Leave unset when `style` is `percent`, which already appends the `%` sign.","type": "string"}},@@ -391,12 +391,12 @@"type": "string"},"style": {- "description": "Number formatting style.\n- `none` — no formatting.\n- `number` — thousands separators (e.g. `1,234`).\n- `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — render the value as a percentage.",+ "description": "Number formatting style.\n- `none` — no formatting.\n- `number` — thousands separators (e.g. `1,234`).\n- `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — multiply the value by 100 and append a `%` sign, so pass a 0-1 ratio (`a / b`, not `100.0 * a / b`). Never pair it with a `%` suffix, which renders `47.3%%`.","enum": ["none", "number", "short", "percent"],"type": "string"},"suffix": {- "description": "Text appended to each value (e.g. `%` or ` ms`).",+ "description": "Text appended to each value (e.g. ` ms`). Leave unset when `style` is `percent`, which already appends the `%` sign.","type": "string"}},diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/insight-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/insight-update.jsonindex c48a165249f0..17e256cb7381 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/insight-update.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/insight-update.json@@ -224,12 +224,12 @@"type": "string"},"style": {- "description": "Number formatting style.\n- `none` — no formatting.\n- `number` — thousands separators (e.g. `1,234`).\n- `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — render the value as a percentage.",+ "description": "Number formatting style.\n- `none` — no formatting.\n- `number` — thousands separators (e.g. `1,234`).\n- `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — multiply the value by 100 and append a `%` sign, so pass a 0-1 ratio (`a / b`, not `100.0 * a / b`). Never pair it with a `%` suffix, which renders `47.3%%`.","enum": ["none", "number", "short", "percent"],"type": "string"},"suffix": {- "description": "Text appended to each value (e.g. `%` or ` ms`).",+ "description": "Text appended to each value (e.g. ` ms`). Leave unset when `style` is `percent`, which already appends the `%` sign.","type": "string"}},@@ -297,12 +297,12 @@"type": "string"},"style": {- "description": "Number formatting style.\n- `none` — no formatting.\n- `number` — thousands separators (e.g. `1,234`).\n- `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — render the value as a percentage.",+ "description": "Number formatting style.\n- `none` — no formatting.\n- `number` — thousands separators (e.g. `1,234`).\n- `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — multiply the value by 100 and append a `%` sign, so pass a 0-1 ratio (`a / b`, not `100.0 * a / b`). Never pair it with a `%` suffix, which renders `47.3%%`.","enum": ["none", "number", "short", "percent"],"type": "string"},"suffix": {- "description": "Text appended to each value (e.g. `%` or ` ms`).",+ "description": "Text appended to each value (e.g. ` ms`). Leave unset when `style` is `percent`, which already appends the `%` sign.","type": "string"}},@@ -402,12 +402,12 @@"type": "string"},"style": {- "description": "Number formatting style.\n- `none` — no formatting.\n- `number` — thousands separators (e.g. `1,234`).\n- `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — render the value as a percentage.",+ "description": "Number formatting style.\n- `none` — no formatting.\n- `number` — thousands separators (e.g. `1,234`).\n- `short` — abbreviated large numbers (e.g. `1.2k`, `3.4M`).\n- `percent` — multiply the value by 100 and append a `%` sign, so pass a 0-1 ratio (`a / b`, not `100.0 * a / b`). Never pair it with a `%` suffix, which renders `47.3%%`.","enum": ["none", "number", "short", "percent"],"type": "string"},"suffix": {- "description": "Text appended to each value (e.g. `%` or ` ms`).",+ "description": "Text appended to each value (e.g. ` ms`). Leave unset when `style` is `percent`, which already appends the `%` sign.","type": "string"}},