: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(canvas): require verifiable insights in skills and mcp tools (#87187)
Peter Kirkham2a190104a7f1
diff --git a/products/canvas/mcp/tools.yaml b/products/canvas/mcp/tools.yamlindex 977328a744bd..ee23545b907f 100644--- a/products/canvas/mcp/tools.yaml+++ b/products/canvas/mcp/tools.yaml@@ -79,7 +79,9 @@ tools:capture events, inline queries, network origins) — so added access is visible before shipping. Pollcanvas-builds-retrieve until the draft's build is terminal, preview the draft with canvas-source-retrievepassing the returned `version_id`, then make it live with canvas-promote-create. Declare runtime- capabilities in `project.capabilities`.+ capabilities in `project.capabilities`. A project that shows PostHog data must make every figure verifiable+ before staging: an insight-backed metric links its saved insight (ph.openExternal with a URL from+ generate-app-url); an ad-hoc ph.query figure exposes the exact query that ran in a modal or collapsed area.param_overrides:id:description: ID of the canvas to stage a draft for.@@ -256,8 +258,11 @@ tools:`expected_current_version_id` (from canvas-source-retrieve) so a concurrent edit is rejected with 409version_conflict instead of overwritten; on conflict, re-read the source, re-apply your edits, and publishagainst the new head. A 429 means the team's build capacity is exhausted — wait a moment and retry. Declare- the canvas's runtime capabilities (insights, capture events, inline queries) in `project.capabilities`. The- canvas lives in PostHog, not on disk — this tool is what saves it.+ the canvas's runtime capabilities (insights, capture events, inline queries) in `project.capabilities`. A+ project that shows PostHog data must make every figure verifiable before publishing: an insight-backed+ metric links its saved insight (ph.openExternal with a URL from generate-app-url); an ad-hoc ph.query figure+ exposes the exact query that ran in a modal or collapsed area. The canvas lives in PostHog, not on disk —+ this tool is what saves it.param_overrides:id:description: ID of the canvas whose source to publish.diff --git a/products/canvas/skills/building-canvases/SKILL.md b/products/canvas/skills/building-canvases/SKILL.mdindex ce0e89becd77..62e0d2388709 100644--- a/products/canvas/skills/building-canvases/SKILL.md+++ b/products/canvas/skills/building-canvases/SKILL.md@@ -87,7 +87,9 @@ matching shape above. The pattern is a hint; the user's actual request remains aRemember `current_version_id` — your publish must be guarded on it.2. Edit the project files using the implementation companions selected above. For any PostHog datathe canvas shows, follow `querying-canvas-data` (saved insights loaded via the `ph` SDK — never- fetch or your own PostHog client), and+ fetch or your own PostHog client), make every figure verifiable — an insight-backed metric+ links its saved insight in PostHog, an ad-hoc query shows the exact query that ran, per that+ skill's "Verifiability" section — and**declare every `ph` call in `project.capabilities`** (insight short ids in`capabilities.posthog.insights`, captured events in `captureEvents`, `inlineQueries: true` forad-hoc queries, and `agentRequests: true` for `ph.agent.request`) — the host enforces these atdiff --git a/products/canvas/skills/building-html-canvases/SKILL.md b/products/canvas/skills/building-html-canvases/SKILL.mdindex 57e3f8b455fa..d4c2c63aeb4b 100644--- a/products/canvas/skills/building-html-canvases/SKILL.md+++ b/products/canvas/skills/building-html-canvases/SKILL.md@@ -56,6 +56,10 @@ build pipeline's dependency admission ships.- No `fetch()`/`XMLHttpRequest`, no `<script>` tags, no dynamic `import()`, no remote assets —the sandbox blocks them. PostHog data comes only through the `ph` bridge (see the`querying-canvas-data` skill), including `ph.capture` for interaction analytics.+- A document that states PostHog numbers must make each one verifiable: an insight-backed number+ links its saved insight through `ph.openExternal` (URL from the `generate-app-url` MCP tool,+ from a click); an ad-hoc `ph.query` number discloses the exact query that ran in a `<details>`+ element beside the claim — see "Verifiability" in `querying-canvas-data`.- External links go through `ph.openExternal(url)` (posthog.com origins only), from a userinteraction.- Validate and publish through the canvas tools as described in `validating-and-publishing-canvases`.diff --git a/products/canvas/skills/building-react-quill-canvases/SKILL.md b/products/canvas/skills/building-react-quill-canvases/SKILL.mdindex d7e94d965b5a..3fa78a84b5d6 100644--- a/products/canvas/skills/building-react-quill-canvases/SKILL.md+++ b/products/canvas/skills/building-react-quill-canvases/SKILL.md@@ -97,6 +97,10 @@ Treat these as starting shapes and adapt them to the request and available data.- Use a `LineChart` for time series and a `BarChart` for discrete categories. Do not turn everyresult into a table.- Give every KPI, chart, and table its own loading, empty, and error state.+- Make every figure verifiable: an insight-backed card gets a "View in PostHog" affordance opening+ its saved insight (`ph.openExternal` with a URL minted by `generate-app-url`); an ad-hoc+ `ph.query` card gets a "View query" `Dialog` or `Collapsible` showing the exact query that ran —+ see "Verifiability" in `querying-canvas-data`.### Web analytics boarddiff --git a/products/canvas/skills/building-react-quill-canvases/references/starter-scaffold.md b/products/canvas/skills/building-react-quill-canvases/references/starter-scaffold.mdindex d69d8e6543aa..6f4785d2b2e3 100644--- a/products/canvas/skills/building-react-quill-canvases/references/starter-scaffold.md+++ b/products/canvas/skills/building-react-quill-canvases/references/starter-scaffold.md@@ -2,10 +2,14 @@A known-good baseline for a React + Quill data canvas. It already wires the pieces that are easyto get wrong — the date picker (self-sizing, no `compact`), theme-aware tokens, per-card loading-skeletons, and reading a typed-node result correctly. Start from it on a first build: keep the-wiring, replace the sample "total events" metric and the layout with what the user asked for.+skeletons, reading a typed-node result correctly, and the "View query" verification dialog every+ad-hoc data card must carry. Start from it on a first build: keep the wiring, replace the sample+"total events" metric and the layout with what the user asked for.Ideally swap the inline `ph.query` typed node for a saved insight loaded with-`ph.loadInsight(shortId, { dateRange })` (see the `querying-canvas-data` skill).+`ph.loadInsight(shortId, { dateRange })` (see the `querying-canvas-data` skill) — then replace the+"View query" dialog with a "View in PostHog" button calling `ph.openExternal(insightUrl)`, the URL+minted at authoring time by the `generate-app-url` MCP tool (`/insights/{id}`), so viewers verify+the numbers on the real insight with their own permissions applied.```tsximport React, { useEffect, useState } from 'react'@@ -16,6 +20,11 @@ import {CardHeader,CardTitle,DateTimePicker,+ Dialog,+ DialogContent,+ DialogHeader,+ DialogTitle,+ DialogTrigger,Heading,Popover,PopoverContent,@@ -26,6 +35,18 @@ import {import { RefreshCw } from 'lucide-react'import { CartesianGrid, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'+// One builder feeds both the ph.query call and the "View query" dialog, so the+// query a viewer inspects is exactly the one that ran. `event: null` = all+// events (works on any project).+const totalEventsQuery = (win) => ({+ kind: 'TrendsQuery',+ series: [{ kind: 'EventsNode', event: null, name: 'All events', math: 'total' }],+ dateRange: {+ date_from: win.start.toISOString(),+ date_to: win.end.toISOString(),+ },+})+export default function Canvas() {const def = quickRanges.find((r) => r.name === 'Last 30 days') ?? quickRanges[0]const [win, setWin] = useState({@@ -47,15 +68,8 @@ export default function Canvas() {setLoading(true)setError(null)// Typed query node, computed by PostHog's own runner so the numbers match- // the UI exactly. `event: null` = all events (works on any project).- ph.query({- kind: 'TrendsQuery',- series: [{ kind: 'EventsNode', event: null, name: 'All events', math: 'total' }],- dateRange: {- date_from: win.start.toISOString(),- date_to: win.end.toISOString(),- },- })+ // the UI exactly.+ ph.query(totalEventsQuery(win)).then((res) => {if (cancelled) return// Typed-node result: `results` is an array of SERIES OBJECTS, not rows.@@ -137,7 +151,31 @@ export default function Canvas() {<Card size="sm"><CardHeader>- <CardTitle>Events over time</CardTitle>+ <div className="flex items-center justify-between gap-2">+ <CardTitle>Events over time</CardTitle>+ {/* Every data card carries a verification affordance. An ad-hoc+ ph.query card shows the query it ran; a card backed by a saved+ insight instead renders a "View in PostHog" Button calling+ ph.openExternal(insightUrl) — the URL minted by the+ generate-app-url MCP tool, never hand-built. */}+ <Dialog>+ <DialogTrigger+ render={+ <Button variant="outline" size="sm">+ View query+ </Button>+ }+ />+ <DialogContent>+ <DialogHeader>+ <DialogTitle>Query behind this chart</DialogTitle>+ </DialogHeader>+ <div className="max-h-80 overflow-auto whitespace-pre-wrap rounded bg-muted p-3 font-mono text-xs">+ {JSON.stringify(totalEventsQuery(win), null, 2)}+ </div>+ </DialogContent>+ </Dialog>+ </div></CardHeader><CardContent>{loading ? (diff --git a/products/canvas/skills/composing-grid-canvases/SKILL.md b/products/canvas/skills/composing-grid-canvases/SKILL.mdindex b8602ee9f432..15c797a58971 100644--- a/products/canvas/skills/composing-grid-canvases/SKILL.md+++ b/products/canvas/skills/composing-grid-canvases/SKILL.md@@ -45,7 +45,9 @@ they serve unless the user asks to share them more widely.A component is authored exactly like a freeform canvas — load `building-react-quill-canvases` (or`building-html-canvases`) plus `querying-canvas-data` and `validating-and-publishing-canvases` —-with three additions.+with three additions. A component that shows PostHog data follows the same verifiability rule as+any canvas: an insight-backed figure links its saved insight, an ad-hoc query exposes the exact+query that ran (see "Verifiability" in `querying-canvas-data`).Start from the complete, buildable project in [references/component-example.md](references/component-example.md); its envelope, placement contract, capability declarations, and defensive `ph.state` access are the parts that break when improvised.- **Create with `kind=component`** and a `description` written for store search: say what thediff --git a/products/canvas/skills/querying-canvas-data/SKILL.md b/products/canvas/skills/querying-canvas-data/SKILL.mdindex abd8dd28c400..e5206820f6c5 100644--- a/products/canvas/skills/querying-canvas-data/SKILL.md+++ b/products/canvas/skills/querying-canvas-data/SKILL.md@@ -3,8 +3,9 @@ name: querying-canvas-datadescription: >Get PostHog data into a canvas correctly: the host-injected `ph` SDK (loadInsight, query,capture, state, openExternal, navigate), the data hierarchy (saved insights first, typed query nodes- second, inline HogQL last), per-insight-type result shapes, date-range wiring, and event capture- from a canvas. Use whenever a canvas shows metrics, charts, tables, or any PostHog data, or+ second, inline HogQL last), verifiability (insight-backed metrics link their saved insight in+ PostHog; ad-hoc queries expose the exact query that ran), per-insight-type result shapes, date-range wiring, and event+ capture from a canvas. Use whenever a canvas shows metrics, charts, tables, or any PostHog data, orneeds to send analytics events.---@@ -38,6 +39,35 @@ Whatever tier you use, **declare it in the project's `capabilities`** before pub`captureEvents`, and `inlineQueries: true` for any `ph.query` use. The host rejects undeclaredcalls at runtime, and validation fails on undeclared literals.+## Verifiability — every claim must be checkable in PostHog++A number a viewer cannot verify is a number they cannot trust. Every data-backed figure a canvas+shows — a KPI, a chart, a table, a stated conclusion — must carry the verification affordance for+its tier:++1. **Insight-backed metrics link the real insight in PostHog.** For a metric loaded from a saved+ insight (the preferred tier), render a "View in PostHog" affordance that calls+ `ph.openExternal(insightUrl)` from a click. Mint the URL at authoring time with the+ `generate-app-url` MCP tool (path template `/insights/{id}` with the insight's short id) and+ bake the returned URL into the source verbatim — never hand-build one. `ph.openExternal` only+ opens `https://*.posthog.com` URLs and only from a user gesture, so wire it to a button or+ link, never to load or render. Do not also bake the insight's saved query text into the+ source: canvas source is readable by every canvas viewer, while access to the insight itself+ is enforced by PostHog — the link is where a viewer inspects the query, with their own+ permissions applied.+2. **Ad-hoc queries disclose the exact query that ran, viewable in place.** For a figure computed+ by `ph.query` (a typed node or inline HogQL), show the query behind it — the HogQL text, or+ the typed query node pretty-printed as JSON — in a modal or a collapsed disclosure attached to+ the card (a Quill `Dialog` or `Collapsible` in a React canvas, a `<details>` element in an+ HTML one). Render it from the same constant or builder you pass to `ph.query`, so the+ displayed query can never drift from the executed one. This discloses nothing beyond what the+ viewer already runs: `ph.query` executes as the signed-in viewer.++These are not optional polish: a canvas that presents PostHog data without them is incomplete.+Keep the affordances compact — a small link icon per insight-backed card, a "View query"+disclosure per ad-hoc card, or one shared modal listing every ad-hoc query the canvas runs, each+labeled with the figure it backs.+For a status board, set `refresh` to the cache lifetime in seconds. Use a whole number from 30 to86400 (one day); values outside that range, or fractional ones, fail at runtime:diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 56a3237a3957..75284dc080e7 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -1100,7 +1100,7 @@}},"canvas-draft-create": {- "description": "Build the COMPLETE source project of a canvas as a DRAFT, without changing the live canvas. The project is validated and built server-side exactly like a publish, but the canvas head and live build do NOT move, so viewers keep seeing the current version. For a canvas that already has a live version this is the DEFAULT way to save a change — the user previews and promotes it; use canvas-publish-create only for a first version or when the user explicitly asked to make the change live. Returns the draft's `version_id`, its queued build, and `capability_widening` — how the draft's declared capabilities grow the live version's (insights, capture events, inline queries, network origins) — so added access is visible before shipping. Poll canvas-builds-retrieve until the draft's build is terminal, preview the draft with canvas-source-retrieve passing the returned `version_id`, then make it live with canvas-promote-create. Declare runtime capabilities in `project.capabilities`.",+ "description": "Build the COMPLETE source project of a canvas as a DRAFT, without changing the live canvas. The project is validated and built server-side exactly like a publish, but the canvas head and live build do NOT move, so viewers keep seeing the current version. For a canvas that already has a live version this is the DEFAULT way to save a change — the user previews and promotes it; use canvas-publish-create only for a first version or when the user explicitly asked to make the change live. Returns the draft's `version_id`, its queued build, and `capability_widening` — how the draft's declared capabilities grow the live version's (insights, capture events, inline queries, network origins) — so added access is visible before shipping. Poll canvas-builds-retrieve until the draft's build is terminal, preview the draft with canvas-source-retrieve passing the returned `version_id`, then make it live with canvas-promote-create. Declare runtime capabilities in `project.capabilities`. A project that shows PostHog data must make every figure verifiable before staging: an insight-backed metric links its saved insight (ph.openExternal with a URL from generate-app-url); an ad-hoc ph.query figure exposes the exact query that ran in a modal or collapsed area.","category": "Canvas","feature": "canvas","summary": "Stage a canvas draft build",@@ -1212,7 +1212,7 @@}},"canvas-publish-create": {- "description": "Publish the COMPLETE source project of a canvas as its new head version and queue a server-side build. Publishing goes live immediately: use it for a canvas's first version, or when the user explicitly asked to make a change live — otherwise stage the change with canvas-draft-create for the user to promote. The project is validated first — error diagnostics reject the publish (400) and leave the canvas untouched. Pass `expected_current_version_id` (from canvas-source-retrieve) so a concurrent edit is rejected with 409 version_conflict instead of overwritten; on conflict, re-read the source, re-apply your edits, and publish against the new head. A 429 means the team's build capacity is exhausted — wait a moment and retry. Declare the canvas's runtime capabilities (insights, capture events, inline queries) in `project.capabilities`. The canvas lives in PostHog, not on disk — this tool is what saves it.",+ "description": "Publish the COMPLETE source project of a canvas as its new head version and queue a server-side build. Publishing goes live immediately: use it for a canvas's first version, or when the user explicitly asked to make a change live — otherwise stage the change with canvas-draft-create for the user to promote. The project is validated first — error diagnostics reject the publish (400) and leave the canvas untouched. Pass `expected_current_version_id` (from canvas-source-retrieve) so a concurrent edit is rejected with 409 version_conflict instead of overwritten; on conflict, re-read the source, re-apply your edits, and publish against the new head. A 429 means the team's build capacity is exhausted — wait a moment and retry. Declare the canvas's runtime capabilities (insights, capture events, inline queries) in `project.capabilities`. A project that shows PostHog data must make every figure verifiable before publishing: an insight-backed metric links its saved insight (ph.openExternal with a URL from generate-app-url); an ad-hoc ph.query figure exposes the exact query that ran in a modal or collapsed area. The canvas lives in PostHog, not on disk — this tool is what saves it.","category": "Canvas","feature": "canvas","summary": "Publish canvas source project",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex 379bc20ac837..f68018408bd7 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -1115,7 +1115,7 @@}},"canvas-draft-create": {- "description": "Build the COMPLETE source project of a canvas as a DRAFT, without changing the live canvas. The project is validated and built server-side exactly like a publish, but the canvas head and live build do NOT move, so viewers keep seeing the current version. For a canvas that already has a live version this is the DEFAULT way to save a change — the user previews and promotes it; use canvas-publish-create only for a first version or when the user explicitly asked to make the change live. Returns the draft's `version_id`, its queued build, and `capability_widening` — how the draft's declared capabilities grow the live version's (insights, capture events, inline queries, network origins) — so added access is visible before shipping. Poll canvas-builds-retrieve until the draft's build is terminal, preview the draft with canvas-source-retrieve passing the returned `version_id`, then make it live with canvas-promote-create. Declare runtime capabilities in `project.capabilities`.",+ "description": "Build the COMPLETE source project of a canvas as a DRAFT, without changing the live canvas. The project is validated and built server-side exactly like a publish, but the canvas head and live build do NOT move, so viewers keep seeing the current version. For a canvas that already has a live version this is the DEFAULT way to save a change — the user previews and promotes it; use canvas-publish-create only for a first version or when the user explicitly asked to make the change live. Returns the draft's `version_id`, its queued build, and `capability_widening` — how the draft's declared capabilities grow the live version's (insights, capture events, inline queries, network origins) — so added access is visible before shipping. Poll canvas-builds-retrieve until the draft's build is terminal, preview the draft with canvas-source-retrieve passing the returned `version_id`, then make it live with canvas-promote-create. Declare runtime capabilities in `project.capabilities`. A project that shows PostHog data must make every figure verifiable before staging: an insight-backed metric links its saved insight (ph.openExternal with a URL from generate-app-url); an ad-hoc ph.query figure exposes the exact query that ran in a modal or collapsed area.","category": "Canvas","feature": "canvas","summary": "Stage a canvas draft build",@@ -1227,7 +1227,7 @@}},"canvas-publish-create": {- "description": "Publish the COMPLETE source project of a canvas as its new head version and queue a server-side build. Publishing goes live immediately: use it for a canvas's first version, or when the user explicitly asked to make a change live — otherwise stage the change with canvas-draft-create for the user to promote. The project is validated first — error diagnostics reject the publish (400) and leave the canvas untouched. Pass `expected_current_version_id` (from canvas-source-retrieve) so a concurrent edit is rejected with 409 version_conflict instead of overwritten; on conflict, re-read the source, re-apply your edits, and publish against the new head. A 429 means the team's build capacity is exhausted — wait a moment and retry. Declare the canvas's runtime capabilities (insights, capture events, inline queries) in `project.capabilities`. The canvas lives in PostHog, not on disk — this tool is what saves it.",+ "description": "Publish the COMPLETE source project of a canvas as its new head version and queue a server-side build. Publishing goes live immediately: use it for a canvas's first version, or when the user explicitly asked to make a change live — otherwise stage the change with canvas-draft-create for the user to promote. The project is validated first — error diagnostics reject the publish (400) and leave the canvas untouched. Pass `expected_current_version_id` (from canvas-source-retrieve) so a concurrent edit is rejected with 409 version_conflict instead of overwritten; on conflict, re-read the source, re-apply your edits, and publish against the new head. A 429 means the team's build capacity is exhausted — wait a moment and retry. Declare the canvas's runtime capabilities (insights, capture events, inline queries) in `project.capabilities`. A project that shows PostHog data must make every figure verifiable before publishing: an insight-backed metric links its saved insight (ph.openExternal with a URL from generate-app-url); an ad-hoc ph.query figure exposes the exact query that ran in a modal or collapsed area. The canvas lives in PostHog, not on disk — this tool is what saves it.","category": "Canvas","feature": "canvas","summary": "Publish canvas source project",