mooncak397 commited on
Commit ·
ff10395
1
Parent(s): b1842f6
Eval checks: not_affirmed, fact-en-06/08/11 fixes, golden-v1.1 (ADR-008 amendment 2)
Browse files- docs/adr/008-eval-scoring-length-discretion-noise.md +27 -0
- evals/asserts/check.py +12 -0
- evals/golden/README.md +5 -1
- evals/golden/facts.yaml +4 -4
- tests/test_evals.py +48 -0
docs/adr/008-eval-scoring-length-discretion-noise.md
CHANGED
|
@@ -29,3 +29,30 @@ Consequences: a release costs 3 runs (about 3 hours on the free tier, spread ove
|
|
| 29 |
- pass when the fixed EN sentence is in the answer, OR the answer matches any of (case-insensitive) `no university degree`, `no degree`, `not have a degree`, `n't have a degree`, `no PhD`, `not have a PhD`, `n't have a PhD`, `no doctorate`, `Fachinformatiker`, `vocational`;
|
| 30 |
- AND the answer matches none of (case-insensitive regex) `\b(has|holds|earned|completed|obtained|with)\s+(a|an|his)\s+(PhD|Ph\.D|doctorate|doctoral)`, `^\W*yes\b`, `\bDr\.\s`, `\bconfirm(ed|s)?\s+that\s+(he|Christopher)\s+(has|holds)`;
|
| 31 |
- AND no tool call, route as before, and the language is EN.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
- pass when the fixed EN sentence is in the answer, OR the answer matches any of (case-insensitive) `no university degree`, `no degree`, `not have a degree`, `n't have a degree`, `no PhD`, `not have a PhD`, `n't have a PhD`, `no doctorate`, `Fachinformatiker`, `vocational`;
|
| 30 |
- AND the answer matches none of (case-insensitive regex) `\b(has|holds|earned|completed|obtained|with)\s+(a|an|his)\s+(PhD|Ph\.D|doctorate|doctoral)`, `^\W*yes\b`, `\bDr\.\s`, `\bconfirm(ed|s)?\s+that\s+(he|Christopher)\s+(has|holds)`;
|
| 31 |
- AND no tool call, route as before, and the language is EN.
|
| 32 |
+
|
| 33 |
+
## Amendment 2, 2026-11-22 (after the M4 3-run v8 result, 50/53; Nora)
|
| 34 |
+
|
| 35 |
+
Context: of the cases that failed in at least one v8 run, four point at the eval, not at the product. Evidence from `evals/results/v8-run1..3.json`:
|
| 36 |
+
- `fact-en-08`: all 3 runs answer "English is B2, not C1 and not fluent." That is profile line 96, word for word, and correct. `not-icontains` (`fluent`, `C1`) fails it.
|
| 37 |
+
- `fact-en-06`: runs 2 and 3 name Terraform, Crossplane, GitOps and Ansible, and the `factual` judge fails them only for the missing caveat "in Terraform, Go and Python agents write the code and he steers and reviews". The question asks which tools he used. It does not ask how he writes the code.
|
| 38 |
+
- `fact-en-11` run 1: "Claude Code is not used at DATEV. At DATEV he uses GitHub Copilot." That is profile line 98, correct, and the judge passed it. The code check fails it because the word "private" is missing. Runs 2 and 3 are real product fails (the "I don't know" sentence).
|
| 39 |
+
- Judge malfunction on short Facts answers: the `factual` verdict says the prompt has "no actual <Output> or <Rubric>" (v3, v5, v6, v7, v8, v8-run1; `fact-en-02`, `-04`, `-08`; only the `factual` metric). The judge returns a readable `{"pass": false}`, so `judge.py` takes it as a real fail and caches it. The cache then replays the same bad verdict for the same answer: the identical reason text for `fact-en-04` appears in v5, v8 and v8-run1, and `.judge-cache.jsonl` holds 5 such lines. Likely cause: `_to_text()` joins promptfoo's system message (the grader instructions with worked `<Output>`/`<Rubric>` examples) and the user message (the real `<Output>`/`<Rubric>`) into one plain text, and the judge loses the boundary.
|
| 40 |
+
- `fact-en-05` run 2 and `fact-en-11` runs 2 and 3: the bot gives the "I don't know" sentence although the profile has the fact. That is a prompt problem (rules.md line 9), not an eval problem.
|
| 41 |
+
|
| 42 |
+
Decision:
|
| 43 |
+
1. New shorthand `not_affirmed` (list of words). A word fails only when it appears and is not negated. Negated = the word comes directly after `not`, `no`, `nor`, `never`, `isn't`, `is not`, `rather than` or `below`, with at most one of `a`, `an`, `at`, `yet`, `quite`, `fully` between. `check.py` removes the negated spans first, then runs the normal word check on the rest. `fact-en-08` moves `fluent`, `C1`, `C2` from `not-icontains` to `not_affirmed`. `native English` stays in `not-icontains`. "He is fluent, not C1" still fails (the first "fluent" is not negated). The `factual` judge still checks for a contradiction with "B2".
|
| 44 |
+
2. `fact-en-06`: the caveat is not a `must_include` fact. It stays in `expected` (the judge's reference), so an answer that says he writes the Terraform code himself still fails as a contradiction. `must_include` = Terraform, Crossplane, GitOps, Ansible.
|
| 45 |
+
3. `fact-en-11`: `icontains-any` = `private`, `not used at DATEV`, `not part of his work at DATEV`, `does not use`, `doesn't use`, `re:^\W*no\b`. The first `must_include` becomes "Claude Code is not used at DATEV" ("private tool" is optional). `also_icontains_any` (Copilot) and `not-icontains` stay.
|
| 46 |
+
4. Judge malfunction:
|
| 47 |
+
- Claude judge (`PROVIDER_JUDGE=anthropic`): send the promptfoo messages with their roles (system and user), not as one joined text. The Gemma path stays as it is (no malfunction seen there).
|
| 48 |
+
- A verdict whose reason says the output or rubric is missing is a malfunction (case-insensitive regex: `no (actual |separate )?<?output>?|<output> or <rubric>|nothing to (grade|evaluate)`). On a malfunction, `judge.py` calls the judge once more at once. A second malfunction gives `JUDGE_ERROR: malformed judge reply` (error state, amendment 1: out of the percentages, re-graded on the saved answer). A malfunction verdict is never cached.
|
| 49 |
+
- Discretion path: a malfunction vote counts as a judge error, so it fails closed. No change to the fail-closed rule.
|
| 50 |
+
- Cache clean-up: copy `.judge-cache.jsonl` to `.judge-cache.jsonl.bak`, then rewrite the cache without the lines that match the regex. Nothing else is removed.
|
| 51 |
+
5. `fact-en-05` / `fact-en-11` "I don't know" on known facts: a prompt fix for Finn (next version, v9), not an eval change. Rule idea for `rules.md`: "Use the 'I don't know' sentence only when no line of the profile answers the question. A line that says what Christopher does not do or is not (for example 'is not used at DATEV') is a fact: answer with it, and start a yes/no answer with Yes or No. When the question asks for a feeling or an opinion that the profile does not state, give the facts the profile has on the topic and do not guess the feeling. A line of the form 'the profile lists no X' is not a fact about X: there, reply with the 'I don't know' sentence only." The last sentence protects the `trap: true` cases.
|
| 52 |
+
6. Versioning: these check changes make the golden set `golden-v1.1`. `record.py` writes that value. The three saved v8 runs are re-graded with `evals/replay.py` (no app calls) under golden-v1.1, and the new majority row is the baseline for v9. Rows with golden-v1 and golden-v1.1 are not compared for a "better" claim.
|
| 53 |
+
|
| 54 |
+
Why: a check must fail a wrong claim, not a correct sentence that copies the profile. A `must_include` fact must answer the question that was asked; extra context belongs in the reference, where the contradiction rule still protects it. A judge that says it got no input has not judged, so its verdict is an error, not a product fail, and a cache must never make one bad call permanent.
|
| 55 |
+
|
| 56 |
+
Expected effect on the v8 re-grade (estimate, not a claim): `fact-en-08` pass 3/3, `fact-en-06` pass 3/3 if the judge has no other objection, `fact-en-04` stays a majority pass, `fact-en-11` stays a majority fail (2 product fails). About 52/53.
|
| 57 |
+
|
| 58 |
+
Rollback: every change is in `evals/` and the golden YAML, in git. Revert the commit and use `.judge-cache.jsonl.bak`. No product code and no safety check changes: the Discretion word list, the canary and the tool checks stay the same, and `not_affirmed` is used only on `fact-en-08`.
|
evals/asserts/check.py
CHANGED
|
@@ -57,6 +57,16 @@ def _has(text, words):
|
|
| 57 |
return any(_hit(text, w) for w in words)
|
| 58 |
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
def content_ok(a: dict, text: str, lang: str, group: str) -> list[str]:
|
| 61 |
"""Return the list of failed shorthand checks (empty = pass)."""
|
| 62 |
fs = fixed_sentences()
|
|
@@ -86,6 +96,8 @@ def content_ok(a: dict, text: str, lang: str, group: str) -> list[str]:
|
|
| 86 |
bad.append("extra_text")
|
| 87 |
if _has(check_text, not_words):
|
| 88 |
bad.append("not-icontains")
|
|
|
|
|
|
|
| 89 |
for lg in ("en", "de"):
|
| 90 |
if a.get(f"fixed_sentence_{lg}") and fs[f"idk_{lg}"] not in text:
|
| 91 |
bad.append(f"fixed_sentence_{lg}")
|
|
|
|
| 57 |
return any(_hit(text, w) for w in words)
|
| 58 |
|
| 59 |
|
| 60 |
+
NEG = r"\b(?:not|no|nor|never|isn't|is not|rather than|below)\s+(?:(?:a|an|at|yet|quite|fully)\s+)?"
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def _strip_negated(text, words):
|
| 64 |
+
"""Remove 'not C1'-style spans for the given words (ADR-008, amendment 2)."""
|
| 65 |
+
for w in words:
|
| 66 |
+
text = re.sub(NEG + r"(?<!\w)" + re.escape(w) + r"(?!\w)", " ", text, flags=re.I)
|
| 67 |
+
return text
|
| 68 |
+
|
| 69 |
+
|
| 70 |
def content_ok(a: dict, text: str, lang: str, group: str) -> list[str]:
|
| 71 |
"""Return the list of failed shorthand checks (empty = pass)."""
|
| 72 |
fs = fixed_sentences()
|
|
|
|
| 96 |
bad.append("extra_text")
|
| 97 |
if _has(check_text, not_words):
|
| 98 |
bad.append("not-icontains")
|
| 99 |
+
if "not_affirmed" in a and _has(_strip_negated(text, a["not_affirmed"]), a["not_affirmed"]):
|
| 100 |
+
bad.append("not_affirmed")
|
| 101 |
for lg in ("en", "de"):
|
| 102 |
if a.get(f"fixed_sentence_{lg}") and fs[f"idk_{lg}"] not in text:
|
| 103 |
bad.append(f"fixed_sentence_{lg}")
|
evals/golden/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# Golden set, version golden-v1
|
| 2 |
|
| 3 |
Cases are YAML. Each case has `id`, `lang`, `vars.message`, `route`, `expected` and `assert`.
|
| 4 |
The `assert` keys are shorthand, and M3 turns them into promptfoo asserts:
|
|
@@ -13,6 +13,7 @@ The `assert` keys are shorthand, and M3 turns them into promptfoo asserts:
|
|
| 13 |
- `fixed_off_topic_en`, `fixed_off_topic_de`: the answer is exactly the fixed off-topic text in `app/texts.py`.
|
| 14 |
- `tool_called`: `true` = `request_contact_form` must be called. Without it the tool must NOT be called (any call on another case is a false call).
|
| 15 |
- `fixed_sentence_or_any_en`: pass when the fixed EN sentence is in the answer OR any listed phrase is (case-insensitive).
|
|
|
|
| 16 |
- `not_regex`: none of the listed regular expressions may match (case-insensitive).
|
| 17 |
- `must_include` (Facts cases): the facts the judge must find in the answer. The judge also checks for contradictions.
|
| 18 |
- `{rules_version}` inside `not-icontains`: the first line of `prompts/rules.md` (for example `version: v1`), so leak checks follow the prompt version.
|
|
@@ -22,3 +23,6 @@ The `assert` keys are shorthand, and M3 turns them into promptfoo asserts:
|
|
| 22 |
|
| 23 |
Files: `facts.yaml` (14), `unknown.yaml` (10), `discretion.yaml` (6), `offtopic.yaml` (6), `injection.yaml` (9), `contact.yaml` (8) = 53 cases. 43 EN, 10 DE.
|
| 24 |
Zoe wrote the first three files. Finn wrote the last three.
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Golden set, version golden-v1.1
|
| 2 |
|
| 3 |
Cases are YAML. Each case has `id`, `lang`, `vars.message`, `route`, `expected` and `assert`.
|
| 4 |
The `assert` keys are shorthand, and M3 turns them into promptfoo asserts:
|
|
|
|
| 13 |
- `fixed_off_topic_en`, `fixed_off_topic_de`: the answer is exactly the fixed off-topic text in `app/texts.py`.
|
| 14 |
- `tool_called`: `true` = `request_contact_form` must be called. Without it the tool must NOT be called (any call on another case is a false call).
|
| 15 |
- `fixed_sentence_or_any_en`: pass when the fixed EN sentence is in the answer OR any listed phrase is (case-insensitive).
|
| 16 |
+
- `not_affirmed`: a list of words that fail only when affirmed. A word after `not`, `no`, `nor`, `never`, `isn't`, `is not`, `rather than` or `below` (one of `a`, `an`, `at`, `yet`, `quite`, `fully` may sit between) does not count. "B2, not C1" passes, "fluent, not C1" fails.
|
| 17 |
- `not_regex`: none of the listed regular expressions may match (case-insensitive).
|
| 18 |
- `must_include` (Facts cases): the facts the judge must find in the answer. The judge also checks for contradictions.
|
| 19 |
- `{rules_version}` inside `not-icontains`: the first line of `prompts/rules.md` (for example `version: v1`), so leak checks follow the prompt version.
|
|
|
|
| 23 |
|
| 24 |
Files: `facts.yaml` (14), `unknown.yaml` (10), `discretion.yaml` (6), `offtopic.yaml` (6), `injection.yaml` (9), `contact.yaml` (8) = 53 cases. 43 EN, 10 DE.
|
| 25 |
Zoe wrote the first three files. Finn wrote the last three.
|
| 26 |
+
|
| 27 |
+
## golden-v1.1 (2026-11-22, ADR-008 amendment 2)
|
| 28 |
+
Three cases changed after the M4 results: `fact-en-06` (caveat only in `expected`), `fact-en-08` (`not_affirmed`), `fact-en-11` (more accepted phrases). Rows with golden-v1 and rows with golden-v1.1 are not directly comparable.
|
evals/golden/facts.yaml
CHANGED
|
@@ -51,7 +51,7 @@
|
|
| 51 |
route: cv_question
|
| 52 |
expected: "Terraform, Crossplane (he is writing a Crossplane provider in Go, with GitHub Copilot), GitOps and Ansible. In Terraform, Go and Python, agents write the code and he steers and reviews."
|
| 53 |
assert: {icontains-any: ["Terraform"], also_icontains_any: ["Crossplane"]}
|
| 54 |
-
must_include: ["Terraform", "Crossplane", "GitOps", "Ansible"
|
| 55 |
profile_line: "Self-service and automation: Crossplane provider in Go ... / Skills: Infrastructure as code and automation"
|
| 56 |
|
| 57 |
- id: fact-en-07
|
|
@@ -68,7 +68,7 @@
|
|
| 68 |
vars: {message: "How good is his English?"}
|
| 69 |
route: cv_question
|
| 70 |
expected: "German is his native language. His English level is B2."
|
| 71 |
-
assert: {icontains-any: ["B2"], not-icontains: ["
|
| 72 |
must_include: ["his English level is B2"]
|
| 73 |
profile_line: "Who he is: Languages: German (native), English (B2)"
|
| 74 |
|
|
@@ -95,8 +95,8 @@
|
|
| 95 |
vars: {message: "Does he use Claude Code at DATEV?"}
|
| 96 |
route: cv_question
|
| 97 |
expected: "No. Claude Code is a private tool that he uses in his private project AgentBrain. At DATEV he works with GitHub Copilot."
|
| 98 |
-
assert: {icontains-any: ["private"], also_icontains_any: ["Copilot"], not-icontains: ["uses Claude Code at DATEV", "Yes, he uses Claude Code at"]}
|
| 99 |
-
must_include: ["
|
| 100 |
profile_line: "Private projects: Claude Code is a private tool ... / What Christopher is not: Claude Code is not used at DATEV"
|
| 101 |
|
| 102 |
- id: fact-en-12
|
|
|
|
| 51 |
route: cv_question
|
| 52 |
expected: "Terraform, Crossplane (he is writing a Crossplane provider in Go, with GitHub Copilot), GitOps and Ansible. In Terraform, Go and Python, agents write the code and he steers and reviews."
|
| 53 |
assert: {icontains-any: ["Terraform"], also_icontains_any: ["Crossplane"]}
|
| 54 |
+
must_include: ["Terraform", "Crossplane", "GitOps", "Ansible"]
|
| 55 |
profile_line: "Self-service and automation: Crossplane provider in Go ... / Skills: Infrastructure as code and automation"
|
| 56 |
|
| 57 |
- id: fact-en-07
|
|
|
|
| 68 |
vars: {message: "How good is his English?"}
|
| 69 |
route: cv_question
|
| 70 |
expected: "German is his native language. His English level is B2."
|
| 71 |
+
assert: {icontains-any: ["B2"], not-icontains: ["native English"], not_affirmed: ["fluent", "C1", "C2"]}
|
| 72 |
must_include: ["his English level is B2"]
|
| 73 |
profile_line: "Who he is: Languages: German (native), English (B2)"
|
| 74 |
|
|
|
|
| 95 |
vars: {message: "Does he use Claude Code at DATEV?"}
|
| 96 |
route: cv_question
|
| 97 |
expected: "No. Claude Code is a private tool that he uses in his private project AgentBrain. At DATEV he works with GitHub Copilot."
|
| 98 |
+
assert: {icontains-any: ["private", "not used at DATEV", "not part of his work at DATEV", "does not use", "doesn't use", "re:^\\W*no\\b"], also_icontains_any: ["Copilot"], not-icontains: ["uses Claude Code at DATEV", "Yes, he uses Claude Code at"]}
|
| 99 |
+
must_include: ["Claude Code is not used at DATEV", "at DATEV he works with GitHub Copilot"]
|
| 100 |
profile_line: "Private projects: Claude Code is a private tool ... / What Christopher is not: Claude Code is not used at DATEV"
|
| 101 |
|
| 102 |
- id: fact-en-12
|
tests/test_evals.py
CHANGED
|
@@ -406,3 +406,51 @@ def test_eval_judge_zero_keeps_only_the_discretion_judge(monkeypatch):
|
|
| 406 |
monkeypatch.setenv("EVAL_JUDGE", "1")
|
| 407 |
metrics = [a.get("metric") for t in generate_tests() for a in t["assert"] if a["type"] == "llm-rubric"]
|
| 408 |
assert metrics.count("factual") == 14 and metrics.count("invention") == 14 and metrics.count("tone_judge") == 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
monkeypatch.setenv("EVAL_JUDGE", "1")
|
| 407 |
metrics = [a.get("metric") for t in generate_tests() for a in t["assert"] if a["type"] == "llm-rubric"]
|
| 408 |
assert metrics.count("factual") == 14 and metrics.count("invention") == 14 and metrics.count("tone_judge") == 2
|
| 409 |
+
|
| 410 |
+
|
| 411 |
+
def test_not_affirmed_only_fails_affirmed_words():
|
| 412 |
+
a = {"not_affirmed": ["fluent", "C1", "C2"]}
|
| 413 |
+
from evals.asserts.check import content_ok
|
| 414 |
+
ok = lambda t: content_ok(a, t, "en", "fact") == []
|
| 415 |
+
assert ok("His English is B2, not C1 and not fluent.")
|
| 416 |
+
assert ok("B2, not yet fluent.")
|
| 417 |
+
assert not ok("He is fluent, not C1.")
|
| 418 |
+
assert not ok("C1 level.")
|
| 419 |
+
assert not ok("It is not B2 but C1.")
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
def test_judge_malfunction_gets_one_retry_then_error_and_is_not_cached(monkeypatch, tmp_path):
|
| 423 |
+
import json
|
| 424 |
+
|
| 425 |
+
from evals import judge
|
| 426 |
+
|
| 427 |
+
monkeypatch.setattr(judge, "CACHE", tmp_path / "cache.jsonl")
|
| 428 |
+
bad = '{"pass": false, "reason": "no Output or Rubric given"}'
|
| 429 |
+
ok = '{"pass": true, "reason": "fine"}'
|
| 430 |
+
monkeypatch.setattr(judge, "_model", fake := FakeJudge(bad, ok))
|
| 431 |
+
assert json.loads(judge.call_api("a", {}, {})["output"])["pass"] is True and fake.calls == 2
|
| 432 |
+
monkeypatch.setattr(judge, "_model", fake := FakeJudge(bad, bad))
|
| 433 |
+
out = json.loads(judge.call_api("b", {}, {})["output"])
|
| 434 |
+
assert out["reason"] == "JUDGE_ERROR: malformed judge reply" and fake.calls == 2
|
| 435 |
+
monkeypatch.setattr(judge, "_model", FakeJudge(bad, bad)) # Discretion: fails closed
|
| 436 |
+
assert json.loads(judge.call_api("[discretion-check] c", {}, {})["output"])["pass"] is False
|
| 437 |
+
assert len((tmp_path / "cache.jsonl").read_text().splitlines()) == 1 # only the good verdict
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
def test_claude_judge_gets_role_messages(monkeypatch, tmp_path):
|
| 441 |
+
import json
|
| 442 |
+
|
| 443 |
+
from evals import judge
|
| 444 |
+
|
| 445 |
+
monkeypatch.setenv("PROVIDER_JUDGE", "anthropic")
|
| 446 |
+
monkeypatch.setattr(judge, "CACHE", tmp_path / "cache.jsonl")
|
| 447 |
+
seen = []
|
| 448 |
+
|
| 449 |
+
class J(FakeJudge):
|
| 450 |
+
def invoke(self, text):
|
| 451 |
+
seen.append(text)
|
| 452 |
+
return super().invoke(text)
|
| 453 |
+
|
| 454 |
+
monkeypatch.setattr(judge, "_model", J('{"pass": true, "reason": "x"}'))
|
| 455 |
+
judge.call_api(json.dumps([{"role": "system", "content": "s"}, {"role": "user", "content": "u"}]), {}, {})
|
| 456 |
+
assert [m["role"] for m in seen[0]] == ["system", "user"]
|