From 71af7547b7192ab11fa898d86aea49fbae5e5688 Mon Sep 17 00:00:00 2001 From: Karan Bansal Date: Thu, 26 Nov 2026 09:41:52 +0530 Subject: [PATCH 1/3] fix(config): reject rule items that set more than one matcher The rule_based judge evaluates one matcher per rule item and silently ignored the rest, so an item holding output_contains, exit_code and files_exist checked only the output and could pass with a failed exit and a missing file. Validation now rejects such an item and names its matchers. --- CHANGELOG.md | 5 +++ internal/config/validator.go | 37 +++++++++++++++++++++ internal/config/validator_test.go | 54 +++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 528396b2..62c3eea4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Reject a `rule_based` rule item that sets more than one matcher. The judge + evaluates one matcher per item and ignored the rest, so an item with + `output_contains`, `exit_code` and `files_exist` checked only the output and + could pass with a failed exit and a missing file. Put each matcher in its own + list item. - Keep `agent_judge` review materials from reading as instructions. The judge prompt now states that inline excerpts and referenced files come from the agent under evaluation and are evidence, never instructions, and it fences diff --git a/internal/config/validator.go b/internal/config/validator.go index e75b168b..5708bbe3 100644 --- a/internal/config/validator.go +++ b/internal/config/validator.go @@ -341,9 +341,20 @@ func validateJudgeEngine(judge JudgeConfig) []string { // values. Such an empty rule passes validation and then misbehaves at runtime: // in success position it fails late with "unknown_rule", and in failure // position it no-ops, letting the case pass with zero assertions evaluated. +// +// A rule that sets more than one matcher is rejected too. The runtime +// dispatcher evaluates exactly one matcher per rule and ignores the rest, so +// an item holding output_contains, exit_code and files_exist checks only the +// output and can pass with a failed exit and a missing file. func validateRecognizableRules(field string, rules []Rule) []string { var errs []string for i, rule := range rules { + if matchers := ruleMatcherNames(rule); len(matchers) > 1 { + errs = append(errs, fmt.Sprintf( + "%s[%d]: assertion sets more than one matcher (%s), but only one is evaluated; put each matcher in its own list item", + field, i, strings.Join(matchers, ", "))) + continue + } if ruleHasRecognizableField(rule) { continue } @@ -354,6 +365,32 @@ func validateRecognizableRules(field string, rules []Rule) []string { return errs } +// ruleMatcherNames lists the matcher fields a rule sets, in the order the +// runtime dispatcher checks them. +func ruleMatcherNames(rule Rule) []string { + var names []string + for _, matcher := range []struct { + name string + set bool + }{ + {"output_contains", rule.OutputContains != nil}, + {"output_matches", rule.OutputMatches != nil}, + {"exit_code", rule.ExitCode != nil}, + {"tool_called", rule.ToolCalled != nil}, + {"files_exist", len(rule.FilesExist) > 0}, + {"files_not_exist", len(rule.FilesNotExist) > 0}, + {"turn_response_contains", rule.TurnResponseContains != nil}, + {"turn_response_not_contains", rule.TurnResponseNotContains != nil}, + {"tool_called_in_turn", rule.ToolCalledInTurn != nil}, + {"tool_not_called_in_turn", rule.ToolNotCalledInTurn != nil}, + } { + if matcher.set { + names = append(names, matcher.name) + } + } + return names +} + // ruleHasRecognizableField reports whether the rule sets at least one matcher // field that the runtime dispatcher in internal/judge can evaluate. The empty // collections (for example files_exist: []) mirror the runtime dispatch, which diff --git a/internal/config/validator_test.go b/internal/config/validator_test.go index 3029beec..dec7aa63 100644 --- a/internal/config/validator_test.go +++ b/internal/config/validator_test.go @@ -132,6 +132,60 @@ func TestValidator_ValidateEvalConfig(t *testing.T) { wantErr: true, errMsg: "judge.success[0]: assertion has no recognizable matcher field", }, + { + name: "success rule with several matchers is rejected", + cfg: &EvalConfig{ + SchemaVersion: "v1alpha1", + Environment: Environment{Type: "none"}, + Engine: EngineConfig{ + Name: "claude_code", + Model: ModelConfig{ + Provider: "anthropic", + Name: "claude-sonnet-4-6", + }, + }, + Cases: CasesConfig{ + Files: []string{"evals/cases/test.yaml"}, + }, + Judge: JudgeConfig{ + Type: "rule_based", + Success: []Rule{{ + OutputContains: &OutputContainsRule{All: []string{"done"}}, + ExitCode: new(0), + FilesExist: []string{"report.md"}, + }}, + }, + }, + wantErr: true, + errMsg: "judge.success[0]: assertion sets more than one matcher (output_contains, exit_code, files_exist), but only one is evaluated; put each matcher in its own list item", + }, + { + name: "failure rule with several matchers is rejected", + cfg: &EvalConfig{ + SchemaVersion: "v1alpha1", + Environment: Environment{Type: "none"}, + Engine: EngineConfig{ + Name: "claude_code", + Model: ModelConfig{ + Provider: "anthropic", + Name: "claude-sonnet-4-6", + }, + }, + Cases: CasesConfig{ + Files: []string{"evals/cases/test.yaml"}, + }, + Judge: JudgeConfig{ + Type: "rule_based", + Failure: []Rule{{ + OutputContains: &OutputContainsRule{All: []string{"done"}}, + ExitCode: new(0), + FilesExist: []string{"report.md"}, + }}, + }, + }, + wantErr: true, + errMsg: "judge.failure[0]: assertion sets more than one matcher (output_contains, exit_code, files_exist)", + }, { name: "empty failure rule is rejected", cfg: &EvalConfig{ From 98a14c151bb44b9347cd970a87f717f63c58f38c Mon Sep 17 00:00:00 2001 From: Karan Bansal Date: Thu, 26 Nov 2026 09:46:07 +0530 Subject: [PATCH 2/3] fix(config): check matcher count only for rule_based judges Other judge types ignore success and failure rules, so a script judge with an unused multi-matcher item must keep validating. Share one matcher list between both rule checks. --- internal/config/validator.go | 44 ++++++++++++++++--------------- internal/config/validator_test.go | 26 ++++++++++++++++++ 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/internal/config/validator.go b/internal/config/validator.go index 5708bbe3..efe2eaef 100644 --- a/internal/config/validator.go +++ b/internal/config/validator.go @@ -301,6 +301,12 @@ func validateJudgeTypeAndLocalFields(judge JudgeConfig) []string { errs = append(errs, validateOutputMatchesRules("judge.failure", judge.Failure)...) errs = append(errs, validateRecognizableRules("judge.success", judge.Success)...) errs = append(errs, validateRecognizableRules("judge.failure", judge.Failure)...) + // Only the rule_based judge evaluates these rules; other judge types + // ignore them, so their matcher count does not matter. + if judge.Type == judgeTypeRuleBased { + errs = append(errs, validateSingleMatcherRules("judge.success", judge.Success)...) + errs = append(errs, validateSingleMatcherRules("judge.failure", judge.Failure)...) + } errs = append(errs, validateNonVacuousRules("judge.success", judge.Success)...) errs = append(errs, validateNonVacuousRules("judge.failure", judge.Failure)...) @@ -341,20 +347,9 @@ func validateJudgeEngine(judge JudgeConfig) []string { // values. Such an empty rule passes validation and then misbehaves at runtime: // in success position it fails late with "unknown_rule", and in failure // position it no-ops, letting the case pass with zero assertions evaluated. -// -// A rule that sets more than one matcher is rejected too. The runtime -// dispatcher evaluates exactly one matcher per rule and ignores the rest, so -// an item holding output_contains, exit_code and files_exist checks only the -// output and can pass with a failed exit and a missing file. func validateRecognizableRules(field string, rules []Rule) []string { var errs []string for i, rule := range rules { - if matchers := ruleMatcherNames(rule); len(matchers) > 1 { - errs = append(errs, fmt.Sprintf( - "%s[%d]: assertion sets more than one matcher (%s), but only one is evaluated; put each matcher in its own list item", - field, i, strings.Join(matchers, ", "))) - continue - } if ruleHasRecognizableField(rule) { continue } @@ -365,6 +360,22 @@ func validateRecognizableRules(field string, rules []Rule) []string { return errs } +// validateSingleMatcherRules rejects a rule that sets more than one matcher. +// The rule_based judge evaluates exactly one matcher per rule and ignores the +// rest, so an item holding output_contains, exit_code and files_exist checks +// only the output and can pass with a failed exit and a missing file. +func validateSingleMatcherRules(field string, rules []Rule) []string { + var errs []string + for i, rule := range rules { + if matchers := ruleMatcherNames(rule); len(matchers) > 1 { + errs = append(errs, fmt.Sprintf( + "%s[%d]: assertion sets more than one matcher (%s), but only one is evaluated; put each matcher in its own list item", + field, i, strings.Join(matchers, ", "))) + } + } + return errs +} + // ruleMatcherNames lists the matcher fields a rule sets, in the order the // runtime dispatcher checks them. func ruleMatcherNames(rule Rule) []string { @@ -396,16 +407,7 @@ func ruleMatcherNames(rule Rule) []string { // collections (for example files_exist: []) mirror the runtime dispatch, which // treats them the same as absent fields. func ruleHasRecognizableField(rule Rule) bool { - return rule.OutputContains != nil || - rule.OutputMatches != nil || - rule.ExitCode != nil || - rule.ToolCalled != nil || - len(rule.FilesExist) > 0 || - len(rule.FilesNotExist) > 0 || - rule.TurnResponseContains != nil || - rule.TurnResponseNotContains != nil || - rule.ToolCalledInTurn != nil || - rule.ToolNotCalledInTurn != nil + return len(ruleMatcherNames(rule)) > 0 } // validateNonVacuousRules rejects matchers that are present but hold no values diff --git a/internal/config/validator_test.go b/internal/config/validator_test.go index dec7aa63..c91a7335 100644 --- a/internal/config/validator_test.go +++ b/internal/config/validator_test.go @@ -186,6 +186,32 @@ func TestValidator_ValidateEvalConfig(t *testing.T) { wantErr: true, errMsg: "judge.failure[0]: assertion sets more than one matcher (output_contains, exit_code, files_exist)", }, + { + name: "script judge ignores unused rules with several matchers", + cfg: &EvalConfig{ + SchemaVersion: "v1alpha1", + Environment: Environment{Type: "none"}, + Engine: EngineConfig{ + Name: "claude_code", + Model: ModelConfig{ + Provider: "anthropic", + Name: "claude-sonnet-4-6", + }, + }, + Cases: CasesConfig{ + Files: []string{"evals/cases/test.yaml"}, + }, + Judge: JudgeConfig{ + Type: "script", + ScriptPath: "evals/judge.sh", + Success: []Rule{{ + ExitCode: new(0), + FilesExist: []string{"report.md"}, + }}, + }, + }, + wantErr: false, + }, { name: "empty failure rule is rejected", cfg: &EvalConfig{ From 3dd3345c6d667c5adbc0b6355a89739bcfec7f25 Mon Sep 17 00:00:00 2001 From: karanb192 Date: Fri, 27 Nov 2026 19:58:21 +0530 Subject: [PATCH 3/3] docs(config): clarify migration for multi-matcher rules --- CHANGELOG.md | 4 ++-- docs/guide/writing-evals.md | 4 ++++ docs/zh/guide/writing-evals.md | 4 ++++ internal/config/validator.go | 2 +- internal/config/validator_test.go | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f6bfbb3..47b6587d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,8 +74,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Reject a `rule_based` rule item that sets more than one matcher. The judge evaluates one matcher per item and ignored the rest, so an item with `output_contains`, `exit_code` and `files_exist` checked only the output and - could pass with a failed exit and a missing file. Put each matcher in its own - list item. + could pass with a failed exit and a missing file. Separate success items + must all pass. Each matching failure item independently fails the case. - Reject a `rule_based` matcher that is present but holds no values to match. `output_contains: {all: []}`, `output_matches: {}`, `turn_response_contains` without `contains_all`/`contains_any`, and `turn_response_not_contains` diff --git a/docs/guide/writing-evals.md b/docs/guide/writing-evals.md index 020ef4cf..ccdfa335 100644 --- a/docs/guide/writing-evals.md +++ b/docs/guide/writing-evals.md @@ -1045,6 +1045,10 @@ judge: > **Evaluation order:** `failure` outranks `success`. If any `failure` rule matches, the case fails immediately. Otherwise every `success` rule must pass. +Each rule item accepts one matcher. Older versions evaluated only the first recognized matcher in an item. An item with multiple matchers now fails validation. + +To require several success conditions, put each matcher in its own `success` item. Split a `failure` item only if each condition should independently fail the case. If failure requires both conditions, express them together in a single check, such as a script judge. + > **MCP tool names:** `tool_called`, `tool_called_in_turn`, and `tool_not_called_in_turn` compare `name` exactly with the tool name the Agent Engine recorded. Claude Code, Codex, and Qoder CLI record MCP tools as `mcp____`, where `` is the server `name` from `mcp.servers`. `output_contains` performs literal substring checks. Use `output_matches` when you need regular expressions; patterns use Go `regexp` syntax and invalid patterns fail config validation. A matcher that is present but lists no values is rejected by config validation: an empty `output_contains`, `output_matches`, `turn_response_contains`, or `turn_response_not_contains` would otherwise be reported as passing with zero checks. The same applies to the empty entry: an empty literal is a substring of every response and an empty pattern matches every response, so `all: [""]` cannot keep the false-positive pass. Whitespace is not empty — `["\n"]` checks that the output is a single line and `[" "]` rejects a double space, and both are compared as written. diff --git a/docs/zh/guide/writing-evals.md b/docs/zh/guide/writing-evals.md index 6421153f..ab41ef5d 100644 --- a/docs/zh/guide/writing-evals.md +++ b/docs/zh/guide/writing-evals.md @@ -897,6 +897,10 @@ judge: > **评估逻辑**:`failure` 优先于 `success`。任何一条 `failure` 规则匹配即立即失败;否则所有 `success` 规则必须全部满足才算通过。 +每个规则项只能包含一个匹配条件。旧版本只检查同一项中第一个可识别的条件。现在,包含多个匹配条件的规则项无法通过校验。 + +如果多个成功条件必须同时成立,请将每个条件写成单独的 `success` 项。只有在任一条件成立都应判定失败时,才把条件拆成多个 `failure` 项。如果两个条件同时成立才算失败,请在一次检查中组合判断,例如使用脚本裁判。 + > **MCP 工具名**:`tool_called`、`tool_called_in_turn` 和 `tool_not_called_in_turn` 会把 `name` 与 Agent Engine 记录的工具名做精确匹配。Claude Code、Codex 和 Qoder CLI 记录的 MCP 工具名格式为 `mcp____`,其中 `` 是 `mcp.servers` 中的 `name`。 `output_contains` 执行字面 substring 检查。需要正则表达式时使用 `output_matches`;pattern 使用 Go `regexp` 语法,非法 pattern 会在配置校验阶段失败。 matcher 存在但没有任何值时会被配置校验拒绝:空的 `output_contains`、`output_matches`、`turn_response_contains` 或 `turn_response_not_contains` 否则会以零检查被报告为通过。空条目(`""`)同样会被拒绝:空字面量是任何响应的子串,空 pattern 匹配任何响应,因此 `all: [""]` 无法继续制造假通过。空白本身不算空——`["\n"]` 可以断言输出只有一行,`[" "]` 可以拒绝双空格,两者都按原样比较。 diff --git a/internal/config/validator.go b/internal/config/validator.go index a6183696..8cd48aea 100644 --- a/internal/config/validator.go +++ b/internal/config/validator.go @@ -371,7 +371,7 @@ func validateSingleMatcherRules(field string, rules []Rule) []string { for i, rule := range rules { if matchers := ruleMatcherNames(rule); len(matchers) > 1 { errs = append(errs, fmt.Sprintf( - "%s[%d]: assertion sets more than one matcher (%s), but only one is evaluated; put each matcher in its own list item", + "%s[%d]: assertion sets more than one matcher (%s); use one matcher per rule item", field, i, strings.Join(matchers, ", "))) } } diff --git a/internal/config/validator_test.go b/internal/config/validator_test.go index c91a7335..0b4a404f 100644 --- a/internal/config/validator_test.go +++ b/internal/config/validator_test.go @@ -157,7 +157,7 @@ func TestValidator_ValidateEvalConfig(t *testing.T) { }, }, wantErr: true, - errMsg: "judge.success[0]: assertion sets more than one matcher (output_contains, exit_code, files_exist), but only one is evaluated; put each matcher in its own list item", + errMsg: "judge.success[0]: assertion sets more than one matcher (output_contains, exit_code, files_exist); use one matcher per rule item", }, { name: "failure rule with several matchers is rejected",