: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
docs(data-catalog): move premise monitoring to LLM judges (#78245)
Thiago Salvatore9e1a5faa991d
diff --git a/products/data_catalog/docs/production-monitoring.md b/products/data_catalog/docs/production-monitoring.mdindex bf138d37862c..f51cde222d6d 100644--- a/products/data_catalog/docs/production-monitoring.md+++ b/products/data_catalog/docs/production-monitoring.md@@ -2,40 +2,50 @@How we validate, on live hosted-MCP traffic, that agents honor the data catalog: checking `system.information_schema.metrics` before hand-writing SQL for a metric, running canonical metrics instead of re-deriving them, proposing metrics/certifications when appropriate, and preferring certified sources and accepted relationships.-All of this lives in PostHog's internal telemetry project (US project 2), where the hosted MCP server captures its analytics. The monitoring has three layers.+All of this lives in PostHog's internal telemetry project (US project 2), where the hosted MCP server captures its analytics. The monitoring has three layers: keyword-gated dashboard tiles for free volume and trend, LLM-judge online evaluations for semantic verdicts, and the `services/mcp` instrumentation both depend on.++The division of labor follows one rule: **the judges decide what a session was trying to do; deterministic code only measures what mechanically happened.** A keyword list can never enumerate every way a person asks a metric question (measured coverage of the tile keywords: ~6.5% of SQL sessions), so any check that starts with "was this a metric question?" belongs to a judge. The tiles keep the keyword heuristic as a cheap trend signal, and the judges measure what it misses.## 1. Dashboard tiles (HogQL over existing telemetry)Tile group `7 · Agent behavior` on the "Data catalog usage" dashboard (project 2, dashboard 1902365):-- `7 · Catalog-first rate for KPI sessions`: share of KPI-intent SQL sessions whose metrics-catalog lookup preceded their first data-bearing query.-- `7 · KPI sessions that skip the catalog`: KPI-intent sessions with raw SQL and no catalog lookup or `data-catalog-metric-run` call.+- `7 · Catalog-first rate for KPI sessions`: share of KPI-intent SQL sessions whose metrics-catalog lookup preceded their first data-bearing query. Carries a fleet-wide series and a catalog-enabled series (`mcp_data_catalog_enabled = true`, property exists from Aug 5, 2026).+- `7 · KPI sessions that skip the catalog`: KPI-intent sessions with raw SQL and no catalog lookup or `data-catalog-metric-run` call, same two series.- `7 · Semantic-layer lookups in SQL`: weekly lookups against `information_schema.metrics`, the `certification` column on `information_schema.tables`, and `information_schema.relationships`.- `7 · KPI derivations vs agent proposals`: derivations without catalog engagement next to sessions where an agent called a catalog write tool.+- `7 · Semantic layer judge verdicts`: daily pass/fail/not-applicable counts from the three judge evaluations (matches both the current and pre-rename evaluation names).++Beyond group 7, the dashboard carries curation and quality tiles worth knowing: `2 · Catalog inventory (cumulative)` (running total of metrics, certification marks, accepted relationships), `3 · Review queue backlog (current)` (entities awaiting a human decision, from each entity's latest lifecycle event), and `5 · Canonical share of metric runs` (share of runs returning an approved, non-drifted result - the consumption quality signal).-Data sources: `$mcp_tool_call` events (tool names, ordering per `$session_id`) and the per-`execute-sql` `$ai_generation` events (`$ai_output_choices` carries the SQL text; `posthog.ai_events`, ~30 day retention). Session classification is regex-heuristic: SQL matching `information_schema.metrics` is a catalog lookup, other `information_schema`/`system.` references are schema discovery, everything else is data-bearing; KPI intent is a keyword match on the agent's stated intent.+Data sources: `$mcp_tool_call` events (tool names, ordering per `$session_id`) and the per-`execute-sql` `$ai_generation` events (`$ai_output_choices` carries the SQL text; `posthog.ai_events`, ~30 day retention). Session classification is regex-heuristic: SQL matching `information_schema.metrics` is a catalog lookup, other `information_schema`/`system.` references are schema discovery, everything else is data-bearing; KPI intent is a keyword match on the agent's stated intent. **The keyword match is a known undercount** - the judges below carry the semantic version of the same questions, and comparing the judges' applicability share against the tiles' keyword share over the same catalog-enabled population measures the keyword gate's miss rate.## 2. Online evaluations (AI evals, `/ai-evals` in project 2)-**Live today:** `MCP: catalog checked before KPI derivation` (Hog, trace target, inactivity settle 5 min, 100% rollout, N/A allowed). Fails a session with KPI intent and data-bearing SQL but no prior successful catalog lookup and no `data-catalog-metric-run` span. Deterministic, no LLM cost. Its Hog source mirrors the tile classification above; results land as `$ai_evaluation` events.+Three LLM-judge trace evaluations, live since Aug 5, 2026. Common configuration: trace target, inactivity settle 300s, judge model `claude-haiku-4-5` on the "Team 2 evals" Anthropic provider key, boolean output with N/A allowed, **2% rollout**, conditions `$ai_product = mcp` AND `$ai_span_name = execute-sql` AND `mcp_data_catalog_enabled = true`. Results land as `$ai_evaluation` events. Cost at this configuration: roughly $70/month total.++| Evaluation | Premise | Verdict |+| ------------------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| `Semantic layer: canonical metric bypass (MCP judge)` | 1 | Was the request a governed business measure, in any phrasing? If yes: catalog consulted before hand-written SQL, and an approved non-drifted match run via `data-catalog-metric-run` rather than re-derived? |+| `Semantic layer: metric proposal appropriateness (MCP judge)` | 2 | Did the session derive a reusable business metric with no canonical definition? If yes: proposed or offered to catalog it, disclosed as landing `proposed`? Speculative proposals on one-off exploration also fail. |+| `Semantic layer: trust metadata adherence (MCP judge)` | 3 | Did the agent read certification/relationship metadata? If yes: certified sources preferred over deprecated, accepted join keys used over guessed ones? |-### Writing Hog that survives real traces+Every rubric follows the same shape, and new judges should too: **classify applicability first, judge second, N/A on missing evidence.** The applicability step is where the judge replaces the keyword list - it decides semantically whether the premise applies to this session. The evidence rule matters because judge input is capped at 150k characters and long traces are uniformly sampled down (about a fifth of catalog-enabled traces exceed the cap): the rubric instructs the judge to answer N/A when it cannot see enough to decide, rather than guessing from a partial view.-A trace evaluation runs against traces of up to 500 events under a 10 second budget and a 64 MB VM, and **any** Hog failure disables the evaluation outright (`disables_evaluation=True` on `hog_error`), so a slow evaluation stops scoring until someone re-enables it. The first version of the evaluation above was disabled within minutes by `Execution timed out (10s limit exceeded)`. Three things caused it, all worth avoiding:+### Reading the rates honestly-- **`and` does not short-circuit.** `Operation.AND` pops every operand, so `e.event == '$ai_span' and e.properties.$ai_span_name == '...'` does the property lookups on every event regardless of type. Nest `if` blocks instead of chaining conditions.-- **Regexes are compiled per call.** `=~*` with an alternation, evaluated once per event, dominated the budget. Use `lower()` once and then `like`.-- **Stop scanning once the verdict is latched.** Guard the expensive string work behind the state that makes it irrelevant, and `return` from inside the loop when no later event can change the answer.+- **Compliance rates are conditional.** A judged trace only produces a pass/fail when the premise applied; the rest are N/A. At 2% rollout (~1,750 judged traces/month) with roughly a tenth of sessions being metric questions, expect on the order of 175 applicable verdicts/month, which puts about ±7 points on the monthly compliance rate. Report monthly, not weekly. Raising rollout to 5% (~$175/month) tightens this if needed.+- **The applicability share is itself a result.** It is the semantic answer to "what fraction of sessions are metric questions", and dividing the tile's keyword-matched share by it gives the keyword gate's measured miss rate.+- **Calibration gates publication.** Hand-read a few dozen verdicts per judge (verdict plus reasoning) before putting any pass-rate on the dashboard, and check specifically whether Haiku's reasoning is deep enough on proposal appropriateness - that judge has the subtlest call and is the candidate for moving to `claude-sonnet-4-6`.+- **There is no pre-enable test path for trace-target evaluations.** `evaluation_runs` rejects trace-target re-runs against a single generation, and the Hog test endpoint does not cover LLM judges, so validation happens by enabling at a small rollout and reading verdicts. Judge failures (parse errors, provider hiccups) do not auto-disable the evaluation the way Hog errors do.-Memory is a separate, rarer failure: reading a global does `deepcopy(...)` onto the 64 MB stack, so an oversized trace can exceed it before any of your code runs. Traces above 500 events are skipped upstream (`trace_too_large`), which catches the worst runaways, but a trace that passes that check with large payloads can still fail, and there is no Hog-side mitigation. Validate with `llma-evaluation-test-hog` against real traces before enabling, and check the evaluation's `status_reason_detail` if it goes quiet.+Evaluation definitions are per-team database rows, not repo code; this document is their source of truth.-**Pending `trackToolSpan` deployment** (`services/mcp/src/hono/analytics.ts`): three LLM-judge trace evaluations, sampled low (5-10%) via `rollout_percentage`:+### Retired: the deterministic Hog evaluation-1. **Metric bypass**: the `$ai_span` for a catalog lookup carries the results (`$ai_output_state`), so the judge sees which metrics the lookup returned. Verdict: given an approved, non-drifted metric matching the session's intent, did the client run it via `data-catalog-metric-run`, or hand-write SQL for the same number?-2. **Proposal appropriateness**: given the session's intents, SQL, and tool spans, did the agent derive a reusable business metric with no canonical definition, and if so did it propose or offer to catalog it (landing `proposed`, disclosed as such)? One-off exploration must not trigger speculative proposals.-3. **Trust adherence**: given certification/relationship metadata the agent read, did the final SQL prefer `certified` over `deprecated` sources and use accepted join keys from `information_schema.relationships`?+`MCP: catalog checked before KPI derivation` (Hog) ran Aug 4-5, 2026 and is retired, disabled pending deletion. Two reasons. Its applicability gate was a keyword list, which required predicting every phrasing of a metric question and measurably covered ~6.5% of sessions - the judges classify semantically instead. And it duplicated the catalog-first tile's measurement with worse failure semantics: any single Hog failure disables the whole evaluation (`disables_evaluation=True` on `hog_error`), which took it offline twice in two days, once from a 10s timeout on a pathological trace and once when tool-span capture changed the traffic shape under it.-Evaluation definitions are per-team database rows, not repo code; this document is their source of truth. When creating or editing them, validate Hog with the evaluation test endpoint (`llma-evaluation-test-hog`) against real traces first, and spot-check judge verdicts at a tiny rollout before trusting rates.+The Hog authoring constraints learned from those incidents still apply to any future Hog trace evaluation: `and` does not short-circuit (nest `if`s), regexes compile per call (use `lower()` + `like`), never iterate `evaluation_events` (index `evaluation_events[i]` with the bound from `trace.event_count`; Hog arrays are 1-indexed - iteration cost is proportional to total trace payload now that every tool call carries args and results), return early once the verdict is latched, scope conditions to the population you mean, and validate with `llma-evaluation-test-hog` against real traces before enabling. Memory is a separate hazard with no Hog-side mitigation: reading a global deepcopies it onto the 64 MB stack, so a large-payload trace under the 500-event cap can still fail.## 3. Instrumentation contract (`services/mcp`)@@ -48,5 +58,5 @@ Evaluation definitions are per-team database rows, not repo code; this document- The evaluation scheduler triggers only on `$ai_generation`, so sessions with no `execute-sql` call are never evaluated; they remain visible in the dashboard tiles via `$mcp_tool_call`.- `posthog.ai_events` retention (~30 days) bounds every SQL-text-based measure.-- A single failing trace disables the whole evaluation rather than skipping that trace, so a rare oversized trace can silently stop scoring. Watch for the auto-disable email.-- The customer's catalog contents are not directly joinable from telemetry; "a matching metric existed" is judged from lookup results in spans, not from the source of truth.+- Judge input is capped at 150k characters with uniform sampling beyond it, so verdicts on very long sessions lean on the N/A-on-missing-evidence rule; the compliance rate has a known blind spot on the fat tail.+- The customer's catalog contents are not directly joinable from telemetry; "a matching metric existed" is judged from lookup results visible in the trace, not from the source of truth.