: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(aio): compare evaluation result as a string in pass-rate queries (#72794)
posthog[bot]a56d110e58d5
diff --git a/products/ai_observability/frontend/evaluations/AIObservabilityEvaluation.tsx b/products/ai_observability/frontend/evaluations/AIObservabilityEvaluation.tsxindex a49433036254..cd88e64e5ce2 100644--- a/products/ai_observability/frontend/evaluations/AIObservabilityEvaluation.tsx+++ b/products/ai_observability/frontend/evaluations/AIObservabilityEvaluation.tsx@@ -42,7 +42,7 @@ import { EvaluationReportConfig } from './components/EvaluationReportConfig'import { EvaluationReportsTab } from './components/EvaluationReportsTab'import { EvaluationRunsTable } from './components/EvaluationRunsTable'import { EvaluationTriggers } from './components/EvaluationTriggers'-import { EVALUATION_SUMMARY_MAX_RUNS } from './constants'+import { EVALUATION_PASSED_HOGQL, EVALUATION_SUMMARY_MAX_RUNS } from './constants'import {evaluationSupportsReports,evaluationSupportsRunSummary,@@ -136,7 +136,7 @@ export function AIObservabilityEvaluation(): JSX.Element {event: '$ai_evaluation',custom_name: `${evaluation.name} — Pass rate`,math: HogQLMathType.HogQL,- math_hogql: `if(countIf(properties.$ai_evaluation_result IS NOT NULL) > 0, countIf(properties.$ai_evaluation_result = 1) / countIf(properties.$ai_evaluation_result IS NOT NULL) * 100, 0)`,+ math_hogql: `if(countIf(properties.$ai_evaluation_result IS NOT NULL) > 0, countIf(${EVALUATION_PASSED_HOGQL}) / countIf(properties.$ai_evaluation_result IS NOT NULL) * 100, 0)`,properties: [{key: '$ai_evaluation_id',diff --git a/products/ai_observability/frontend/evaluations/constants.ts b/products/ai_observability/frontend/evaluations/constants.tsindex ab4aca5b654c..30fd2151fbaf 100644--- a/products/ai_observability/frontend/evaluations/constants.ts+++ b/products/ai_observability/frontend/evaluations/constants.ts@@ -1,3 +1,11 @@// Evaluation summary limits// This should match EVALUATION_SUMMARY_MAX_RUNS in backend/summarization/constants.pyexport const EVALUATION_SUMMARY_MAX_RUNS = 250++// Compared against the string 'true', not `= true` or `= 1`: HogQL types $ai_evaluation_result from+// each team's own property definition, so teams that haven't registered it as Boolean extract the+// JSON bool as the string 'true' (where a numeric literal throws), while Boolean-registered teams+// still compare correctly against the string form. Reading the property directly rather than via+// JSONExtractString keeps the lookup on the properties_group_ai column and its bloom filter index.+// Same reasoning as the predicates in posthog/temporal/ai_observability/eval_reports/output_types.py.+export const EVALUATION_PASSED_HOGQL = "properties.$ai_evaluation_result = 'true'"diff --git a/products/ai_observability/frontend/evaluations/evaluationMetricsLogic.ts b/products/ai_observability/frontend/evaluations/evaluationMetricsLogic.tsindex bb3f2193f7de..a21b0eb25c7e 100644--- a/products/ai_observability/frontend/evaluations/evaluationMetricsLogic.ts+++ b/products/ai_observability/frontend/evaluations/evaluationMetricsLogic.ts@@ -9,6 +9,7 @@ import { ChartDisplayType, HogQLMathType } from '~/types'// eslint-disable-next-line import/no-cycleimport { PASS_RATE_SUCCESS_THRESHOLD } from './components/EvaluationMetrics'+import { EVALUATION_PASSED_HOGQL } from './constants'import { llmEvaluationsLogic } from './llmEvaluationsLogic'import { EvaluationConfig } from './types'@@ -176,7 +177,7 @@ export const evaluationMetricsLogic = kea<evaluationMetricsLogicType>([properties.$ai_evaluation_id as evaluation_id,count() as runs_count,countIf(properties.$ai_evaluation_result IS NOT NULL) as applicable_count,- countIf(properties.$ai_evaluation_result = 1) as pass_count+ countIf(${EVALUATION_PASSED_HOGQL}) as pass_countFROM eventsWHERE event = '$ai_evaluation' AND {filters}GROUP BY evaluation_id@@ -283,7 +284,7 @@ export const evaluationMetricsLogic = kea<evaluationMetricsLogicType>([custom_name: evaluation.name,math: HogQLMathType.HogQL,// Pass rate excludes N/A results, returns 0 if all results are N/A- math_hogql: `if(countIf(properties.$ai_evaluation_id = '${evaluation.id}' AND properties.$ai_evaluation_result IS NOT NULL) > 0, countIf(properties.$ai_evaluation_id = '${evaluation.id}' AND properties.$ai_evaluation_result = 1) / countIf(properties.$ai_evaluation_id = '${evaluation.id}' AND properties.$ai_evaluation_result IS NOT NULL) * 100, 0)`,+ math_hogql: `if(countIf(properties.$ai_evaluation_id = '${evaluation.id}' AND properties.$ai_evaluation_result IS NOT NULL) > 0, countIf(properties.$ai_evaluation_id = '${evaluation.id}' AND ${EVALUATION_PASSED_HOGQL}) / countIf(properties.$ai_evaluation_id = '${evaluation.id}' AND properties.$ai_evaluation_result IS NOT NULL) * 100, 0)`,})),trendsFilter: {display: ChartDisplayType.ActionsLineGraph,diff --git a/products/ai_observability/frontend/utils.ts b/products/ai_observability/frontend/utils.tsindex 5e6538f4ae7d..1af7cf19c6cc 100644--- a/products/ai_observability/frontend/utils.ts+++ b/products/ai_observability/frontend/utils.ts@@ -8,7 +8,7 @@ import { LLMTrace, LLMTraceEvent } from '~/queries/schema/schema-general'import { hogql } from '~/queries/utils'import type { SpanAggregation } from './aiObservabilityTraceDataLogic'-import { EVALUATION_SUMMARY_MAX_RUNS } from './evaluations/constants'+import { EVALUATION_PASSED_HOGQL, EVALUATION_SUMMARY_MAX_RUNS } from './evaluations/constants'import type { EvaluationOutputType, EvaluationRun, EvaluationType } from './evaluations/types'import {AnthropicDocumentMessage,@@ -1231,7 +1231,7 @@ export async function queryEvaluationRunsStats(params: {SELECTcount() as total,countIf(properties.$ai_evaluation_result IS NOT NULL) as applicable,- countIf(properties.$ai_evaluation_result = 1) as passed+ countIf(${hogql.raw(EVALUATION_PASSED_HOGQL)}) as passedFROM eventsWHEREevent = '$ai_evaluation'