Skip to content

Commit af4ab21

Browse files
myhoaiclaude
andcommitted
feat(gooddata-eval): label harness errors, keep every verdict
QA-30213, phase 1: a failing run is labelled ERROR only when the test harness failed (its simulated user or its judge), FAIL otherwise. The rule is one fail-closed allowlist in core/outcome.py; chat_error, agent_timeout, turn_incomplete and any unknown cause stay FAIL, since a customer hits them too. The labels decide nothing: an ERROR run still counts as a run that did not pass, so gates, pass rates and scores are unchanged. They appear in the "Failing runs" part of the failure message, in failed_runs[] (exit_reason, outcome, failed_checks), on the raised exception (outcome when every run errored, and shadow, the verdict a phase-2 candidate rule would give, recorded only for QA-30296), and in Langfuse as an extra eval_error score. Judge failures of general question, guardrail and document skill are labelled too; a failed takeaway request stays FAIL. A timed-out or incomplete turn now records agent_timeout / turn_incomplete instead of chat_error. jira: QA-30213 risk: low Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c249199 commit af4ab21

31 files changed

Lines changed: 2066 additions & 84 deletions

‎packages/gooddata-eval/AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ experiment. The newest and most actively developed package in the repo.
3434
| `core/reporting/` | console and JSON output rendering |
3535
| `core/scoring.py`, `core/runner.py` | scoring and orchestration |
3636
| `core/models.py` | `DatasetItem`, `ChatResult`, `ItemReport` and friends |
37+
| `core/outcome.py` | `Outcome` (PASS / FAIL / ERROR): the one fail-closed rule that labels a failing run ERROR when the harness failed (simulated user, judge), plus the item label and the recorded-only shadow verdict. Labels decide no verdict; the agentic kinds reach it through `core/agentic/_outcome.py`'s `label_runs` |
3738

3839
**Depends on**: `gooddata-sdk`, `httpx`, `pydantic`, `orjson`, `rich`. The LLM-judge
3940
evaluator is an optional extra (`llm-judge`, pulling `openai>=1.45,<2.0`); every `openai`

‎packages/gooddata-eval/src/gooddata_eval/core/agentic/_failed_runs.py‎

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
from collections.abc import Callable, Sequence
2626
from typing import Any
2727

28+
from gooddata_eval.core.agentic._failure_message import cap_failed_checks
29+
from gooddata_eval.core.agentic._outcome import JudgeErrorOf, run_exit_reason, run_outcome
2830
from gooddata_eval.core.models import build_tool_calls
2931

3032

@@ -33,6 +35,8 @@ def build_failed_runs(
3335
*,
3436
passed: Callable[[Any], bool],
3537
detail: Callable[[Any], dict],
38+
failed_checks: Callable[[Any], list[dict]] | None = None,
39+
judge_error: JudgeErrorOf | None = None,
3640
) -> list[dict]:
3741
"""One record per run that did not pass, in the order the runs happened.
3842
@@ -47,26 +51,37 @@ def build_failed_runs(
4751
A run the judge could not grade is recorded like any other non-passing run, with its
4852
``error`` set. That matches ``core/runner.py``, which also records ungraded runs; the
4953
verdict-level accounting of ungraded runs stays with the caller's ``unscored_runs``.
54+
55+
``exit_reason`` is the run's ``LoopExit`` value, or null for a kind whose loop records
56+
none, and ``outcome`` its ``core.outcome.Outcome`` record: ERROR when the harness failed
57+
(its simulated user or its judge), FAIL otherwise. The label decides nothing; the run
58+
counts as not passed either way; ``judge_error`` is passed on to ``run_outcome``. ``failed_checks`` is written only when the caller supplies it: a missing
59+
key means the kind does not name its failing checks, while an empty list would claim the
60+
run failed none. Its expected/actual values are capped in size; the run's ``detail``
61+
keeps them whole.
5062
"""
5163
records: list[dict] = []
5264
for run_index, run in enumerate(run_results, start=1):
5365
if passed(run):
5466
continue
5567
tool_calls = list(getattr(run, "tool_call_events", None) or [])
5668
reasoning_steps = list(getattr(run, "reasoning_steps", None) or [])
57-
records.append(
58-
{
59-
"run_index": run_index,
60-
"passed": False,
61-
"error": getattr(run, "judge_error", None),
62-
"detail": detail(run),
63-
"conversation_id": getattr(run, "conversation_id", None),
64-
"response_id": getattr(run, "response_id", None),
65-
"reasoning_step_count": len(reasoning_steps),
66-
"reasoning_steps": reasoning_steps,
67-
"tool_call_count": len(tool_calls),
68-
"tool_names": [getattr(e, "function_name", None) for e in tool_calls],
69-
"tool_calls": build_tool_calls(tool_calls),
70-
}
71-
)
69+
record: dict[str, Any] = {
70+
"run_index": run_index,
71+
"passed": False,
72+
"error": getattr(run, "judge_error", None),
73+
"detail": detail(run),
74+
"conversation_id": getattr(run, "conversation_id", None),
75+
"response_id": getattr(run, "response_id", None),
76+
"reasoning_step_count": len(reasoning_steps),
77+
"reasoning_steps": reasoning_steps,
78+
"tool_call_count": len(tool_calls),
79+
"tool_names": [getattr(e, "function_name", None) for e in tool_calls],
80+
"tool_calls": build_tool_calls(tool_calls),
81+
"exit_reason": run_exit_reason(run),
82+
"outcome": run_outcome(run, passed=False, judge_error=judge_error).as_record(),
83+
}
84+
if failed_checks is not None:
85+
record["failed_checks"] = cap_failed_checks(failed_checks(run))
86+
records.append(record)
7287
return records
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# (C) 2026 GoodData Corporation
2+
"""The head of an agentic kind's failure message: the gate result, then every failing run.
3+
4+
Each kind's assertion message describes its BEST run, which on a partial gate failure (some
5+
of the K runs passed) is a passing run: every check reads True and the reason the item
6+
failed is nowhere in the message. This module renders the part that is missing -- for each
7+
failing run its index, why its loop stopped and the checks it failed, with expected/actual
8+
where the kind knows them -- from the same ``failed_runs`` records the item reports, so the
9+
message and the triage data cannot disagree about which runs failed or why.
10+
11+
One renderer for every kind on purpose: the readers of these messages (people and the
12+
triage tooling) look for one shape, whatever the capability under test.
13+
"""
14+
15+
from __future__ import annotations
16+
17+
import json
18+
from collections.abc import Iterable, Mapping, Sequence
19+
from dataclasses import dataclass
20+
from enum import Enum
21+
from typing import Any
22+
23+
__all__ = ["FailedCheck", "cap_failed_checks", "failed_check_records", "failing_runs_note", "failure_head"]
24+
25+
# A value longer than this is cut: the message is one line per run, and the whole value is in
26+
# the run's detail anyway.
27+
_MAX_VALUE_CHARS = 160
28+
29+
30+
class _Unset(Enum):
31+
UNSET = "unset"
32+
33+
34+
_UNSET = _Unset.UNSET
35+
36+
37+
@dataclass(frozen=True)
38+
class FailedCheck:
39+
"""One check a run failed, with the expected/actual pair when the kind knows it.
40+
41+
``label`` narrows the check when one name covers several parts, e.g. the ``date`` part of
42+
``filters_correct``.
43+
"""
44+
45+
name: str
46+
expected: Any = _UNSET
47+
actual: Any = _UNSET
48+
label: str | None = None
49+
50+
def as_record(self) -> dict[str, Any]:
51+
"""The JSON-ready form written into a failing run's ``failed_checks``."""
52+
record: dict[str, Any] = {"name": self.name}
53+
if self.label is not None:
54+
record["label"] = self.label
55+
if self.expected is not _UNSET:
56+
record["expected"] = self.expected
57+
if self.actual is not _UNSET:
58+
record["actual"] = self.actual
59+
return record
60+
61+
62+
def failed_check_records(checks: Iterable[FailedCheck]) -> list[dict[str, Any]]:
63+
"""``checks`` as the records ``failed_runs[].failed_checks`` holds."""
64+
return [check.as_record() for check in checks]
65+
66+
67+
def _text(value: Any) -> str:
68+
text = value if isinstance(value, str) else json.dumps(value, default=str, ensure_ascii=False, sort_keys=True)
69+
return " ".join(text.split())
70+
71+
72+
def _value(value: Any) -> str:
73+
if value is None or value == [] or value == {} or value == "":
74+
return "none"
75+
text = _text(value)
76+
return text if len(text) <= _MAX_VALUE_CHARS else text[: _MAX_VALUE_CHARS - 3] + "..."
77+
78+
79+
def cap_failed_checks(records: Sequence[Mapping[str, Any]]) -> list[dict[str, Any]]:
80+
"""``records`` with every expected/actual value cut to what the message shows of it.
81+
82+
A check's values can be whole filter or bucket structures, repeated for every failing run
83+
of every item; the record keeps the same ``_MAX_VALUE_CHARS`` the message does. A value
84+
that fits stays as it is, JSON and all; a longer one becomes its cut text. The run's
85+
``detail`` holds the full values.
86+
"""
87+
capped: list[dict[str, Any]] = []
88+
for record in records:
89+
entry = dict(record)
90+
for key in ("expected", "actual"):
91+
if key in entry and len(_text(entry[key])) > _MAX_VALUE_CHARS:
92+
entry[key] = _value(entry[key])
93+
capped.append(entry)
94+
return capped
95+
96+
97+
def _render_check(record: Mapping[str, Any]) -> str:
98+
name = str(record.get("name", "?"))
99+
parts: list[str] = []
100+
if "expected" in record:
101+
parts.append(f"expected {_value(record['expected'])}")
102+
if "actual" in record:
103+
parts.append(f"actual {_value(record['actual'])}")
104+
label = record.get("label")
105+
if not parts and label is None:
106+
return name
107+
inner = ", ".join(parts)
108+
if label is not None:
109+
inner = f"{label}: {inner}" if inner else str(label)
110+
return f"{name}[{inner}]"
111+
112+
113+
def _render_run(record: Mapping[str, Any], runs_total: int) -> str:
114+
outcome = record.get("outcome")
115+
head = f"run {record.get('run_index', '?')}/{runs_total}"
116+
exit_reason = record.get("exit_reason")
117+
if isinstance(outcome, Mapping) and outcome.get("status") == "error":
118+
# A harness error: the reason (simulated_user_failed, judge_failed) is the diagnosis.
119+
# Its checks are not listed: they failed because the harness did, not the agent.
120+
return f"{head} ERROR ({outcome.get('reason') or 'unknown'})"
121+
head += " FAIL" + (f" (loop exit: {exit_reason})" if exit_reason else "")
122+
checks = record.get("failed_checks")
123+
if checks:
124+
return f"{head}: {', '.join(_render_check(c) for c in checks)}"
125+
if checks is not None:
126+
return f"{head}: no failing check recorded"
127+
return head
128+
129+
130+
def failing_runs_note(failed_runs: Sequence[Mapping[str, Any]], runs_total: int) -> str:
131+
"""Every failing run on one line each, joined with ``; ``. Empty when no run failed."""
132+
return "; ".join(_render_run(record, runs_total) for record in failed_runs)
133+
134+
135+
def failure_head(gate_note: str, failed_runs: Sequence[Mapping[str, Any]], runs_total: int) -> str:
136+
"""``gate_note`` followed by the failing runs, ready to start a kind's assertion message.
137+
138+
Returns ``gate_note`` unchanged when there is no failing run to list, so a kind that
139+
builds no ``failed_runs`` keeps its message exactly as before.
140+
"""
141+
note = failing_runs_note(failed_runs, runs_total)
142+
return f"{gate_note} Failing runs: {note}." if note else gate_note

0 commit comments

Comments
 (0)