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): validate evaluation conditions shape so unknown keys are dropped (#60519)

Steven Shults41fc7b9e7b4c
diff --git a/products/ai_observability/backend/api/evaluations.py b/products/ai_observability/backend/api/evaluations.py
index 376bfa83d014..1fa65f911b6d 100644
--- a/products/ai_observability/backend/api/evaluations.py
+++ b/products/ai_observability/backend/api/evaluations.py
@@ -113,6 +113,23 @@ class ModelConfigurationSerializer(serializers.Serializer):
}
+class EvaluationConditionSerializer(serializers.Serializer):
+ """A trigger condition set controlling which generations an evaluation runs on."""
+
+ id = serializers.CharField(max_length=100, help_text="Stable identifier for this condition set.")
+ rollout_percentage = serializers.FloatField(
+ default=100,
+ min_value=0,
+ max_value=100,
+ help_text="Percentage (0-100) of matching events to sample for this evaluation. Defaults to 100.",
+ )
+ properties = serializers.ListField(
+ child=serializers.DictField(),
+ default=list,
+ help_text="Property filters (event or person) that scope which generations match this condition set.",
+ )
+
+
class EvaluationSerializer(serializers.ModelSerializer):
created_by = UserBasicSerializer(read_only=True)
model_configuration = ModelConfigurationSerializer(required=False, allow_null=True)
@@ -124,6 +141,15 @@ class EvaluationSerializer(serializers.ModelSerializer):
required=False,
help_text="Output config. For 'boolean' output_type: {allows_na} to permit N/A results.",
)
+ conditions = EvaluationConditionSerializer(
+ many=True,
+ required=False,
+ help_text=(
+ "Trigger conditions that filter which events are evaluated. OR between condition sets, "
+ "AND within each. Each set is {id, rollout_percentage, properties[]} — `rollout_percentage` "
+ "(0-100, defaults to 100) is the sampling field the dispatcher reads."
+ ),
+ )
class Meta:
model = Evaluation
@@ -156,9 +182,6 @@ class EvaluationSerializer(serializers.ModelSerializer):
"help_text": "'llm_judge' uses an LLM to score outputs against a prompt; 'hog' runs deterministic Hog code."
},
"output_type": {"help_text": "Output format. Currently only 'boolean' is supported."},
- "conditions": {
- "help_text": "Optional trigger conditions to filter which events are evaluated. OR between condition sets, AND within each."
- },
"deleted": {"help_text": "Set to true to soft-delete the evaluation."},
}
diff --git a/products/ai_observability/backend/api/test/test_evaluations.py b/products/ai_observability/backend/api/test/test_evaluations.py
index 98ec5d66180f..d07540fcaab2 100644
--- a/products/ai_observability/backend/api/test/test_evaluations.py
+++ b/products/ai_observability/backend/api/test/test_evaluations.py
@@ -3,6 +3,7 @@ from uuid import uuid4
from posthog.test.base import APIBaseTest
from unittest.mock import patch
+from parameterized import parameterized
from rest_framework import status
from posthog.models import Organization, Project, Team, User
@@ -448,6 +449,67 @@ class TestEvaluationConfigsApi(APIBaseTest):
self.assertEqual(len(response.data["conditions"][0]["properties"]), 1)
self.assertEqual(response.data["conditions"][0]["properties"][0]["key"], "$ai_model_name")
+ def test_unknown_condition_keys_are_dropped_and_rollout_percentage_defaults_to_100(self):
+ # Regression: callers (notably MCP) previously sent `sampling_rate` instead of
+ # `rollout_percentage` and the unstructured JSONField silently persisted it. The
+ # dispatcher reads `rollout_percentage`, so the eval looked configured on the
+ # API surface (GET echoed `sampling_rate`) but never fired.
+ response = self.client.post(
+ f"/api/environments/{self.team.id}/evaluations/",
+ {
+ "name": "Typo eval",
+ "evaluation_type": "llm_judge",
+ "evaluation_config": {"prompt": "Evaluate"},
+ "output_type": "boolean",
+ "output_config": {},
+ "conditions": [{"id": "cond-1", "sampling_rate": 100, "properties": []}],
+ },
+ )
+ self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.json())
+ condition = response.data["conditions"][0]
+ self.assertNotIn("sampling_rate", condition)
+ self.assertEqual(condition["rollout_percentage"], 100)
+
+ stored = Evaluation.objects.get(id=response.data["id"])
+ self.assertEqual(stored.conditions[0]["rollout_percentage"], 100)
+ self.assertNotIn("sampling_rate", stored.conditions[0])
+
+ get_response = self.client.get(f"/api/environments/{self.team.id}/evaluations/{response.data['id']}/")
+ self.assertEqual(get_response.status_code, status.HTTP_200_OK)
+ self.assertNotIn("sampling_rate", get_response.data["conditions"][0])
+ self.assertEqual(get_response.data["conditions"][0]["rollout_percentage"], 100)
+
+ @parameterized.expand([(-1,), (101,), (150,)])
+ def test_rollout_percentage_out_of_range_rejected(self, rollout_percentage):
+ response = self.client.post(
+ f"/api/environments/{self.team.id}/evaluations/",
+ {
+ "name": "Out of range",
+ "evaluation_type": "llm_judge",
+ "evaluation_config": {"prompt": "Evaluate"},
+ "output_type": "boolean",
+ "output_config": {},
+ "conditions": [{"id": "cond-1", "rollout_percentage": rollout_percentage, "properties": []}],
+ },
+ )
+ self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
+
+ @parameterized.expand([(0,), (100,)])
+ def test_rollout_percentage_boundaries_accepted(self, rollout_percentage):
+ response = self.client.post(
+ f"/api/environments/{self.team.id}/evaluations/",
+ {
+ "name": "Boundary",
+ "evaluation_type": "llm_judge",
+ "evaluation_config": {"prompt": "Evaluate"},
+ "output_type": "boolean",
+ "output_config": {},
+ "conditions": [{"id": "cond-1", "rollout_percentage": rollout_percentage, "properties": []}],
+ },
+ )
+ self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.json())
+ self.assertEqual(response.data["conditions"][0]["rollout_percentage"], rollout_percentage)
+
class TestTestHogEndpoint(APIBaseTest):
def _mock_hogql_response(self, count=1):
diff --git a/products/ai_observability/backend/migrations/0003_normalize_evaluation_conditions.py b/products/ai_observability/backend/migrations/0003_normalize_evaluation_conditions.py
new file mode 100644
index 000000000000..4f3c5b2dec76
--- /dev/null
+++ b/products/ai_observability/backend/migrations/0003_normalize_evaluation_conditions.py
@@ -0,0 +1,95 @@
+from uuid import uuid4
+
+from django.db import migrations
+
+# Keys the EvaluationConditionSerializer accepts, plus the bytecode keys that
+# Evaluation.save() writes onto each condition. Anything else (e.g. a legacy
+# `sampling_rate`) is dropped during normalization.
+_ALLOWED_KEYS = frozenset({"id", "rollout_percentage", "properties", "bytecode", "bytecode_error"})
+
+# Keys of a PostHog property filter that some legacy rows stored at the condition's
+# top level instead of nested inside `properties`.
+_PROPERTY_FILTER_KEYS = ("key", "value", "operator", "type", "group_type_index")
+
+
+def _condition_is_clean(condition):
+ if not isinstance(condition, dict):
+ return False
+ if not (isinstance(condition.get("id"), str) and condition["id"]):
+ return False
+ rollout = condition.get("rollout_percentage")
+ if isinstance(rollout, bool) or not isinstance(rollout, (int, float)):
+ return False
+ properties = condition.get("properties")
+ if not isinstance(properties, list) or not all(isinstance(p, dict) for p in properties):
+ return False
+ return all(key in _ALLOWED_KEYS for key in condition)
+
+
+def _conditions_need_fix(conditions):
+ if not isinstance(conditions, list):
+ return True
+ return not all(_condition_is_clean(condition) for condition in conditions)
+
+
+def _normalize_condition(condition):
+ if not isinstance(condition, dict):
+ return {"id": str(uuid4()), "rollout_percentage": 0, "properties": []}
+
+ condition_id = condition.get("id")
+ condition_id = condition_id if isinstance(condition_id, str) and condition_id else str(uuid4())
+
+ rollout = condition.get("rollout_percentage")
+ # Default a missing/invalid rollout to 0 (not 100) so a previously-dormant eval stays
+ # dormant — these rows were never firing, and 100 would silently start them at full volume.
+ if isinstance(rollout, bool) or not isinstance(rollout, (int, float)):
+ rollout = 0
+
+ raw_properties = condition.get("properties")
+ properties = [p for p in raw_properties if isinstance(p, dict)] if isinstance(raw_properties, list) else []
+ # Fold a property filter that leaked to the condition's top level back into `properties`.
+ leaked_filter = {key: condition[key] for key in _PROPERTY_FILTER_KEYS if key in condition}
+ if leaked_filter:
+ properties.append(leaked_filter)
+
+ normalized = {"id": condition_id, "rollout_percentage": rollout, "properties": properties}
+
+ # Keep compiled filter bytecode only when `properties` is untouched; if we changed it,
+ # drop the now-stale bytecode so the next save() recompiles it.
+ if not leaked_filter and properties == raw_properties:
+ for key in ("bytecode", "bytecode_error"):
+ if key in condition:
+ normalized[key] = condition[key]
+
+ return normalized
+
+
+def normalize_evaluation_conditions(apps, schema_editor):
+ Evaluation = apps.get_model("ai_observability", "Evaluation")
+
+ batch_size = 500
+ updates = []
+ for evaluation in Evaluation.objects.all().iterator(chunk_size=batch_size):
+ conditions = evaluation.conditions
+ if not _conditions_need_fix(conditions):
+ continue
+ source = conditions if isinstance(conditions, list) else []
+ evaluation.conditions = [_normalize_condition(condition) for condition in source]
+ updates.append(evaluation)
+ if len(updates) >= batch_size:
+ # bulk_update (not save) so the post_save reload-workers signal does not fire per row.
+ Evaluation.objects.bulk_update(updates, ["conditions"], batch_size=batch_size)
+ updates = []
+
+ if updates:
+ Evaluation.objects.bulk_update(updates, ["conditions"], batch_size=batch_size)
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("ai_observability", "0002_migrate_ai_observability_models"),
+ ]
+
+ operations = [
+ migrations.RunPython(normalize_evaluation_conditions, migrations.RunPython.noop, elidable=True),
+ ]
diff --git a/products/ai_observability/backend/migrations/max_migration.txt b/products/ai_observability/backend/migrations/max_migration.txt
index 0c8ab2cf305c..e5f46d276434 100644
--- a/products/ai_observability/backend/migrations/max_migration.txt
+++ b/products/ai_observability/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0002_migrate_ai_observability_models
+0003_normalize_evaluation_conditions
diff --git a/products/ai_observability/backend/test/test_normalize_evaluation_conditions.py b/products/ai_observability/backend/test/test_normalize_evaluation_conditions.py
new file mode 100644
index 000000000000..047d23e1f452
--- /dev/null
+++ b/products/ai_observability/backend/test/test_normalize_evaluation_conditions.py
@@ -0,0 +1,114 @@
+import importlib
+
+from parameterized import parameterized
+
+_migration = importlib.import_module(
+ "products.ai_observability.backend.migrations.0003_normalize_evaluation_conditions"
+)
+_normalize_condition = _migration._normalize_condition
+_conditions_need_fix = _migration._conditions_need_fix
+
+
+class TestNormalizeEvaluationConditions:
+ def test_drops_stray_keys_and_defaults_missing_rollout_to_zero(self):
+ result = _normalize_condition({"id": "cond-1", "sampling_rate": 50, "properties": []})
+ assert result == {"id": "cond-1", "rollout_percentage": 0, "properties": []}
+
+ def test_backfills_missing_id(self):
+ result = _normalize_condition({"rollout_percentage": 100, "properties": []})
+ assert isinstance(result["id"], str) and result["id"]
+ assert result["rollout_percentage"] == 100
+ assert result["properties"] == []
+
+ def test_folds_top_level_property_filter_into_properties(self):
+ result = _normalize_condition(
+ {"id": "c1", "key": "$ai_model", "value": "gpt-4", "operator": "exact", "type": "event"}
+ )
+ assert result["id"] == "c1"
+ assert result["rollout_percentage"] == 0
+ assert result["properties"] == [{"key": "$ai_model", "value": "gpt-4", "operator": "exact", "type": "event"}]
+
+ def test_folds_top_level_filter_after_existing_properties(self):
+ result = _normalize_condition(
+ {"id": "c1", "rollout_percentage": 25, "properties": [{"key": "a"}], "key": "b", "operator": "exact"}
+ )
+ assert result["properties"] == [{"key": "a"}, {"key": "b", "operator": "exact"}]
+ assert result["rollout_percentage"] == 25
+
+ def test_normalizes_bool_rollout_to_zero(self):
+ assert (
+ _normalize_condition({"id": "c1", "rollout_percentage": True, "properties": []})["rollout_percentage"] == 0
+ )
+
+ def test_drops_non_dict_property_members(self):
+ result = _normalize_condition({"id": "c1", "rollout_percentage": 0, "properties": ["garbage", {"key": "k"}]})
+ assert result["properties"] == [{"key": "k"}]
+
+ def test_normalized_output_is_idempotent(self):
+ dirty = [{"id": "c1", "sampling_rate": 1, "key": "k", "value": "v"}]
+ once = [_normalize_condition(condition) for condition in dirty]
+ assert _conditions_need_fix(once) is False
+ assert [_normalize_condition(condition) for condition in once] == once
+
+ def test_leaves_already_valid_condition_unchanged(self):
+ condition = {
+ "id": "c1",
+ "rollout_percentage": 50,
+ "properties": [{"key": "x", "value": "y", "operator": "exact", "type": "event"}],
+ }
+ assert _normalize_condition(condition) == condition
+
+ def test_preserves_bytecode_when_properties_unchanged(self):
+ condition = {
+ "id": "c1",
+ "sampling_rate": 10,
+ "properties": [{"key": "x", "value": "y", "operator": "exact", "type": "event"}],
+ "bytecode": ["_H", 1],
+ "bytecode_error": None,
+ }
+ result = _normalize_condition(condition)
+ assert result["bytecode"] == ["_H", 1]
+ assert result["bytecode_error"] is None
+ assert "sampling_rate" not in result
+ assert result["rollout_percentage"] == 0
+
+ def test_drops_stale_bytecode_when_folding_changes_properties(self):
+ result = _normalize_condition(
+ {"id": "c1", "key": "x", "value": "y", "operator": "exact", "type": "event", "bytecode": ["_H", 1]}
+ )
+ assert "bytecode" not in result
+ assert result["properties"] == [{"key": "x", "value": "y", "operator": "exact", "type": "event"}]
+
+ def test_handles_non_dict_condition(self):
+ result = _normalize_condition("garbage")
+ assert isinstance(result["id"], str) and result["id"]
+ assert result["rollout_percentage"] == 0
+ assert result["properties"] == []
+
+ @parameterized.expand(
+ [
+ ("stray_key", [{"id": "c1", "sampling_rate": 1, "properties": []}]),
+ ("missing_id", [{"rollout_percentage": 100, "properties": []}]),
+ ("leaked_filter_key", [{"id": "c1", "key": "x"}]),
+ ("missing_rollout", [{"id": "c1", "properties": []}]),
+ ("bool_rollout", [{"id": "c1", "rollout_percentage": True, "properties": []}]),
+ ("non_dict_property_member", [{"id": "c1", "rollout_percentage": 0, "properties": ["garbage"]}]),
+ ("not_a_list", "not a list"),
+ ("non_dict_member", ["garbage"]),
+ ]
+ )
+ def test_conditions_need_fix_true(self, _name, conditions):
+ assert _conditions_need_fix(conditions) is True
+
+ @parameterized.expand(
+ [
+ ("empty", []),
+ ("canonical", [{"id": "c1", "rollout_percentage": 100, "properties": []}]),
+ (
+ "canonical_with_bytecode",
+ [{"id": "c1", "rollout_percentage": 50, "properties": [], "bytecode": ["_H"], "bytecode_error": None}],
+ ),
+ ]
+ )
+ def test_conditions_need_fix_false(self, _name, conditions):
+ assert _conditions_need_fix(conditions) is False
diff --git a/products/ai_observability/frontend/generated/api.schemas.ts b/products/ai_observability/frontend/generated/api.schemas.ts
index 846268b9e789..04ad4654aa0a 100644
--- a/products/ai_observability/frontend/generated/api.schemas.ts
+++ b/products/ai_observability/frontend/generated/api.schemas.ts
@@ -358,6 +358,27 @@ export const OutputTypeEnumApi = {
Boolean: 'boolean',
} as const
+export type EvaluationConditionApiPropertiesItem = { [key: string]: unknown }
+
+/**
+ * A trigger condition set controlling which generations an evaluation runs on.
+ */
+export interface EvaluationConditionApi {
+ /**
+ * Stable identifier for this condition set.
+ * @maxLength 100
+ */
+ id: string
+ /**
+ * Percentage (0-100) of matching events to sample for this evaluation. Defaults to 100.
+ * @minimum 0
+ * @maximum 100
+ */
+ rollout_percentage?: number
+ /** Property filters (event or person) that scope which generations match this condition set. */
+ properties?: EvaluationConditionApiPropertiesItem[]
+}
+
/**
* * `openai` - Openai
* `anthropic` - Anthropic
@@ -445,8 +466,8 @@ export interface EvaluationApi {
output_type: OutputTypeEnumApi
/** Output config. For 'boolean' output_type: {allows_na} to permit N/A results. */
output_config?: EvaluationApiOutputConfig
- /** Optional trigger conditions to filter which events are evaluated. OR between condition sets, AND within each. */
- conditions?: unknown
+ /** Trigger conditions that filter which events are evaluated. OR between condition sets, AND within each. Each set is {id, rollout_percentage, properties[]} — `rollout_percentage` (0-100, defaults to 100) is the sampling field the dispatcher reads. */
+ conditions?: EvaluationConditionApi[]
model_configuration?: ModelConfigurationApi | null
readonly created_at: string
readonly updated_at: string
@@ -517,8 +538,8 @@ export interface PatchedEvaluationApi {
output_type?: OutputTypeEnumApi
/** Output config. For 'boolean' output_type: {allows_na} to permit N/A results. */
output_config?: PatchedEvaluationApiOutputConfig
- /** Optional trigger conditions to filter which events are evaluated. OR between condition sets, AND within each. */
- conditions?: unknown
+ /** Trigger conditions that filter which events are evaluated. OR between condition sets, AND within each. Each set is {id, rollout_percentage, properties[]} — `rollout_percentage` (0-100, defaults to 100) is the sampling field the dispatcher reads. */
+ conditions?: EvaluationConditionApi[]
model_configuration?: ModelConfigurationApi | null
readonly created_at?: string
readonly updated_at?: string
diff --git a/products/ai_observability/frontend/generated/api.zod.ts b/products/ai_observability/frontend/generated/api.zod.ts
index 73a97ae38d87..525dac9f1459 100644
--- a/products/ai_observability/frontend/generated/api.zod.ts
+++ b/products/ai_observability/frontend/generated/api.zod.ts
@@ -105,6 +105,12 @@ export const EvaluationRunsCreateBody = /* @__PURE__ */ zod.object({
export const evaluationsCreateBodyNameMax = 400
export const evaluationsCreateBodyOutputConfigAllowsNaDefault = false
+export const evaluationsCreateBodyConditionsItemIdMax = 100
+
+export const evaluationsCreateBodyConditionsItemRolloutPercentageDefault = 100
+export const evaluationsCreateBodyConditionsItemRolloutPercentageMin = 0
+export const evaluationsCreateBodyConditionsItemRolloutPercentageMax = 100
+
export const evaluationsCreateBodyModelConfigurationOneModelMax = 100
export const EvaluationsCreateBody = /* @__PURE__ */ zod.object({
@@ -151,10 +157,33 @@ export const EvaluationsCreateBody = /* @__PURE__ */ zod.object({
.optional()
.describe("Output config. For 'boolean' output_type: {allows_na} to permit N\/A results."),
conditions: zod
- .unknown()
+ .array(
+ zod
+ .object({
+ id: zod
+ .string()
+ .max(evaluationsCreateBodyConditionsItemIdMax)
+ .describe('Stable identifier for this condition set.'),
+ rollout_percentage: zod
+ .number()
+ .min(evaluationsCreateBodyConditionsItemRolloutPercentageMin)
+ .max(evaluationsCreateBodyConditionsItemRolloutPercentageMax)
+ .default(evaluationsCreateBodyConditionsItemRolloutPercentageDefault)
+ .describe(
+ 'Percentage (0-100) of matching events to sample for this evaluation. Defaults to 100.'
+ ),
+ properties: zod
+ .array(zod.record(zod.string(), zod.unknown()))
+ .optional()
+ .describe(
+ 'Property filters (event or person) that scope which generations match this condition set.'
+ ),
+ })
+ .describe('A trigger condition set controlling which generations an evaluation runs on.')
+ )
.optional()
.describe(
- 'Optional trigger conditions to filter which events are evaluated. OR between condition sets, AND within each.'
+ 'Trigger conditions that filter which events are evaluated. OR between condition sets, AND within each. Each set is {id, rollout_percentage, properties[]} — `rollout_percentage` (0-100, defaults to 100) is the sampling field the dispatcher reads.'
),
model_configuration: zod
.union([
@@ -187,6 +216,12 @@ export const EvaluationsCreateBody = /* @__PURE__ */ zod.object({
export const evaluationsUpdateBodyNameMax = 400
export const evaluationsUpdateBodyOutputConfigAllowsNaDefault = false
+export const evaluationsUpdateBodyConditionsItemIdMax = 100
+
+export const evaluationsUpdateBodyConditionsItemRolloutPercentageDefault = 100
+export const evaluationsUpdateBodyConditionsItemRolloutPercentageMin = 0
+export const evaluationsUpdateBodyConditionsItemRolloutPercentageMax = 100
+
export const evaluationsUpdateBodyModelConfigurationOneModelMax = 100
export const EvaluationsUpdateBody = /* @__PURE__ */ zod.object({
@@ -233,10 +268,33 @@ export const EvaluationsUpdateBody = /* @__PURE__ */ zod.object({
.optional()
.describe("Output config. For 'boolean' output_type: {allows_na} to permit N\/A results."),
conditions: zod
- .unknown()
+ .array(
+ zod
+ .object({
+ id: zod
+ .string()
+ .max(evaluationsUpdateBodyConditionsItemIdMax)
+ .describe('Stable identifier for this condition set.'),
+ rollout_percentage: zod
+ .number()
+ .min(evaluationsUpdateBodyConditionsItemRolloutPercentageMin)
+ .max(evaluationsUpdateBodyConditionsItemRolloutPercentageMax)
+ .default(evaluationsUpdateBodyConditionsItemRolloutPercentageDefault)
+ .describe(
+ 'Percentage (0-100) of matching events to sample for this evaluation. Defaults to 100.'
+ ),
+ properties: zod
+ .array(zod.record(zod.string(), zod.unknown()))
+ .optional()
+ .describe(
+ 'Property filters (event or person) that scope which generations match this condition set.'
+ ),
+ })
+ .describe('A trigger condition set controlling which generations an evaluation runs on.')
+ )
.optional()
.describe(
- 'Optional trigger conditions to filter which events are evaluated. OR between condition sets, AND within each.'
+ 'Trigger conditions that filter which events are evaluated. OR between condition sets, AND within each. Each set is {id, rollout_percentage, properties[]} — `rollout_percentage` (0-100, defaults to 100) is the sampling field the dispatcher reads.'
),
model_configuration: zod
.union([
@@ -269,6 +327,12 @@ export const EvaluationsUpdateBody = /* @__PURE__ */ zod.object({
export const evaluationsPartialUpdateBodyNameMax = 400
export const evaluationsPartialUpdateBodyOutputConfigAllowsNaDefault = false
+export const evaluationsPartialUpdateBodyConditionsItemIdMax = 100
+
+export const evaluationsPartialUpdateBodyConditionsItemRolloutPercentageDefault = 100
+export const evaluationsPartialUpdateBodyConditionsItemRolloutPercentageMin = 0
+export const evaluationsPartialUpdateBodyConditionsItemRolloutPercentageMax = 100
+
export const evaluationsPartialUpdateBodyModelConfigurationOneModelMax = 100
export const EvaluationsPartialUpdateBody = /* @__PURE__ */ zod.object({
@@ -317,10 +381,33 @@ export const EvaluationsPartialUpdateBody = /* @__PURE__ */ zod.object({
.optional()
.describe("Output config. For 'boolean' output_type: {allows_na} to permit N\/A results."),
conditions: zod
- .unknown()
+ .array(
+ zod
+ .object({
+ id: zod
+ .string()
+ .max(evaluationsPartialUpdateBodyConditionsItemIdMax)
+ .describe('Stable identifier for this condition set.'),
+ rollout_percentage: zod
+ .number()
+ .min(evaluationsPartialUpdateBodyConditionsItemRolloutPercentageMin)
+ .max(evaluationsPartialUpdateBodyConditionsItemRolloutPercentageMax)
+ .default(evaluationsPartialUpdateBodyConditionsItemRolloutPercentageDefault)
+ .describe(
+ 'Percentage (0-100) of matching events to sample for this evaluation. Defaults to 100.'
+ ),
+ properties: zod
+ .array(zod.record(zod.string(), zod.unknown()))
+ .optional()
+ .describe(
+ 'Property filters (event or person) that scope which generations match this condition set.'
+ ),
+ })
+ .describe('A trigger condition set controlling which generations an evaluation runs on.')
+ )
.optional()
.describe(
- 'Optional trigger conditions to filter which events are evaluated. OR between condition sets, AND within each.'
+ 'Trigger conditions that filter which events are evaluated. OR between condition sets, AND within each. Each set is {id, rollout_percentage, properties[]} — `rollout_percentage` (0-100, defaults to 100) is the sampling field the dispatcher reads.'
),
model_configuration: zod
.union([
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 0e6ae2c98469..b30c3204b97f 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -15656,6 +15656,27 @@ export namespace Schemas {
Boolean: 'boolean',
} as const;
+ export type EvaluationConditionPropertiesItem = { [key: string]: unknown };
+
+ /**
+ * A trigger condition set controlling which generations an evaluation runs on.
+ */
+ export interface EvaluationCondition {
+ /**
+ * Stable identifier for this condition set.
+ * @maxLength 100
+ */
+ id: string;
+ /**
+ * Percentage (0-100) of matching events to sample for this evaluation. Defaults to 100.
+ * @minimum 0
+ * @maximum 100
+ */
+ rollout_percentage?: number;
+ /** Property filters (event or person) that scope which generations match this condition set. */
+ properties?: EvaluationConditionPropertiesItem[];
+ }
+
/**
* * `openai` - Openai
* `anthropic` - Anthropic
@@ -15717,8 +15738,8 @@ export namespace Schemas {
output_type: OutputTypeEnum;
/** Output config. For 'boolean' output_type: {allows_na} to permit N/A results. */
output_config?: EvaluationOutputConfig;
- /** Optional trigger conditions to filter which events are evaluated. OR between condition sets, AND within each. */
- conditions?: unknown;
+ /** Trigger conditions that filter which events are evaluated. OR between condition sets, AND within each. Each set is {id, rollout_percentage, properties[]} — `rollout_percentage` (0-100, defaults to 100) is the sampling field the dispatcher reads. */
+ conditions?: EvaluationCondition[];
model_configuration?: ModelConfiguration | null;
readonly created_at: string;
readonly updated_at: string;
@@ -28280,8 +28301,8 @@ export namespace Schemas {
output_type?: OutputTypeEnum;
/** Output config. For 'boolean' output_type: {allows_na} to permit N/A results. */
output_config?: PatchedEvaluationOutputConfig;
- /** Optional trigger conditions to filter which events are evaluated. OR between condition sets, AND within each. */
- conditions?: unknown;
+ /** Trigger conditions that filter which events are evaluated. OR between condition sets, AND within each. Each set is {id, rollout_percentage, properties[]} — `rollout_percentage` (0-100, defaults to 100) is the sampling field the dispatcher reads. */
+ conditions?: EvaluationCondition[];
model_configuration?: ModelConfiguration | null;
readonly created_at?: string;
readonly updated_at?: string;
diff --git a/services/mcp/src/generated/ai_observability/api.ts b/services/mcp/src/generated/ai_observability/api.ts
index 76fc80d30467..a30cf8753fc6 100644
--- a/services/mcp/src/generated/ai_observability/api.ts
+++ b/services/mcp/src/generated/ai_observability/api.ts
@@ -120,6 +120,12 @@ export const EvaluationsCreateParams = /* @__PURE__ */ zod.object({
export const evaluationsCreateBodyNameMax = 400
export const evaluationsCreateBodyOutputConfigAllowsNaDefault = false
+export const evaluationsCreateBodyConditionsItemIdMax = 100
+
+export const evaluationsCreateBodyConditionsItemRolloutPercentageDefault = 100
+export const evaluationsCreateBodyConditionsItemRolloutPercentageMin = 0
+export const evaluationsCreateBodyConditionsItemRolloutPercentageMax = 100
+
export const evaluationsCreateBodyModelConfigurationOneModelMax = 100
export const EvaluationsCreateBody = /* @__PURE__ */ zod.object({
@@ -166,10 +172,33 @@ export const EvaluationsCreateBody = /* @__PURE__ */ zod.object({
.optional()
.describe("Output config. For 'boolean' output_type: {allows_na} to permit N/A results."),
conditions: zod
- .unknown()
+ .array(
+ zod
+ .object({
+ id: zod
+ .string()
+ .max(evaluationsCreateBodyConditionsItemIdMax)
+ .describe('Stable identifier for this condition set.'),
+ rollout_percentage: zod
+ .number()
+ .min(evaluationsCreateBodyConditionsItemRolloutPercentageMin)
+ .max(evaluationsCreateBodyConditionsItemRolloutPercentageMax)
+ .default(evaluationsCreateBodyConditionsItemRolloutPercentageDefault)
+ .describe(
+ 'Percentage (0-100) of matching events to sample for this evaluation. Defaults to 100.'
+ ),
+ properties: zod
+ .array(zod.record(zod.string(), zod.unknown()))
+ .optional()
+ .describe(
+ 'Property filters (event or person) that scope which generations match this condition set.'
+ ),
+ })
+ .describe('A trigger condition set controlling which generations an evaluation runs on.')
+ )
.optional()
.describe(
- 'Optional trigger conditions to filter which events are evaluated. OR between condition sets, AND within each.'
+ 'Trigger conditions that filter which events are evaluated. OR between condition sets, AND within each. Each set is {id, rollout_percentage, properties[]} — `rollout_percentage` (0-100, defaults to 100) is the sampling field the dispatcher reads.'
),
model_configuration: zod
.union([
@@ -220,6 +249,12 @@ export const EvaluationsPartialUpdateParams = /* @__PURE__ */ zod.object({
export const evaluationsPartialUpdateBodyNameMax = 400
export const evaluationsPartialUpdateBodyOutputConfigAllowsNaDefault = false
+export const evaluationsPartialUpdateBodyConditionsItemIdMax = 100
+
+export const evaluationsPartialUpdateBodyConditionsItemRolloutPercentageDefault = 100
+export const evaluationsPartialUpdateBodyConditionsItemRolloutPercentageMin = 0
+export const evaluationsPartialUpdateBodyConditionsItemRolloutPercentageMax = 100
+
export const evaluationsPartialUpdateBodyModelConfigurationOneModelMax = 100
export const EvaluationsPartialUpdateBody = /* @__PURE__ */ zod.object({
@@ -268,10 +303,33 @@ export const EvaluationsPartialUpdateBody = /* @__PURE__ */ zod.object({
.optional()
.describe("Output config. For 'boolean' output_type: {allows_na} to permit N/A results."),
conditions: zod
- .unknown()
+ .array(
+ zod
+ .object({
+ id: zod
+ .string()
+ .max(evaluationsPartialUpdateBodyConditionsItemIdMax)
+ .describe('Stable identifier for this condition set.'),
+ rollout_percentage: zod
+ .number()
+ .min(evaluationsPartialUpdateBodyConditionsItemRolloutPercentageMin)
+ .max(evaluationsPartialUpdateBodyConditionsItemRolloutPercentageMax)
+ .default(evaluationsPartialUpdateBodyConditionsItemRolloutPercentageDefault)
+ .describe(
+ 'Percentage (0-100) of matching events to sample for this evaluation. Defaults to 100.'
+ ),
+ properties: zod
+ .array(zod.record(zod.string(), zod.unknown()))
+ .optional()
+ .describe(
+ 'Property filters (event or person) that scope which generations match this condition set.'
+ ),
+ })
+ .describe('A trigger condition set controlling which generations an evaluation runs on.')
+ )
.optional()
.describe(
- 'Optional trigger conditions to filter which events are evaluated. OR between condition sets, AND within each.'
+ 'Trigger conditions that filter which events are evaluated. OR between condition sets, AND within each. Each set is {id, rollout_percentage, properties[]} — `rollout_percentage` (0-100, defaults to 100) is the sampling field the dispatcher reads.'
),
model_configuration: zod
.union([
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-evaluation-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-evaluation-create.json
index 15d1e1e296b2..b9a25fc5c766 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-evaluation-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-evaluation-create.json
@@ -2,7 +2,38 @@
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"conditions": {
- "description": "Optional trigger conditions to filter which events are evaluated. OR between condition sets, AND within each."
+ "description": "Trigger conditions that filter which events are evaluated. OR between condition sets, AND within each. Each set is {id, rollout_percentage, properties[]} — `rollout_percentage` (0-100, defaults to 100) is the sampling field the dispatcher reads.",
+ "items": {
+ "description": "A trigger condition set controlling which generations an evaluation runs on.",
+ "properties": {
+ "id": {
+ "description": "Stable identifier for this condition set.",
+ "maxLength": 100,
+ "type": "string"
+ },
+ "properties": {
+ "description": "Property filters (event or person) that scope which generations match this condition set.",
+ "items": {
+ "additionalProperties": {},
+ "propertyNames": {
+ "type": "string"
+ },
+ "type": "object"
+ },
+ "type": "array"
+ },
+ "rollout_percentage": {
+ "default": 100,
+ "description": "Percentage (0-100) of matching events to sample for this evaluation. Defaults to 100.",
+ "maximum": 100,
+ "minimum": 0,
+ "type": "number"
+ }
+ },
+ "required": ["id"],
+ "type": "object"
+ },
+ "type": "array"
},
"deleted": {
"description": "Set to true to soft-delete the evaluation.",
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-evaluation-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-evaluation-update.json
index f39bb18c7242..9720e4518f33 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-evaluation-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-evaluation-update.json
@@ -2,7 +2,38 @@
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"conditions": {
- "description": "Optional trigger conditions to filter which events are evaluated. OR between condition sets, AND within each."
+ "description": "Trigger conditions that filter which events are evaluated. OR between condition sets, AND within each. Each set is {id, rollout_percentage, properties[]} — `rollout_percentage` (0-100, defaults to 100) is the sampling field the dispatcher reads.",
+ "items": {
+ "description": "A trigger condition set controlling which generations an evaluation runs on.",
+ "properties": {
+ "id": {
+ "description": "Stable identifier for this condition set.",
+ "maxLength": 100,
+ "type": "string"
+ },
+ "properties": {
+ "description": "Property filters (event or person) that scope which generations match this condition set.",
+ "items": {
+ "additionalProperties": {},
+ "propertyNames": {
+ "type": "string"
+ },
+ "type": "object"
+ },
+ "type": "array"
+ },
+ "rollout_percentage": {
+ "default": 100,
+ "description": "Percentage (0-100) of matching events to sample for this evaluation. Defaults to 100.",
+ "maximum": 100,
+ "minimum": 0,
+ "type": "number"
+ }
+ },
+ "required": ["id"],
+ "type": "object"
+ },
+ "type": "array"
},
"deleted": {
"description": "Set to true to soft-delete the evaluation.",