recall_guard.core.loader
recall_guard.core.loader
Generic JSONL evaluation-set loader and cutoff-date guard.
Implements the input-source-agnostic JSONL contract for the honest-model-ranking harness (Req 2.1-2.5):
EvalRow/EvalSetfrozen dataclasses describe the in-memory shape.load_eval_set(path)parses an optional_cutoff_dateheader line plus one{prompt, target_direction[, metadata]}row per line. It validates the row schema strictly (raisesValueErroron bad rows) and emitslogging.WARNINGrecords for low-N (<100) and class-imbalance (>60%) conditions, rather than raising.load_cutoffs(path)parsesdata/cutoffs.yamlof shape{models: {model_id: YYYY-MM-DD}}into adict[str, date].assert_cutoff_safe(eval_set, models, cutoffs)enforces the cutoff guard: every shortlisted model must appear incutoffs, and no model's training cutoff may post-date the eval set's declaredcutoff_date. Violations raiseCutoffViolation.
The loader never performs a train/dev split (Req 2.4): the entire file is the evaluation set.
CutoffViolation
Bases: Exception
Raised when shortlisted models post-date the eval set's cutoff.
Source code in recall_guard/core/loader.py
44 45 | |
EvalRow
dataclass
One evaluation row: prompt + ground-truth direction + opaque metadata.
Source code in recall_guard/core/loader.py
48 49 50 51 52 53 54 | |
EvalSet
dataclass
A loaded JSONL eval set plus its cutoff header and content hash.
Source code in recall_guard/core/loader.py
57 58 59 60 61 62 63 | |
load_eval_set
load_eval_set(path)
Parse a JSONL eval file into an EvalSet.
The first line may optionally be a header object containing
{"_cutoff_date": "YYYY-MM-DD"}. All other lines must be row objects
matching the input contract (Req 2.1). Logs WARNING records for low-N
and class-imbalance conditions (Req 2.2, 2.3); never raises for those.
Returns the entire set as a single list with no train/dev split (Req 2.4).
Source code in recall_guard/core/loader.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
parse_metadata_date
parse_metadata_date(raw)
Normalise an eval-row metadata.date value to a date.
The shared contract for every post-harness consumer (orchestrator,
gap analyzer, backtest): accept plain YYYY-MM-DD and any ISO-8601
datetime whose first ten characters are the date (2024-06-30T00:00:00).
Returns None for non-strings and unparseable values so callers can
skip the row instead of crashing.
Source code in recall_guard/core/loader.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
load_cutoffs
load_cutoffs(path)
Parse the cutoffs YAML registry into {model_id: cutoff_date}.
Source code in recall_guard/core/loader.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
assert_cutoff_safe
assert_cutoff_safe(eval_set, models, cutoffs)
Fail-fast guard: every shortlisted model has a cutoff <= eval cutoff.
Raises:
CutoffViolation: if any model is missing from cutoffs or, when
eval_set.cutoff_date is set, post-dates it.
Source code in recall_guard/core/loader.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |