Public API¶
This page lists the public API. Everything not listed here is implementation detail.
Anything under clean_evals._internal may change without notice. The public
surface follows SemVer; breaking changes ratchet majors. Pre-1.0, minor
versions may break the public API with a CHANGELOG.md entry.
Stability tags¶
— won't change without a major bump.
— may change at minor bumps with deprecation notice.
Data models¶
clean_evals.Case ¶
Bases: _FrozenStrictModel
A single eval input + optional expected output.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Stable identifier within the dataset. Allowed characters: alphanumerics, underscore, dash, dot, colon. No spaces. |
input |
dict[str, Any]
|
Free-form structured input passed to the prompt template. |
expected |
dict[str, Any] | None
|
Expected output for the case. |
tags |
list[str]
|
Free-form tags used for filtering and per-tag accuracy breakdowns. |
metadata |
dict[str, Any]
|
Free-form metadata. Not used by the runner; passed through to reporters. |
locked |
bool
|
When |
Example
Case(id="case_001", input={"text": "I love it"}, expected={"label": "positive"}) Case(id='case_001', ...)
Source code in src/clean_evals/models.py
clean_evals.Dataset ¶
Bases: _StrictModel
A versioned collection of Case rows plus its scoring configuration.
Datasets are immutable once tagged: once locked_at is set on the
backing storage row, the version is sealed and any edit must produce a new
version. Historical runs against v1 remain comparable after v2 ships.
The scorer field names a scorer registered under the
clean_evals.scorers entry-point group. scorer_config is passed
verbatim to Scorer.from_config.
Loading from YAML
Dataset.from_yaml("examples/sentiment/dataset.yml") # doctest: +SKIP
Source code in src/clean_evals/models.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
from_yaml
classmethod
¶
Load a dataset from a YAML file.
The YAML may inline cases, or reference a sidecar JSONL via
cases_jsonl: ./path/to/cases.jsonl relative to the YAML.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the YAML file. |
required |
scrubber
|
Scrubber | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
A validated |
Source code in src/clean_evals/models.py
to_yaml ¶
Write the dataset to a YAML file.
Cases are inlined. For large datasets, write JSONL separately and reference it from the YAML — but that's a workflow you do by hand.
Source code in src/clean_evals/models.py
clean_evals.ModelResponse ¶
Bases: _FrozenStrictModel
A single model invocation's output and accounting.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
Raw response text. |
parsed |
dict[str, Any] | None
|
|
tokens_in |
int
|
Input tokens reported by the provider. |
tokens_out |
int
|
Output tokens reported by the provider. |
latency_ms |
int
|
Wall-clock latency including network. Adapter-measured. |
cost_usd |
float
|
Computed via |
raw |
dict[str, Any]
|
Provider response as a dict, for debugging and per-case diff. |
Source code in src/clean_evals/models.py
clean_evals.ScoreResult ¶
Bases: _FrozenStrictModel
Output of a single scorer invocation.
Attributes:
| Name | Type | Description |
|---|---|---|
score |
float
|
Normalised 0.0–1.0 score. Required. |
passed |
bool
|
Whether this counts as a "pass" for leaderboard purposes.
Scorers decide their own threshold; |
breakdown |
dict[str, float]
|
Optional sub-component scores for richer reporting
(e.g. |
notes |
str | None
|
Optional free-form text — handy for LLM-judge rationales. |
Source code in src/clean_evals/models.py
clean_evals.CaseResult ¶
Bases: _FrozenStrictModel
One (case, model) outcome.
A model erroring (timeout, 5xx, content filter, schema-invalid output)
produces a CaseResult with the appropriate status rather than
crashing the run. Reports distinguish wrong answers from infrastructure
errors so a model that 500s on 30% of cases is not "70% accurate."
Attributes:
| Name | Type | Description |
|---|---|---|
case_id |
str
|
Foreign key to |
model |
str
|
Snapshot model id (e.g. |
status |
_RUN_STATUS
|
|
response |
ModelResponse | None
|
The model's response, or |
score |
ScoreResult | None
|
Scorer output, or |
error |
str | None
|
Captured error payload when |
started_at, |
finished_at
|
UTC timestamps with microsecond precision. |
Source code in src/clean_evals/models.py
clean_evals.RunConfig ¶
Bases: _StrictModel
Configuration for a single eval run.
Attributes:
| Name | Type | Description |
|---|---|---|
models |
list[str]
|
Snapshot model ids only — floating aliases ending in
|
model_params |
dict[str, ModelParams]
|
Per-model parameters keyed by model id (see
:class: |
concurrency |
dict[str, int]
|
Optional per-provider concurrency caps. Empty = uncapped (the runner backs off on 429 anyway). |
timeout_s |
float
|
Per-call timeout, in seconds. Adapter-enforced. |
retries |
int
|
Retries on transient failures (429, 5xx, network errors). |
seed |
int | None
|
Provider seed for determinism. |
temperature |
float
|
Sampling temperature. |
max_cost_usd |
float
|
Best-effort ceiling for the run. Spend is checked as
results arrive; cases that have not started when the ceiling
trips are aborted with |
Source code in src/clean_evals/models.py
clean_evals.ModelSummary ¶
Bases: _FrozenStrictModel
Per-model leaderboard row in a RunResult.
Attributes:
| Name | Type | Description |
|---|---|---|
cost_per_correct_usd |
float | None
|
Cost per passed case. |
pricing_version |
str
|
The frozen pricing table version used for cost attribution. Rerunning under newer pricing creates a new run; old summaries still report the spend that was actually charged. |
Source code in src/clean_evals/models.py
clean_evals.RunResult ¶
Bases: _StrictModel
Top-level result for a single Runner.run invocation.
Reporters consume this. Storage persists this. The Decision UI renders this. It is the unit of comparison.
Source code in src/clean_evals/models.py
Runner¶
clean_evals.Runner ¶
Run a Dataset against a list of models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapters
|
dict[str, ModelAdapter] | None
|
Mapping from provider id to adapter instance. |
None
|
scorer_registry_obj
|
Any
|
Custom registry. Most callers leave this |
None
|
prompt_template
|
str | None
|
How to render a case's input as a single prompt
string. |
None
|
event_sink
|
EventSink | None
|
Optional progress sink. Default no-op for headless runs. |
None
|
daily_cost_so_far_usd
|
float | None
|
How much was spent today before this run
started. |
None
|
Example
import asyncio from clean_evals import Dataset, Runner, RunConfig ds = Dataset( # doctest: +SKIP ... name="hello", version="v1", scorer="exact_match", cases=[], ... ) runner = Runner() # doctest: +SKIP result = asyncio.run(runner.run( # doctest: +SKIP ... ds, RunConfig(models=["gpt-4o-mini-2024-07-18"]), ... ))
Source code in src/clean_evals/runner.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 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 241 242 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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |
aclose
async
¶
Close HTTP clients of adapters this runner created lazily.
Source code in src/clean_evals/runner.py
run
async
¶
Run dataset against config.models.
Source code in src/clean_evals/runner.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 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 241 242 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 | |
run_sync ¶
Synchronous wrapper. Spins up a fresh event loop and blocks.
Adapters the runner instantiated itself are closed before the loop is torn down (their HTTP clients are bound to it). Explicitly injected adapters stay open — the caller owns their lifecycle.
Source code in src/clean_evals/runner.py
Plugin protocols¶
clean_evals.Scorer ¶
Bases: Protocol
Computes a 0.0–1.0 quality score for a model's output.
Implementations should be pure: same (case, response) always yields
the same ScoreResult. Anything stochastic (LLM judges) should be
seeded so the run is reproducible.
Class attributes
name: The registry key under which this scorer is discoverable.
Datasets reference it via Dataset.scorer.
Source code in src/clean_evals/protocols.py
clean_evals.ModelAdapter ¶
Bases: Protocol
Talks to a single model provider.
Adapters MUST:
- Be
async-native (usehttpx.AsyncClient, neverrequests). - Validate that the requested
modelis a dated snapshot. Floating aliases like-latestare rejected atRunConfigvalidation, but adapters should also defend in depth. - Return
ModelResponse.cost_usdpopulated viaclean_evals.pricingusing the prompt's actual token counts. - On HTTP 429, raise
RateLimitedwith theRetry-Aftervalue if present so the runner can back off. - On other transient failures, raise the standard exception types from
:mod:
clean_evals.errorsso the runner can retry consistently.
Source code in src/clean_evals/protocols.py
clean_evals.Reporter ¶
Bases: Protocol
Writes a RunResult to a destination.
Reporters are invoked synchronously after the run completes. Each
reporter MAY write multiple files; write returns the path of the
primary artifact (the one humans/CI typically open first).
Source code in src/clean_evals/protocols.py
clean_evals.Scrubber ¶
Bases: Protocol
Optional plugin for cleaning PII / sensitive data during dataset load.
Called by Dataset.from_yaml(..., scrubber=...) once per case after
parsing. Implementations must be pure — same input, same output.