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.

chore(aio): teach agents per-type eval failures and key requirements (#117788)

Bernat Torresea53a3c53cbb
diff --git a/products/ai_observability/backend/api/models.py b/products/ai_observability/backend/api/models.py
index a38f0bb58c56..2721ba10ddb3 100644
--- a/products/ai_observability/backend/api/models.py
+++ b/products/ai_observability/backend/api/models.py
@@ -39,7 +39,9 @@ class LLMProviderModelsSummarySerializer(serializers.Serializer):
requires_provider_key = serializers.BooleanField(
help_text=(
"True when this provider's models can only be listed by passing `key_id` for one of the team's provider "
- "keys. PostHog funds no models for it, so `model_count` is 0 until a key is supplied."
+ "keys, so `model_count` is 0 until a key is supplied. False means PostHog funds some of the provider's "
+ "models in the playground. LLM-judge evaluations and LLM taggers always run on one of the team's own "
+ "provider keys, whatever this value is."
)
)
diff --git a/products/ai_observability/frontend/generated/api.schemas.ts b/products/ai_observability/frontend/generated/api.schemas.ts
index c117d38da1bb..b106a98e4e7b 100644
--- a/products/ai_observability/frontend/generated/api.schemas.ts
+++ b/products/ai_observability/frontend/generated/api.schemas.ts
@@ -3460,7 +3460,7 @@ export interface LLMProviderModelsSummaryApi {
provider: string
/** How many of this provider's models appear in `models`. */
model_count: number
- /** True when this provider's models can only be listed by passing `key_id` for one of the team's provider keys. PostHog funds no models for it, so `model_count` is 0 until a key is supplied. */
+ /** True when this provider's models can only be listed by passing `key_id` for one of the team's provider keys, so `model_count` is 0 until a key is supplied. False means PostHog funds some of the provider's models in the playground. LLM-judge evaluations and LLM taggers always run on one of the team's own provider keys, whatever this value is. */
requires_provider_key: boolean
}
diff --git a/products/ai_observability/skills/exploring-ai-failures/references/finding-traces.md b/products/ai_observability/skills/exploring-ai-failures/references/finding-traces.md
index 5c7b10886524..a6b3e13670ea 100644
--- a/products/ai_observability/skills/exploring-ai-failures/references/finding-traces.md
+++ b/products/ai_observability/skills/exploring-ai-failures/references/finding-traces.md
@@ -87,10 +87,15 @@ posthog:llma-evaluation-list { "enabled": true }
SELECT toDate(timestamp) AS day, count() AS fails
FROM events
WHERE event = '$ai_evaluation' AND properties.$ai_evaluation_id = '<uuid>'
- AND properties.$ai_evaluation_result = false AND timestamp >= now() - INTERVAL 30 DAY
+ AND (<fail predicate>) AND (isNull(properties.$ai_evaluation_skipped) OR properties.$ai_evaluation_skipped != 'true')
+ AND (isNull(properties.$ai_evaluation_applicable) OR properties.$ai_evaluation_applicable != 'false')
+ AND timestamp >= now() - INTERVAL 30 DAY
GROUP BY day ORDER BY day
```
+Build `<fail predicate>` from the eval's output type and config, as in the fail predicate table in
+`exploring-llm-evaluations`. `$ai_evaluation_result = 'false'` only fits a pass/fail eval that is not a detector.
+
`exploring-llm-evaluations` covers reading eval results in depth.
## Counting failure modes
diff --git a/products/ai_observability/skills/exploring-llm-evaluations/SKILL.md b/products/ai_observability/skills/exploring-llm-evaluations/SKILL.md
index 3227b35f54e5..899f53751991 100644
--- a/products/ai_observability/skills/exploring-llm-evaluations/SKILL.md
+++ b/products/ai_observability/skills/exploring-llm-evaluations/SKILL.md
@@ -101,14 +101,34 @@ For evaluations that don't support N/A, this property may be `null` — treat nu
For boolean evaluations, `output_config.true_is_failure: false` maps `true` to pass and `false` to fail.
Set it to `true` for detector-style evaluations where `true` means the evaluator found a problem.
+### The fail predicate
+
+Events store the raw result, not pass or fail. PostHog applies the evaluation's current `output_type` and
+`output_config` when it reads them. Build `<fail predicate>` from the config that `llma-evaluation-get`
+returns, and use it wherever the queries below filter for fails:
+
+| Evaluation | `<fail predicate>` |
+| ------------------------------------------------ | --------------------------------------------------------------------- |
+| `boolean`, `true_is_failure` false or unset | `properties.$ai_evaluation_result = 'false'` |
+| `boolean`, `true_is_failure: true` (detector) | `properties.$ai_evaluation_result = 'true'` |
+| `numeric`, `passing_rule` `gte` threshold `T` | `toFloat(properties.$ai_evaluation_numeric_result) < T` |
+| `numeric`, `passing_rule` `lte` threshold `T` | `toFloat(properties.$ai_evaluation_numeric_result) > T` |
+| `categorical`, `passing_rule.categories` `[a,b]` | `NOT (notEmpty(<cats>) AND hasAll(['a', 'b'], <cats>))` |
+| `categorical`, `passing_rule.categories` `[]` | `notEmpty(<cats>)` |
+| `numeric` or `categorical` with no passing rule | None. Read the score or categories directly, there is no pass or fail |
+
+`<cats>` is `JSONExtract(ifNull(properties.$ai_evaluation_categorical_result, '[]'), 'Array(String)')`.
+Always add `(isNull(properties.$ai_evaluation_skipped) OR properties.$ai_evaluation_skipped != 'true')`, because a skipped run can still store
+`result = false`. Compare these properties to the strings `'true'` and `'false'`: a project without Boolean
+property definitions reads them as strings, and a comparison to a bare `true` or `false` then fails.
+
## Workflow: investigate why an evaluation is failing
-Works the same way for boolean `llm_judge` and `hog` evaluations — the differences
+Works the same way for `llm_judge` and `hog` evaluations — the differences
only matter when you eventually go to fix the evaluator (edit the prompt vs. edit
the Hog source). Sentiment evaluations should be inspected by sentiment label and
score rather than pass/fail filters.
-The SQL pass/fail examples below use boolean results.
-For numeric and categorical evaluations, read their result property and current passing rule instead of `$ai_evaluation_result`.
+The queries below take the evaluation's `<fail predicate>` from the table above.
### Step 1 — Find the evaluation
@@ -130,20 +150,13 @@ before assuming the failure is in the generation.
```sql
posthog:execute-sql
SELECT
- countIf(properties.$ai_evaluation_applicable = false) AS na_count,
- countIf(
- (properties.$ai_evaluation_applicable IS NULL
- OR properties.$ai_evaluation_applicable != false)
- AND properties.$ai_evaluation_result = true
- ) AS pass_count,
- countIf(
- (properties.$ai_evaluation_applicable IS NULL
- OR properties.$ai_evaluation_applicable != false)
- AND properties.$ai_evaluation_result = false
- ) AS fail_count
+ countIf(properties.$ai_evaluation_applicable = 'false') AS na_count,
+ countIf((isNull(properties.$ai_evaluation_applicable) OR properties.$ai_evaluation_applicable != 'false') AND NOT (<fail predicate>)) AS pass_count,
+ countIf((isNull(properties.$ai_evaluation_applicable) OR properties.$ai_evaluation_applicable != 'false') AND (<fail predicate>)) AS fail_count
FROM events
WHERE event = '$ai_evaluation'
AND properties.$ai_evaluation_id = '<evaluation_uuid>'
+ AND (isNull(properties.$ai_evaluation_skipped) OR properties.$ai_evaluation_skipped != 'true')
AND timestamp >= now() - INTERVAL 7 DAY
```
@@ -166,11 +179,9 @@ SELECT
FROM events
WHERE event = '$ai_evaluation'
AND properties.$ai_evaluation_id = '<evaluation_uuid>'
- AND properties.$ai_evaluation_result = false
- AND (
- properties.$ai_evaluation_applicable IS NULL
- OR properties.$ai_evaluation_applicable != false
- )
+ AND (<fail predicate>)
+ AND (isNull(properties.$ai_evaluation_applicable) OR properties.$ai_evaluation_applicable != 'false')
+ AND (isNull(properties.$ai_evaluation_skipped) OR properties.$ai_evaluation_skipped != 'true')
AND timestamp >= now() - INTERVAL 7 DAY
ORDER BY timestamp DESC
LIMIT 25
@@ -344,7 +355,9 @@ identical.
FROM events
WHERE event = '$ai_evaluation'
AND properties.$ai_evaluation_id = '<uuid>'
- AND properties.$ai_evaluation_result = false
+ AND (<fail predicate>)
+ AND (isNull(properties.$ai_evaluation_applicable) OR properties.$ai_evaluation_applicable != 'false')
+ AND (isNull(properties.$ai_evaluation_skipped) OR properties.$ai_evaluation_skipped != 'true')
AND timestamp >= now() - INTERVAL 30 DAY
GROUP BY day
ORDER BY day
@@ -354,8 +367,8 @@ identical.
### "Are passes and fails caused by the same root content?"
-1. Pull two samples with the Step 3 query, flipping `$ai_evaluation_result` between
- `true` and `false`
+1. Pull two samples with the Step 3 query, once with `<fail predicate>` and once with
+ `NOT (<fail predicate>)`
2. If the passing and failing runs describe similar content:
- For an `llm_judge`: the prompt or rubric is probably ambiguous — reword
`evaluation_config.prompt` and use `llma-evaluation-update`
@@ -390,7 +403,7 @@ SELECT
FROM events
WHERE event = '$ai_evaluation'
AND properties.$ai_evaluation_id = '<evaluation_uuid>'
- AND properties.$ai_evaluation_applicable = false
+ AND properties.$ai_evaluation_applicable = 'false'
AND timestamp >= now() - INTERVAL 7 DAY
ORDER BY timestamp DESC
LIMIT 25
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index a1765bece5ea..6ac97a570451 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -61389,7 +61389,7 @@ export namespace Schemas {
provider: string;
/** How many of this provider's models appear in `models`. */
model_count: number;
- /** True when this provider's models can only be listed by passing `key_id` for one of the team's provider keys. PostHog funds no models for it, so `model_count` is 0 until a key is supplied. */
+ /** True when this provider's models can only be listed by passing `key_id` for one of the team's provider keys, so `model_count` is 0 until a key is supplied. False means PostHog funds some of the provider's models in the playground. LLM-judge evaluations and LLM taggers always run on one of the team's own provider keys, whatever this value is. */
requires_provider_key: boolean;
}