: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
fix(signals): make inbox reports show the chart instead of narrating it (#85439)
Andrew Maguire082f21f052b8
diff --git a/products/signals/backend/report_generation/AGENTS.md b/products/signals/backend/report_generation/AGENTS.mdindex a69103ed7491..900c1ed7e309 100644--- a/products/signals/backend/report_generation/AGENTS.md+++ b/products/signals/backend/report_generation/AGENTS.md@@ -61,6 +61,8 @@ Production persistence is handled outside `run_multi_turn_research()`, in the caThe presentation step can also author `charts` — query nodes the inbox draws on the report body, so a finding about a metric move is visible next to the sentence describing it. They are the same `SignalReport.charts` the scout channel writes (schema + bounds in `report_charts.py`), authored in the same structured response as the title/summary so the summary can place one with a `[label](chart:<id>)` markdown link. This is the pipeline counterpart of the scout `emit_report` charts path.+- **Expected on a data-shaped finding.** `_REPORT_CHARTS_GUIDANCE` tells the presentation step to attach the chart whenever the finding rests on data moving (a metric that broke, a rate that slid, a distribution that shifted), and to attach nothing when it lives in code, in a config, or in a single count. That pairs with the summary's 200-word target and 300-word ceiling: the chart carries the interval-by-interval series so the prose can state the finding and stop. Charts today correlate with longer summaries rather than shorter ones, because a run that attaches one still narrates the series underneath it, so the two rules only work together. Nothing but this guidance decides how many charts a report gets, so softening it back toward "usually the wrong call" is what returns the inbox to unillustrated walls of text.+- **A malformed chart costs the whole report.** `charts` rides in the same `ReportPresentationOutput` as the title and summary, and `MultiTurnSession._parse_and_validate` calls `model_validate` with no retry, so one bad node raises and the research run fails with nothing persisted. `_resolve_report_charts_payload` never sees it. That is why the guidance names the outer-node wrapping explicitly and tells the run to drop a doubtful chart rather than risk it. Giving a malformed chart its own degrade path would need a retry or a partial parse in the runner, which is shared with every other multi-turn caller.- **Opt-in.** Gated per team by the `signals-report-charts` flag (`_team_report_charts_enabled` in the caller activity; on in DEBUG). When off, both the chart guidance and the `charts` field itself are dropped from the presentation prompt (chart-free schema), and the caller drops anything the model returns anyway — so an un-opted team is never shown or steered toward charts on the delicate fleet-wide path.- **Replace, not append.** `charts` is the report's whole set. On a re-research the previous charts are shown back as context (loaded from `SignalReport.charts` by `_load_previous_research`); the run keeps, refreshes, or drops them and the caller replaces the column with the result.- **Persistence is atomic with the prose.** `run_agentic_report_activity` only _resolves_ the charts payload (`_resolve_report_charts_payload`) and returns it on `RunAgenticReportOutput.charts`; the column is written by the transition activity that also writes the title/summary (`mark_report_ready_activity` / `mark_report_pending_input_activity`), inside the same `transition_to` transaction. So charts and the prose they illustrate land together — a failed run or the not-actionable reset (neither writes the new prose) leaves the charts alone by construction, with no separate-transaction window. The resolver yields three outcomes: a valid non-empty set (replace the column); `None` when the team isn't opted in **or** the run authored no charts (leave the column alone — the presentation field is optional, so an omitted key and a deliberate "drop everything" both arrive empty and are indistinguishable, and wiping user-visible charts on that ambiguity is the worse failure, so the pipeline never auto-clears to zero; a human can clear from the inbox); and `[]` when the set busts the whole-set caps (clear, so a stale set can't sit under the new summary).diff --git a/products/signals/backend/report_generation/research.py b/products/signals/backend/report_generation/research.pyindex 8d4686da443a..5ea305af4681 100644--- a/products/signals/backend/report_generation/research.py+++ b/products/signals/backend/report_generation/research.py@@ -79,6 +79,7 @@ Then give it light structure so a busy reader can scan the rest, three short secWithin each section write a sentence or two of natural, flowing prose, not bullet soup. Bold the few phrases a reader should catch at a glance (the core symptom, the key number, the root cause, the proposed change) so it's scannable without becoming a wall of labels. Don't over-bold: if everything's bold, nothing is.Hard rules:+- Aim the whole summary at 200 words, and never go past 300. This is the part a busy reader actually finishes, and the signals, evidence, and research artefacts already carry the full trail for anyone who wants to go deeper. Length is not thoroughness: cutting a paragraph of supporting detail you researched is the right call, and a report nobody reads to the end has surfaced nothing.- Everything must be factual, grounded in what you actually researched and what has actually happened. Never invent, never speculate as if it were fact. If something's a hypothesis, say so plainly.- Be specific. Reference the concrete signals, errors, metrics, or code paths you found; vagueness reads as not having done the work.- No filler ("various issues detected", "it's worth noting", "in conclusion").@@ -90,10 +91,12 @@ Hard rules:default_factory=list,description=("Charts the inbox draws on the report, so a finding about a metric move is visible next "- "to the sentence describing it. Optional — attach one only when the shape of the data is "- "the point. Reference a chart from the summary as a markdown link with a `chart:` target "- "(e.g. `[Daily signups](chart:signups-drop)`) to place it inline; an unreferenced chart "- "renders after the prose. Leave empty when a chart would only restate a number."+ "to the sentence describing it. Attach one whenever the finding rests on data moving, and "+ "let it carry the series so the prose can state the finding and stop. Reference a chart "+ "from the summary as a markdown link with a `chart:` target (e.g. "+ "`[Daily signups](chart:signups-drop)`) to place it inline; an unreferenced chart renders "+ "after the prose. Leave empty when the finding has no shape to show, such as one that "+ "lives in code, in a config, or in a single count."),)@@ -345,14 +348,19 @@ def _render_previous_presentation_context(previous_title: str | None, previous_s# team that isn't opted in is never shown or steered toward charts on the delicate fleet-wide path._REPORT_CHARTS_GUIDANCE = f"""## Attaching charts-You may attach charts under `charts`, which the inbox draws on the report itself so a data move is visible next to the sentence describing it rather than a number the reader has to go and reproduce. This is optional and usually the wrong call — attach a chart only when the *shape* of the data is the point (a trend that broke, a distribution that shifted, a funnel step that collapsed). A chart restating one number the summary already gives is noise; write the number. Most reports should carry zero charts.+You may attach charts under `charts`, which the inbox draws on the report itself so a data move is visible next to the sentence describing it rather than a number the reader has to go and reproduce.-- **Each chart is `chart_id` + `title` + `query`.** `chart_id` is your own slug (lowercase letters, numbers, `_`, `-`); `title` is the heading above it; `query` is a query node — `InsightVizNode` (an ad-hoc product-analytics chart), `DataVisualizationNode` (a `HogQLQuery` source, plus `display` and `chartSettings` for a graph rather than a result table), or `SavedInsightNode` (an existing insight by `shortId`). Any other kind is refused. Add a `caption` when there's a specific thing to look at.+**When the finding rests on data moving, attach the chart that shows it.** A metric that broke, a rate that slid, a distribution that shifted, a funnel step that collapsed: each of those is a shape, and a reader takes a shape in at a glance where a paragraph of figures makes them rebuild it in their head. The test is the result you got back, never the tool you got it from: a query that returned a series over time, a distribution across buckets, or a set of funnel steps has a shape to draw, and the same tool returning one aggregate row does not. Attaching is what keeps the prose short, because the summary can state the finding and leave the detail to the picture.++Attach nothing when there is no shape to show. A finding that lives entirely in code, in a config, or in a single count has nothing to draw, and a chart restating one number the summary already gives is noise, so write the number instead. One or two charts is the usual answer for a data-shaped report, and none for the rest.++- **Each chart is `chart_id` + `title` + `query`.** `chart_id` is your own slug (lowercase letters, numbers, `_`, `-`); `title` is the heading above it; `query` is a query node — `InsightVizNode` (an ad-hoc product-analytics chart), `DataVisualizationNode` (a `HogQLQuery` source, plus `display` and `chartSettings` for a graph rather than a result table), or `SavedInsightNode` (an existing insight by `shortId`). Any other kind is refused. `query` is that outer node, never the bare query you ran: a `TrendsQuery` goes inside `InsightVizNode.source` and a `HogQLQuery` inside `DataVisualizationNode.source`. Getting that wrong costs more than the chart, because the title, the summary, and the charts are validated as one response, so a malformed node fails the whole thing and the research run ends with no report. When in doubt about a chart, leave it out and keep the prose. Add a `caption` when there's a specific thing to look at.- **A graph from SQL needs its axes named.** Setting `display` on a `DataVisualizationNode` without `chartSettings` draws every row at one x position instead of a series: `chartSettings.xAxis.column` and `chartSettings.yAxis[].column` say which columns of your result are which, naming them exactly as your `SELECT` aliases them. A daily count aliased `SELECT toDate(timestamp) AS day, count() AS occurrences` needs `"chartSettings": {{"xAxis": {{"column": "day"}}, "yAxis": [{{"column": "occurrences"}}]}}`. Leave `display` off entirely and the node renders the result table instead, which reads better than a chart for a handful of rows.- **Only attach a query you actually ran this session.** A well-formed node of an allowed kind holding a broken query is stored without complaint and then fails to draw when the reader opens the report, with nothing to tell you. So build each chart from a query you already executed through `mcp__posthog__exec` (`call query-trends {{...}}`, `call execute-sql {{...}}`, or read the exact node off an existing insight) – never one written from memory.- **A chart renders data, it does not run code.** HogVM `bytecode`, a nested `HogQuery`, `sendRawQuery`, and a nested `SuggestedQuestionsQuery` are each refused wherever they sit in the node. A warehouse query is fine through HogQL — keep `connectionId`, drop `sendRawQuery`.- **Place it from the summary.** A markdown link with a `chart:` target — `[Daily signups](chart:signups-drop)` — draws the chart at that point in the body; reference it once. A chart you never reference still renders, after the prose. Two references in one paragraph sit side by side.- **Prose must stand on its own.** The report is also delivered to Slack, where nothing draws a chart and a reference degrades to its plain label. State the finding in words and let the chart corroborate it — never "the chart below shows the drop".+- **Let the chart carry the series.** The prose keeps the finding and the one or two numbers that size it, so a Slack reader still gets it; what the chart takes over is the interval-by-interval recital. "Step-2 conversion fell from 62% to 48% over the week" beside a chart beats a sentence listing every day.- **Pin the window** to absolute dates wherever the node supports it, so the reader sees the data you wrote about rather than whatever a relative range resolves to days later.- **At most {MAX_REPORT_CHARTS} per report**, far more than any report should use — three charts a reader studies beat a dozen they scroll past.- **`charts` is the report's whole set.** It replaces whatever the report showed before, the way title and summary do. To keep a chart across a re-research, send it again; drop one by leaving it out."""