Skip to content

: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.

fix(llma): tag runs list shows empty when data exists (#58087)

Andrew Maguireaec43cd801a2
diff --git a/products/llm_analytics/frontend/tags/llmTaggerLogic.test.ts b/products/llm_analytics/frontend/tags/llmTaggerLogic.test.ts
index 674866d03797..93b10f0fc65b 100644
--- a/products/llm_analytics/frontend/tags/llmTaggerLogic.test.ts
+++ b/products/llm_analytics/frontend/tags/llmTaggerLogic.test.ts
@@ -523,5 +523,47 @@ describe('llmTaggerLogic', () => {
],
})
})
+
+ // Regression: combining `values: { tagger_id }` with `{filters}` made the
+ // backend's parse_select throw, the loader's catch silently returned [],
+ // and the runs tab rendered empty even when matching events existed.
+ // Lock in that the request inlines (and escapes) the id into the query
+ // string and does not send a `values` dict.
+ it.each([
+ ['plain id', 'tagger-abc', "properties.$ai_tagger_id = 'tagger-abc'"],
+ ['id with single quote', "o'malley", "properties.$ai_tagger_id = 'o\\'malley'"],
+ ['id with backslash', 'tagger\\abc', "properties.$ai_tagger_id = 'tagger\\\\abc'"],
+ ])('inlines the tagger id without a values dict (%s)', async (_label, taggerId, expectedSnippet) => {
+ const capturedQueries: { query: string; values?: unknown }[] = []
+ useMocks({
+ get: {
+ [`/api/environments/:team_id/taggers/${taggerId}/`]: mockTagger,
+ },
+ post: {
+ '/api/environments/:team_id/query/:kind': async (req, res, ctx) => {
+ const body = (await req.json()) as { query?: { query?: string; values?: unknown } }
+ if (body.query?.query?.includes('$ai_tagger_id')) {
+ capturedQueries.push({
+ query: body.query.query,
+ values: body.query.values,
+ })
+ }
+ return res(ctx.json({ results: [] }))
+ },
+ },
+ })
+
+ logic = llmTaggerLogic({ id: taggerId })
+ logic.mount()
+
+ await expectLogic(logic).toDispatchActions(['loadTagRunsSuccess'])
+
+ expect(capturedQueries).toHaveLength(1)
+ const sent = capturedQueries[0]
+ expect(sent.query).toContain(expectedSnippet)
+ expect(sent.query).toContain('{filters}')
+ expect(sent.query).not.toContain('{tagger_id}')
+ expect(sent.values).toBeUndefined()
+ })
})
})
diff --git a/products/llm_analytics/frontend/tags/llmTaggerLogic.ts b/products/llm_analytics/frontend/tags/llmTaggerLogic.ts
index 3176c2f082c2..73774238a09c 100644
--- a/products/llm_analytics/frontend/tags/llmTaggerLogic.ts
+++ b/products/llm_analytics/frontend/tags/llmTaggerLogic.ts
@@ -8,6 +8,7 @@ import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
import { HogQLQuery, NodeKind, TrendsQuery } from '~/queries/schema/schema-general'
+import { escapeHogQLString } from '~/queries/utils'
import { ChartDisplayType, PropertyFilterType, PropertyOperator } from '~/types'
import { llmAnalyticsSharedLogic } from '../llmAnalyticsSharedLogic'
@@ -312,9 +313,13 @@ export const llmTaggerLogic = kea<llmTaggerLogicType>([
}
const dateFrom = values.dateFilter?.dateFrom || '-24h'
const dateTo = values.dateFilter?.dateTo || null
- // Use a HogQL parameter placeholder rather than string interpolation —
- // props.id comes from the URL path, so interpolating it directly into
- // the query text would open an injection vector.
+ // Inline the tagger_id rather than using a `values` dict: parse_select
+ // eagerly resolves all placeholders against `values` before
+ // find_placeholders runs, which means combining `{tagger_id}` with
+ // `{filters}` fails — `{filters}` is missing from `values` and the
+ // whole query errors out, leaving the runs list silently empty.
+ // escapeHogQLString returns the value already wrapped in single quotes.
+ const escapedTaggerId = escapeHogQLString(props.id)
const query: HogQLQuery = {
kind: NodeKind.HogQLQuery,
query: `
@@ -328,12 +333,11 @@ export const llmTaggerLogic = kea<llmTaggerLogicType>([
properties.$ai_tagger_name as tagger_name
FROM events
WHERE event = '$ai_tag'
- AND properties.$ai_tagger_id = {tagger_id}
+ AND properties.$ai_tagger_id = ${escapedTaggerId}
AND {filters}
ORDER BY timestamp DESC
LIMIT 100
`,
- values: { tagger_id: props.id },
filters: {
dateRange: {
date_from: dateFrom,
diff --git a/products/llm_analytics/frontend/traceMessagesLazyLoaderLogic.ts b/products/llm_analytics/frontend/traceMessagesLazyLoaderLogic.ts
index 733a240a9fd4..ec701fcb99c6 100644
--- a/products/llm_analytics/frontend/traceMessagesLazyLoaderLogic.ts
+++ b/products/llm_analytics/frontend/traceMessagesLazyLoaderLogic.ts
@@ -3,6 +3,7 @@ import { actions, events, kea, listeners, path, reducers, selectors } from 'kea'
import api from 'lib/api'
import { HogQLQuery, NodeKind } from '~/queries/schema/schema-general'
+import { escapeHogQLString } from '~/queries/utils'
import type { traceMessagesLazyLoaderLogicType } from './traceMessagesLazyLoaderLogicType'
import { parsePartialJSON } from './utils'
@@ -38,11 +39,6 @@ function chunk<T>(arr: T[], size: number): T[][] {
return chunks
}
-// Escape a trace ID for safe inlining into a single-quoted HogQL string.
-function escapeHogqlString(value: string): string {
- return value.replace(/\\/g, '\\\\').replace(/'/g, "''")
-}
-
// "2026-04-11T19:20:55.828Z" → "2026-04-11 19:20:55" (ClickHouse toDateTime format, UTC).
function formatHogqlDateTime(d: Date): string {
return d.toISOString().replace('T', ' ').slice(0, 19)
@@ -192,9 +188,9 @@ export const traceMessagesLazyLoaderLogic = kea<traceMessagesLazyLoaderLogicType
// Inlining IDs + timestamps rather than using a values dict: we
// can't combine `{values}` with `{filters}`-style placeholders
// because parse_select eagerly resolves all placeholders against
- // the values dict before find_placeholders runs. Each ID is
- // escaped via escapeHogqlString.
- const idList = safe.map((s) => `'${escapeHogqlString(s.id)}'`).join(',')
+ // the values dict before find_placeholders runs.
+ // escapeHogQLString returns the value already wrapped in single quotes.
+ const idList = safe.map((s) => escapeHogQLString(s.id)).join(',')
const query: HogQLQuery = {
kind: NodeKind.HogQLQuery,
query: `