benchmark-disclosure 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- benchmark_disclosure/__init__.py +20 -0
- benchmark_disclosure/__main__.py +3 -0
- benchmark_disclosure/_registry.py +3 -0
- benchmark_disclosure/assess.py +543 -0
- benchmark_disclosure/cli.py +194 -0
- benchmark_disclosure/conformance.py +84 -0
- benchmark_disclosure/data/mapping.yaml +764 -0
- benchmark_disclosure/evidence.py +114 -0
- benchmark_disclosure/inspect_hook.py +579 -0
- benchmark_disclosure/mapping.py +301 -0
- benchmark_disclosure/otlp_file.py +98 -0
- benchmark_disclosure/paths.py +88 -0
- benchmark_disclosure/readers/__init__.py +173 -0
- benchmark_disclosure/readers/inspect_log.py +199 -0
- benchmark_disclosure/readers/otlp.py +209 -0
- benchmark_disclosure/report.py +491 -0
- benchmark_disclosure/rubric.py +64 -0
- benchmark_disclosure/signals.py +742 -0
- benchmark_disclosure/spec_markdown.py +93 -0
- benchmark_disclosure-0.1.0.dist-info/METADATA +208 -0
- benchmark_disclosure-0.1.0.dist-info/RECORD +25 -0
- benchmark_disclosure-0.1.0.dist-info/WHEEL +4 -0
- benchmark_disclosure-0.1.0.dist-info/entry_points.txt +5 -0
- benchmark_disclosure-0.1.0.dist-info/licenses/LICENSE +202 -0
- benchmark_disclosure-0.1.0.dist-info/licenses/NOTICE +16 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Make benchmark and agent-eval runs reviewable against a published review rubric."""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.1.0"
|
|
4
|
+
|
|
5
|
+
from .assess import Assessment, assess # noqa: E402
|
|
6
|
+
from .mapping import Mapping, load_mapping # noqa: E402
|
|
7
|
+
from .readers import load_evidence # noqa: E402
|
|
8
|
+
from .report import render_html, render_markdown, to_summary # noqa: E402
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"Assessment",
|
|
12
|
+
"Mapping",
|
|
13
|
+
"__version__",
|
|
14
|
+
"assess",
|
|
15
|
+
"load_evidence",
|
|
16
|
+
"load_mapping",
|
|
17
|
+
"render_html",
|
|
18
|
+
"render_markdown",
|
|
19
|
+
"to_summary",
|
|
20
|
+
]
|
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
"""Score each rubric item as found, incomplete or not found, with evidence pointers.
|
|
2
|
+
|
|
3
|
+
A status says whether the inputs hold a non-empty value at a mapped location. It
|
|
4
|
+
does not check what the value says beyond rejecting placeholders such as
|
|
5
|
+
"unknown", and it is not a judgment of the benchmark.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
|
+
from datetime import UTC, datetime
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from .evidence import Evidence, Run
|
|
16
|
+
from .mapping import EvidenceKey, Item, Mapping, Source
|
|
17
|
+
from .paths import is_empty, parent_pointer, resolve, resolve_all
|
|
18
|
+
|
|
19
|
+
FOUND, INCOMPLETE, NOT_FOUND = "found", "incomplete", "not_found"
|
|
20
|
+
STATUSES = (FOUND, INCOMPLETE, NOT_FOUND)
|
|
21
|
+
_RANK = {FOUND: 2, INCOMPLETE: 1, NOT_FOUND: 0}
|
|
22
|
+
MAX_POINTERS = 3
|
|
23
|
+
MAX_VALUES = 5
|
|
24
|
+
PLACEHOLDERS = {
|
|
25
|
+
"unknown",
|
|
26
|
+
"n/a",
|
|
27
|
+
"na",
|
|
28
|
+
"none",
|
|
29
|
+
"tbd",
|
|
30
|
+
"todo",
|
|
31
|
+
"unspecified",
|
|
32
|
+
"not specified",
|
|
33
|
+
"not stated",
|
|
34
|
+
"not known",
|
|
35
|
+
"not disclosed",
|
|
36
|
+
"not documented",
|
|
37
|
+
"not available",
|
|
38
|
+
"not publicly available",
|
|
39
|
+
"not assessed",
|
|
40
|
+
"unavailable",
|
|
41
|
+
"undisclosed",
|
|
42
|
+
"nil",
|
|
43
|
+
"?",
|
|
44
|
+
"-",
|
|
45
|
+
"—",
|
|
46
|
+
}
|
|
47
|
+
ABSENT_NOTES = {
|
|
48
|
+
"none_set": "absent: Inspect records this whenever it applies, so it did not apply",
|
|
49
|
+
"none_recorded": (
|
|
50
|
+
"no eval- or task-level value recorded; a limit set inside a solver or agent is logged only when a task hits it"
|
|
51
|
+
),
|
|
52
|
+
"provider_default": (
|
|
53
|
+
"not set in the eval, task or model calls recorded in the log; a provider or "
|
|
54
|
+
"Inspect default applied, and its value is not recorded"
|
|
55
|
+
),
|
|
56
|
+
}
|
|
57
|
+
# Absence that Inspect records whenever the thing applies is evidence; absence of a
|
|
58
|
+
# setting is not, so it never lifts a key above not found.
|
|
59
|
+
ABSENT_STATUS = {"none_set": FOUND, "none_recorded": NOT_FOUND, "provider_default": NOT_FOUND}
|
|
60
|
+
# Manifest fields the mapping does not read but that are part of the manifest format.
|
|
61
|
+
MANIFEST_FIELDS = {
|
|
62
|
+
"benchmark.name",
|
|
63
|
+
"benchmark.version",
|
|
64
|
+
"benchmark.task_names",
|
|
65
|
+
"withheld",
|
|
66
|
+
"leaderboard.runs_in_inputs",
|
|
67
|
+
"sources",
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@dataclass
|
|
72
|
+
class Observation:
|
|
73
|
+
source: str
|
|
74
|
+
values: list[str]
|
|
75
|
+
pointers: list[str]
|
|
76
|
+
count: int
|
|
77
|
+
note: str | None = None
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@dataclass
|
|
81
|
+
class KeyResult:
|
|
82
|
+
"""One evidence key evaluated for one run, or for the documentation."""
|
|
83
|
+
|
|
84
|
+
status: str
|
|
85
|
+
observations: list[Observation] = field(default_factory=list)
|
|
86
|
+
note: str | None = None
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@dataclass
|
|
90
|
+
class EvidenceResult:
|
|
91
|
+
key: EvidenceKey
|
|
92
|
+
status: str
|
|
93
|
+
per_run: dict[str, KeyResult]
|
|
94
|
+
benchmark: KeyResult | None = None
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@dataclass
|
|
98
|
+
class Signal:
|
|
99
|
+
id: str
|
|
100
|
+
level: str # "info" or "review"
|
|
101
|
+
message: str
|
|
102
|
+
data: dict[str, Any] = field(default_factory=dict)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@dataclass
|
|
106
|
+
class ItemResult:
|
|
107
|
+
item: Item
|
|
108
|
+
status: str
|
|
109
|
+
required: list[EvidenceResult]
|
|
110
|
+
supporting: list[EvidenceResult]
|
|
111
|
+
signals: list[Signal]
|
|
112
|
+
leaderboard: list[EvidenceResult] = field(default_factory=list)
|
|
113
|
+
from_runs: list[EvidenceResult] = field(default_factory=list)
|
|
114
|
+
runs_are_leaderboard: bool = False
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@dataclass
|
|
118
|
+
class Assessment:
|
|
119
|
+
mapping: Mapping
|
|
120
|
+
evidence: Evidence
|
|
121
|
+
items: list[ItemResult]
|
|
122
|
+
evidence_results: dict[str, EvidenceResult]
|
|
123
|
+
generated_at: str
|
|
124
|
+
conformance: dict[str, Any] | None = None
|
|
125
|
+
warnings: list[str] = field(default_factory=list)
|
|
126
|
+
|
|
127
|
+
@property
|
|
128
|
+
def scored_items(self) -> list[ItemResult]:
|
|
129
|
+
return [r for r in self.items if not r.item.informational]
|
|
130
|
+
|
|
131
|
+
def totals(self) -> dict[str, int]:
|
|
132
|
+
counts = dict.fromkeys(STATUSES, 0)
|
|
133
|
+
for result in self.scored_items:
|
|
134
|
+
counts[result.status] += 1
|
|
135
|
+
return counts
|
|
136
|
+
|
|
137
|
+
def section_totals(self) -> dict[str, dict[str, int]]:
|
|
138
|
+
out: dict[str, dict[str, int]] = {}
|
|
139
|
+
for result in self.scored_items:
|
|
140
|
+
counts = out.setdefault(result.item.section, dict.fromkeys(STATUSES, 0))
|
|
141
|
+
counts[result.status] += 1
|
|
142
|
+
return out
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def combine(statuses: list[str]) -> str:
|
|
146
|
+
if not statuses:
|
|
147
|
+
return NOT_FOUND
|
|
148
|
+
if all(s == FOUND for s in statuses):
|
|
149
|
+
return FOUND
|
|
150
|
+
if all(s == NOT_FOUND for s in statuses):
|
|
151
|
+
return NOT_FOUND
|
|
152
|
+
return INCOMPLETE
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def best(statuses: list[str]) -> str:
|
|
156
|
+
return max(statuses, key=_RANK.__getitem__) if statuses else NOT_FOUND
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def show(value: Any, limit: int = 120) -> str:
|
|
160
|
+
text = value if isinstance(value, str) else json.dumps(value, sort_keys=True, default=str)
|
|
161
|
+
text = " ".join(text.split())
|
|
162
|
+
return text if len(text) <= limit else text[: limit - 1] + "…"
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def unwrap(value: Any) -> tuple[Any, dict[str, Any]]:
|
|
166
|
+
"""A manifest value may be written as ``{value: ..., source: ..., coverage: ..., note: ...}``."""
|
|
167
|
+
if isinstance(value, dict) and "value" in value:
|
|
168
|
+
return value["value"], {k: v for k, v in value.items() if k != "value"}
|
|
169
|
+
return value, {}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _words(value: str) -> str:
|
|
173
|
+
return value.strip().lower().rstrip(".;!")
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def is_placeholder(value: Any, none_is_value: bool = False) -> bool:
|
|
177
|
+
"""Values that say nothing, such as "unknown", "N/A." or "not disclosed".
|
|
178
|
+
|
|
179
|
+
Matching is exact, so a real answer that starts with "None (...)" still counts.
|
|
180
|
+
"""
|
|
181
|
+
if isinstance(value, list):
|
|
182
|
+
return bool(value) and all(is_placeholder(v, none_is_value) for v in value)
|
|
183
|
+
if not isinstance(value, str):
|
|
184
|
+
return False
|
|
185
|
+
words = _words(value)
|
|
186
|
+
return words in PLACEHOLDERS and not (none_is_value and words == "none")
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _declares_none(value: Any) -> bool:
|
|
190
|
+
"""An access declaration such as "none - tasks are private"."""
|
|
191
|
+
if not isinstance(value, str):
|
|
192
|
+
return False
|
|
193
|
+
first = _words(value).replace(":", " ").replace(",", " ").split(" ", 1)[0]
|
|
194
|
+
return first in ("none", "private", "unavailable") or is_placeholder(value)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _accepted(source: Source, value: Any) -> bool:
|
|
198
|
+
if not source.accept:
|
|
199
|
+
return True
|
|
200
|
+
return isinstance(value, str) and value.strip().lower() in source.accept
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def _rejected(source: Source, value: Any) -> bool:
|
|
204
|
+
return bool(source.reject) and str(value) in source.reject
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def _observation(source: Source, found: list[tuple[str, Any]], note: str | None = None) -> Observation:
|
|
208
|
+
values = list(dict.fromkeys(show(v) for _, v in found))
|
|
209
|
+
return Observation(
|
|
210
|
+
source=source.label,
|
|
211
|
+
values=values[:MAX_VALUES],
|
|
212
|
+
pointers=[p for p, _ in found[:MAX_POINTERS]],
|
|
213
|
+
count=len(found),
|
|
214
|
+
note=note,
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _withhold(observation: Observation, total: int) -> None:
|
|
219
|
+
shown = f"{observation.count} of {total}" if total > observation.count else str(observation.count)
|
|
220
|
+
observation.values = [f"withheld: {shown} non-empty value(s); rerun with --show-content to include"]
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _log_pointer(run: Run, pointer: str) -> str:
|
|
224
|
+
"""Point derived values at the log field they were computed from."""
|
|
225
|
+
if pointer.startswith("/_derived/") and run.log is not None:
|
|
226
|
+
name = pointer.removeprefix("/_derived/").split("/", 1)[0]
|
|
227
|
+
pointer = (run.log.get("_derived_from") or {}).get(name, pointer)
|
|
228
|
+
return f"{run.source}#{pointer}"
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
# Each source yields (status, observation) pairs for the facets it feeds.
|
|
232
|
+
SourceResult = tuple[str, Observation]
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def _inspect_results(key: EvidenceKey, run: Run, source: Source, show_content: bool) -> list[SourceResult]:
|
|
236
|
+
if run.log is None:
|
|
237
|
+
return []
|
|
238
|
+
matches = resolve_all(run.log, source.path)
|
|
239
|
+
rejected = [(p, v) for p, v in matches if not is_empty(v) and _rejected(source, v)]
|
|
240
|
+
found = [
|
|
241
|
+
(_log_pointer(run, p), v)
|
|
242
|
+
for p, v in matches
|
|
243
|
+
if not is_empty(v) and not _rejected(source, v) and _accepted(source, v)
|
|
244
|
+
]
|
|
245
|
+
unverified = (
|
|
246
|
+
"[origin=agent]" in source.path and (run.log.get("_derived") or {}).get("origin_inferred") == "unverified"
|
|
247
|
+
)
|
|
248
|
+
if found:
|
|
249
|
+
empties = sum(1 for _, v in matches if is_empty(v))
|
|
250
|
+
observation = _observation(source, found, source.partial)
|
|
251
|
+
# Content is withheld before anything else, so no branch below can return it.
|
|
252
|
+
if key.content and not show_content:
|
|
253
|
+
_withhold(observation, len(found) + empties)
|
|
254
|
+
if unverified:
|
|
255
|
+
# An old log without span records cannot tell the model under test's calls from a scorer's.
|
|
256
|
+
note = "the log predates Inspect's call origin, so these calls may include a scorer's"
|
|
257
|
+
observation.note = f"{observation.note}; {note}" if observation.note else note
|
|
258
|
+
return [(INCOMPLETE, observation)]
|
|
259
|
+
if empties and "[*]" in source.path and not source.empty_is_value:
|
|
260
|
+
share = f"{len(found)} of {len(found) + empties} values are non-empty"
|
|
261
|
+
observation.note = f"{observation.note}; {share}" if observation.note else share
|
|
262
|
+
return [(INCOMPLETE, observation)]
|
|
263
|
+
return [(INCOMPLETE if source.partial else FOUND, observation)]
|
|
264
|
+
if matches and source.empty_is_value and not rejected:
|
|
265
|
+
pointers = [(_log_pointer(run, p), source.empty_is_value) for p, _ in matches]
|
|
266
|
+
if unverified:
|
|
267
|
+
note = "the log predates Inspect's call origin, so these calls may include a scorer's"
|
|
268
|
+
return [(INCOMPLETE, _observation(source, pointers, note))]
|
|
269
|
+
return [(FOUND, _observation(source, pointers))]
|
|
270
|
+
if matches and not rejected:
|
|
271
|
+
note = f"all {len(matches)} values are empty"
|
|
272
|
+
return [(NOT_FOUND, Observation(source.label, [], [_log_pointer(run, matches[0][0])], 0, note))]
|
|
273
|
+
if rejected:
|
|
274
|
+
shown = "a withheld value" if key.content and not show_content else show(rejected[0][1])
|
|
275
|
+
note = source.reject_note or f"{shown} does not count"
|
|
276
|
+
return [(NOT_FOUND, Observation(source.label, [], [_log_pointer(run, rejected[0][0])], 0, note))]
|
|
277
|
+
if source.absent == "unknown":
|
|
278
|
+
return []
|
|
279
|
+
parent = parent_pointer(run.log, source.path)
|
|
280
|
+
if parent is None:
|
|
281
|
+
return []
|
|
282
|
+
status = ABSENT_STATUS[source.absent]
|
|
283
|
+
return [(status, Observation(source.label, [], [_log_pointer(run, parent)], 0, ABSENT_NOTES[source.absent]))]
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def is_subject_span(span: Any, prefix: str) -> bool:
|
|
287
|
+
"""Spans with no role, or the role ``subject``; every other role is some other caller."""
|
|
288
|
+
role = span.attributes.get(
|
|
289
|
+
"gen_ai.evaluation.model.role", span.attributes.get(prefix + "gen_ai.evaluation.model.role")
|
|
290
|
+
)
|
|
291
|
+
return str(role or "") in ("", "subject")
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def _span_results(key: EvidenceKey, run: Run, source: Source, prefix: str, show_content: bool) -> list[SourceResult]:
|
|
295
|
+
names = [source.attribute] if source.kind == "otel" else [source.attribute, prefix + source.attribute]
|
|
296
|
+
found: list[tuple[str, Any]] = []
|
|
297
|
+
spans = run.spans if source.event else run.spans_for(source.span)
|
|
298
|
+
if source.span == "chat" and source.calls == "subject":
|
|
299
|
+
spans = [s for s in spans if is_subject_span(s, prefix)]
|
|
300
|
+
for span in spans:
|
|
301
|
+
if source.event:
|
|
302
|
+
for event in span.events:
|
|
303
|
+
if event.name != source.event:
|
|
304
|
+
continue
|
|
305
|
+
for name in names:
|
|
306
|
+
value = event.attributes.get(name)
|
|
307
|
+
if not is_empty(value) and _accepted(source, value) and not _rejected(source, value):
|
|
308
|
+
found.append((span.pointer(name, event.name), value))
|
|
309
|
+
continue
|
|
310
|
+
for name in names:
|
|
311
|
+
value = span.attributes.get(name)
|
|
312
|
+
if not is_empty(value) and _accepted(source, value) and not _rejected(source, value):
|
|
313
|
+
found.append((span.pointer(name), value))
|
|
314
|
+
if not found:
|
|
315
|
+
return []
|
|
316
|
+
observation = _observation(source, found, source.partial)
|
|
317
|
+
if key.content and not show_content:
|
|
318
|
+
_withhold(observation, len(found))
|
|
319
|
+
return [(INCOMPLETE if source.partial else FOUND, observation)]
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def _manifest_results(key: EvidenceKey, evidence: Evidence, source: Source) -> list[SourceResult]:
|
|
323
|
+
if evidence.manifest is None:
|
|
324
|
+
return []
|
|
325
|
+
out: list[SourceResult] = []
|
|
326
|
+
for pointer, raw in resolve(evidence.manifest.data, source.path):
|
|
327
|
+
value, meta = unwrap(raw)
|
|
328
|
+
where = f"{evidence.manifest.source}#{pointer}"
|
|
329
|
+
notes = [str(meta["note"])] if meta.get("note") else []
|
|
330
|
+
if meta.get("source"):
|
|
331
|
+
notes.append(f"source: {meta['source']}")
|
|
332
|
+
declared_none = bool(source.accept) and _declares_none(value)
|
|
333
|
+
if is_empty(value) or is_placeholder(value, key.none_is_value) or declared_none:
|
|
334
|
+
note = f"the manifest says {show(value)!s}" if not is_empty(value) else "empty in the manifest"
|
|
335
|
+
out.append((NOT_FOUND, Observation(source.label, [], [where], 0, note)))
|
|
336
|
+
continue
|
|
337
|
+
observation = Observation(source.label, [show(value)], [where], 1, "; ".join(notes) or None)
|
|
338
|
+
if not _accepted(source, value):
|
|
339
|
+
expected = ", ".join(source.accept)
|
|
340
|
+
observation.note = f"not one of the recognized values ({expected})"
|
|
341
|
+
out.append((INCOMPLETE, observation))
|
|
342
|
+
elif str(meta.get("coverage", "")).lower() == "partial" or source.partial:
|
|
343
|
+
if source.partial:
|
|
344
|
+
observation.note = "; ".join(filter(None, [source.partial, observation.note]))
|
|
345
|
+
out.append((INCOMPLETE, observation))
|
|
346
|
+
else:
|
|
347
|
+
out.append((FOUND, observation))
|
|
348
|
+
return out
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def _facet_status(results: list[SourceResult]) -> str:
|
|
352
|
+
statuses = [s for s, _ in results]
|
|
353
|
+
return best(statuses) if statuses else NOT_FOUND
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
def _evaluate(
|
|
357
|
+
key: EvidenceKey, run: Run | None, evidence: Evidence, mapping: Mapping, show_content: bool = False
|
|
358
|
+
) -> KeyResult:
|
|
359
|
+
per_facet: dict[str, list[SourceResult]] = {name: [] for name, _ in key.facets}
|
|
360
|
+
for source in key.sources:
|
|
361
|
+
if source.kind == "manifest":
|
|
362
|
+
results = _manifest_results(key, evidence, source)
|
|
363
|
+
elif run is None:
|
|
364
|
+
continue
|
|
365
|
+
elif source.kind == "inspect":
|
|
366
|
+
results = _inspect_results(key, run, source, show_content)
|
|
367
|
+
else:
|
|
368
|
+
results = _span_results(key, run, source, mapping.interim_prefix, show_content)
|
|
369
|
+
for facet in source.facets:
|
|
370
|
+
per_facet[facet].extend(results)
|
|
371
|
+
|
|
372
|
+
statuses = []
|
|
373
|
+
observations: list[Observation] = []
|
|
374
|
+
notes: list[str] = []
|
|
375
|
+
for facet, results in per_facet.items():
|
|
376
|
+
status = _facet_status(results)
|
|
377
|
+
statuses.append(status)
|
|
378
|
+
# Show the strongest evidence for each facet, and fallback notes only when nothing better exists.
|
|
379
|
+
keep = [o for s, o in results if s == status]
|
|
380
|
+
if any(o.values for o in keep):
|
|
381
|
+
keep = [o for o in keep if o.values]
|
|
382
|
+
seen_notes: set[str | None] = set()
|
|
383
|
+
for observation in keep:
|
|
384
|
+
if not observation.values and observation.note in seen_notes:
|
|
385
|
+
continue
|
|
386
|
+
seen_notes.add(observation.note)
|
|
387
|
+
if observation not in observations:
|
|
388
|
+
observations.append(observation)
|
|
389
|
+
if len(key.facets) > 1 and status == NOT_FOUND:
|
|
390
|
+
notes.append(f"not found: {key.facet_label(facet)}")
|
|
391
|
+
status = combine(statuses)
|
|
392
|
+
note = "; ".join(notes) or next((o.note for o in observations if o.note and not o.values), None)
|
|
393
|
+
return KeyResult(status, observations, note)
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
def _withheld(key: EvidenceKey, evidence: Evidence) -> tuple[str, str] | None:
|
|
397
|
+
if evidence.manifest is None:
|
|
398
|
+
return None
|
|
399
|
+
declared = evidence.manifest.data.get("withheld") or {}
|
|
400
|
+
if not isinstance(declared, dict):
|
|
401
|
+
return None
|
|
402
|
+
for name, reason in declared.items():
|
|
403
|
+
name = str(name)
|
|
404
|
+
if name == key.id or (name.endswith(".*") and key.id.startswith(name[:-1])):
|
|
405
|
+
text, _ = unwrap(reason)
|
|
406
|
+
return name, str(text)
|
|
407
|
+
return None
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
def evaluate_key(key: EvidenceKey, evidence: Evidence, mapping: Mapping, show_content: bool = False) -> EvidenceResult:
|
|
411
|
+
declared = _withheld(key, evidence)
|
|
412
|
+
if declared:
|
|
413
|
+
# A manifest can declare evidence withheld that run telemetry cannot see, e.g. a
|
|
414
|
+
# remote grader behind a public harness. The declaration wins over the runs.
|
|
415
|
+
name, reason = declared
|
|
416
|
+
note = f"declared withheld in the manifest: {reason}"
|
|
417
|
+
pointer = f"{evidence.manifest.source}#/withheld/{name.replace('/', '~1')}"
|
|
418
|
+
withheld = KeyResult(NOT_FOUND, [Observation("manifest:withheld", [], [pointer], 0, note)], note)
|
|
419
|
+
if key.scope == "benchmark" or not evidence.runs:
|
|
420
|
+
return EvidenceResult(key=key, status=NOT_FOUND, per_run={}, benchmark=withheld)
|
|
421
|
+
return EvidenceResult(key=key, status=NOT_FOUND, per_run={run.id: withheld for run in evidence.runs})
|
|
422
|
+
if key.scope == "benchmark" or not evidence.runs:
|
|
423
|
+
# With no runs, run evidence can still come from the manifest.
|
|
424
|
+
result = _evaluate(key, None, evidence, mapping, show_content)
|
|
425
|
+
return EvidenceResult(key=key, status=result.status, per_run={}, benchmark=result)
|
|
426
|
+
per_run = {run.id: _evaluate(key, run, evidence, mapping, show_content) for run in evidence.runs}
|
|
427
|
+
status = combine([r.status for r in per_run.values()])
|
|
428
|
+
return EvidenceResult(key=key, status=status, per_run=per_run)
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
def runs_are_leaderboard(evidence: Evidence) -> bool:
|
|
432
|
+
if evidence.manifest is None or not evidence.runs:
|
|
433
|
+
return False
|
|
434
|
+
leaderboard = evidence.manifest.data.get("leaderboard")
|
|
435
|
+
if not isinstance(leaderboard, dict):
|
|
436
|
+
return False
|
|
437
|
+
value, _ = unwrap(leaderboard.get("runs_in_inputs"))
|
|
438
|
+
return value is True or str(value).strip().lower() in ("true", "yes")
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
def _item_status(item: Item, results: dict[str, EvidenceResult], leaderboard_runs: bool) -> str:
|
|
442
|
+
statuses = [results[k].status for k in item.required]
|
|
443
|
+
if item.asks_about_leaderboard:
|
|
444
|
+
options = []
|
|
445
|
+
if item.leaderboard_documented:
|
|
446
|
+
options.append(combine([results[k].status for k in item.leaderboard_documented]))
|
|
447
|
+
if leaderboard_runs and item.leaderboard_from_runs:
|
|
448
|
+
options.append(combine([results[k].status for k in item.leaderboard_from_runs]))
|
|
449
|
+
statuses.append(best(options))
|
|
450
|
+
return combine(statuses)
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
def _normal(name: Any) -> str:
|
|
454
|
+
return str(name).lower().replace("-", "_").replace(" ", "_")
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def input_warnings(mapping: Mapping, evidence: Evidence) -> list[str]:
|
|
458
|
+
"""Manifest typos, withheld keys that match nothing, and runs of a different benchmark."""
|
|
459
|
+
if evidence.manifest is None:
|
|
460
|
+
return []
|
|
461
|
+
data = evidence.manifest.data
|
|
462
|
+
warnings = [
|
|
463
|
+
f"manifest field `{name}` is not read by the mapping (check for a typo)"
|
|
464
|
+
for name in unknown_manifest_fields(mapping, data)
|
|
465
|
+
]
|
|
466
|
+
withheld = data.get("withheld")
|
|
467
|
+
if isinstance(withheld, dict):
|
|
468
|
+
for name in withheld:
|
|
469
|
+
name = str(name)
|
|
470
|
+
prefix = name[:-1] if name.endswith(".*") else None
|
|
471
|
+
if name not in mapping.evidence and not (prefix and any(k.startswith(prefix) for k in mapping.evidence)):
|
|
472
|
+
warnings.append(f"withheld entry `{name}` matches no evidence key (check for a typo)")
|
|
473
|
+
benchmark = data.get("benchmark") if isinstance(data.get("benchmark"), dict) else {}
|
|
474
|
+
names = unwrap(benchmark.get("task_names"))[0] or []
|
|
475
|
+
declared = [unwrap(benchmark.get("name"))[0]] + (list(names) if isinstance(names, list) else [names])
|
|
476
|
+
expected = {_normal(n) for n in declared if n}
|
|
477
|
+
if expected:
|
|
478
|
+
for task in dict.fromkeys(run.task for run in evidence.runs if run.task):
|
|
479
|
+
if _normal(task) not in expected:
|
|
480
|
+
shown = ", ".join(str(n) for n in declared if n)
|
|
481
|
+
warnings.append(
|
|
482
|
+
f"runs of task `{task}` do not match the manifest's benchmark ({shown}); "
|
|
483
|
+
"list the Inspect task names under benchmark.task_names"
|
|
484
|
+
)
|
|
485
|
+
return warnings
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
def unknown_manifest_fields(mapping: Mapping, data: dict[str, Any]) -> list[str]:
|
|
489
|
+
"""Manifest fields no mapping source reads, which are usually typos."""
|
|
490
|
+
known = mapping.manifest_paths() | MANIFEST_FIELDS
|
|
491
|
+
unknown: list[str] = []
|
|
492
|
+
|
|
493
|
+
def walk(node: Any, prefix: str) -> None:
|
|
494
|
+
for name, value in node.items():
|
|
495
|
+
path = f"{prefix}{name}"
|
|
496
|
+
if path in known:
|
|
497
|
+
continue
|
|
498
|
+
if isinstance(value, dict) and "value" not in value and any(k.startswith(path + ".") for k in known):
|
|
499
|
+
walk(value, path + ".")
|
|
500
|
+
else:
|
|
501
|
+
unknown.append(path)
|
|
502
|
+
|
|
503
|
+
walk(data, "")
|
|
504
|
+
return unknown
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
def assess(
|
|
508
|
+
evidence: Evidence, mapping: Mapping, with_conformance: bool = True, show_content: bool = False
|
|
509
|
+
) -> Assessment:
|
|
510
|
+
"""Score every rubric item. Values of `content: true` evidence are withheld unless `show_content`."""
|
|
511
|
+
from .signals import compute_signal
|
|
512
|
+
|
|
513
|
+
results = {key_id: evaluate_key(key, evidence, mapping, show_content) for key_id, key in mapping.evidence.items()}
|
|
514
|
+
leaderboard_runs = runs_are_leaderboard(evidence)
|
|
515
|
+
items = []
|
|
516
|
+
for item in mapping.items:
|
|
517
|
+
items.append(
|
|
518
|
+
ItemResult(
|
|
519
|
+
item=item,
|
|
520
|
+
status=_item_status(item, results, leaderboard_runs),
|
|
521
|
+
required=[results[k] for k in item.required],
|
|
522
|
+
supporting=[results[k] for k in item.supporting],
|
|
523
|
+
signals=[s for name in item.signals for s in compute_signal(name, evidence)],
|
|
524
|
+
leaderboard=[results[k] for k in item.leaderboard_documented],
|
|
525
|
+
from_runs=[results[k] for k in item.leaderboard_from_runs],
|
|
526
|
+
runs_are_leaderboard=leaderboard_runs,
|
|
527
|
+
)
|
|
528
|
+
)
|
|
529
|
+
warnings = list(evidence.warnings) + input_warnings(mapping, evidence)
|
|
530
|
+
conformance = None
|
|
531
|
+
if with_conformance and any(run.spans for run in evidence.runs):
|
|
532
|
+
from .conformance import summarize
|
|
533
|
+
|
|
534
|
+
conformance = summarize([s for run in evidence.runs for s in run.spans])
|
|
535
|
+
return Assessment(
|
|
536
|
+
mapping=mapping,
|
|
537
|
+
evidence=evidence,
|
|
538
|
+
items=items,
|
|
539
|
+
evidence_results=results,
|
|
540
|
+
generated_at=datetime.now(UTC).replace(microsecond=0).isoformat(),
|
|
541
|
+
conformance=conformance,
|
|
542
|
+
warnings=warnings,
|
|
543
|
+
)
|