karenina.benchmark¶
benchmark
¶
Benchmark module for Karenina verification system.
Classes¶
Benchmark
¶
Main class for managing Karenina benchmarks in JSON-LD format.
This class provides a high-level API for: - Creating benchmarks manually or automatically - Loading/saving JSON-LD benchmark files - Running verification with existing execution system - Full compatibility with frontend GUI exports
This is a facade that delegates to specialized manager classes for better maintainability.
Source code in src/karenina/benchmark/benchmark.py
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 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 | |
Attributes¶
is_scenario_benchmark
property
¶
True if this benchmark contains scenarios instead of standalone questions.
workspace_root
property
¶
Root directory for task workspaces (not persisted in checkpoint).
Functions¶
__init__
¶
__init__(
name: str,
description: str = "",
version: str = "0.1.0",
creator: str = "Karenina Benchmarking System",
workspace_root: Path | None = None,
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
¶ |
str
|
Name of the benchmark |
required |
description
¶ |
str
|
Description of the benchmark |
''
|
version
¶ |
str
|
Version of the benchmark content |
'0.1.0'
|
creator
¶ |
str
|
Creator name or organization |
'Karenina Benchmarking System'
|
workspace_root
¶ |
Path | None
|
Root directory containing task workspaces. Question workspace paths are resolved relative to this root. Not persisted in the checkpoint (it is a local filesystem path). |
None
|
Source code in src/karenina/benchmark/benchmark.py
add_answer_template
¶
Add or update an answer template for a question.
add_global_rubric_trait
¶
add_global_rubric_trait(
trait: LLMRubricTrait
| RegexRubricTrait
| CallableRubricTrait
| MetricRubricTrait
| AgenticRubricTrait,
) -> None
Add a global rubric trait to the benchmark.
Source code in src/karenina/benchmark/benchmark.py
add_question
¶
add_question(
question: Union[str, dict[str, Any], Question],
raw_answer: str | None = None,
answer_template: str | type | None = None,
question_id: str | None = None,
finished: bool | object = _NOT_PROVIDED,
author: dict[str, Any] | None = None,
sources: list[dict[str, Any]] | None = None,
custom_metadata: dict[str, Any] | None = None,
few_shot_examples: list[dict[str, str]] | None = None,
answer_notes: str | None = None,
) -> str
Add a question to the benchmark.
Accepts a question string, a Question object, or a dict with keys
question and raw_answer (plus any optional kwargs).
Raises:
| Type | Description |
|---|---|
ValueError
|
If scenarios already exist (homogeneous enforcement). |
Source code in src/karenina/benchmark/benchmark.py
add_question_from_object
¶
add_question_from_object(
question_obj: Question, **metadata: Any
) -> str
Add a question to the benchmark from a Question object.
add_question_rubric_trait
¶
add_question_rubric_trait(
question_id: str,
trait: LLMRubricTrait
| RegexRubricTrait
| CallableRubricTrait
| MetricRubricTrait
| AgenticRubricTrait,
) -> None
Add a question-specific rubric trait.
Source code in src/karenina/benchmark/benchmark.py
add_questions
¶
add_questions(
questions_data: Sequence[dict[str, Any] | Question],
finished: bool | object = _NOT_PROVIDED,
) -> list[str]
Add multiple questions at once.
Accepts a list of dicts, Question objects, or a mix of both.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
questions_data
¶ |
Sequence[dict[str, Any] | Question]
|
List of dicts or Question objects. |
required |
finished
¶ |
bool | object
|
Default finished state for items that do not define one. Pass False when importing items for template drafting and curator review. Omission preserves the existing default. |
_NOT_PROVIDED
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of question IDs that were created. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If scenarios already exist (homogeneous enforcement). |
Source code in src/karenina/benchmark/benchmark.py
add_questions_batch
¶
add_questions_batch(
questions_data: Sequence[dict[str, Any] | Question],
finished: bool | object = _NOT_PROVIDED,
) -> list[str]
Add multiple questions at once with an optional finished state.
Source code in src/karenina/benchmark/benchmark.py
add_scenario
¶
add_scenario(scenario: ScenarioDefinition | Any) -> None
Add a scenario to the benchmark.
Accepts either a ScenarioDefinition (frozen) or a Scenario builder (which will be validated and frozen automatically).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scenario
¶ |
ScenarioDefinition | Any
|
A ScenarioDefinition or a Scenario builder instance. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If standalone questions already exist (homogeneous enforcement), or if a scenario with the same name already exists. |
Source code in src/karenina/benchmark/benchmark.py
apply_global_template
¶
Apply a template to all questions that don't have one.
check_readiness
¶
clear_all_rubrics
¶
clear_global_rubric
¶
clear_questions
¶
clear_verification_results
¶
clear_verification_results(
question_ids: list[str] | None = None,
run_name: str | None = None,
) -> int
Clear verification results.
Source code in src/karenina/benchmark/benchmark.py
clone
¶
clone() -> Benchmark
Create a deep copy of the benchmark.
Source code in src/karenina/benchmark/benchmark.py
copy_template
¶
count_by_field
¶
Count questions grouped by a field value using dot notation.
Source code in src/karenina/benchmark/benchmark.py
create
classmethod
¶
create(
name: str,
description: str = "",
version: str = "0.1.0",
creator: str = "Karenina Benchmarking System",
workspace_root: Path | None = None,
) -> Benchmark
Create a new benchmark (alias for constructor).
Source code in src/karenina/benchmark/benchmark.py
export_generated_templates
¶
export_verification_results
¶
export_verification_results(
question_ids: list[str] | None = None,
run_name: str | None = None,
format: str = "json",
global_rubric: Rubric | None = None,
) -> str
Export verification results in specified format.
Source code in src/karenina/benchmark/benchmark.py
export_verification_results_to_file
¶
export_verification_results_to_file(
file_path: Path,
question_ids: list[str] | None = None,
run_name: str | None = None,
format: str | None = None,
global_rubric: Rubric | None = None,
) -> None
Export verification results directly to a file.
Source code in src/karenina/benchmark/benchmark.py
extend_rubric
¶
extend_rubric(
prior_results: VerificationResultSet,
config: VerificationConfig,
*,
run_name: str | None = None,
question_ids: list[str] | None = None,
async_enabled: bool | None = None,
progress_callback: Callable[[float, str], None]
| None = None,
sink: Any = None,
store: bool = True,
) -> VerificationResultSet
Attach a new rubric to a prior verification run.
Enriches every row of prior_results with rubric scores
produced against the rubric currently attached to this benchmark
(global and per-question). Answering is replayed from the prior
traces; template parsing and verification are skipped. Row count
is preserved: the merged set has the same shape as
prior_results with a populated rubric sub-object on each
row.
Trait scores are unioned with any rubric fields already present
on prior rows. Same-name trait collisions raise ValueError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prior_results
¶ |
VerificationResultSet
|
Result set from an earlier |
required |
config
¶ |
VerificationConfig
|
Verification configuration matching the shape of
|
required |
run_name
¶ |
str | None
|
Optional override for the merged run name. |
None
|
question_ids
¶ |
list[str] | None
|
Optional subset of question IDs. |
None
|
async_enabled
¶ |
bool | None
|
Forwarded to |
None
|
progress_callback
¶ |
Callable[[float, str], None] | None
|
Forwarded to |
None
|
sink
¶ |
Any
|
Optional :class: |
None
|
store
¶ |
bool
|
When True (default), write the merged set into the results manager. |
True
|
Returns:
| Type | Description |
|---|---|
VerificationResultSet
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
On input validation failure; see
:func: |
Source code in src/karenina/benchmark/benchmark.py
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 | |
extend_template
¶
extend_template(
prior_results: VerificationResultSet,
config: VerificationConfig,
*,
run_name: str | None = None,
question_ids: list[str] | None = None,
async_enabled: bool | None = None,
progress_callback: Callable[[float, str], None]
| None = None,
sink: Any = None,
store: bool = True,
) -> VerificationResultSet
Extend a prior verification run along any combination of three axes.
Axes, all optional and composable in a single call:
- New judges (
config.parsing_models). - New answerers (
config.answering_models). - More replicates (higher
config.replicate_count).
Prior (question, answerer, replicate) answering traces are served
from a :class:~karenina.replay.ReplayStore; new answerers, new
replicates, or any combination thereof run answering live. Parsing
always runs live. Triples already present in prior_results are
skipped so prior rows pass through verbatim. The merged output matches
a joint run over the full (answerers × judges × replicates) matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prior_results
¶ |
VerificationResultSet
|
Result set from an earlier |
required |
config
¶ |
VerificationConfig
|
Verification configuration describing the final
state (full union, not deltas): every judge in
|
required |
run_name
¶ |
str | None
|
Optional override for the merged run name. Defaults to
the run name carried by |
None
|
question_ids
¶ |
list[str] | None
|
Optional subset of question IDs to re-judge.
Defaults to every question present in |
None
|
async_enabled
¶ |
bool | None
|
Optional async control forwarded to
|
None
|
progress_callback
¶ |
Callable[[float, str], None] | None
|
Optional progress callback forwarded to
|
None
|
sink
¶ |
Any
|
Optional :class: |
None
|
store
¶ |
bool
|
When True (default), also store the merged set into the
in-memory results manager under |
True
|
Returns:
| Type | Description |
|---|---|
VerificationResultSet
|
Merged |
VerificationResultSet
|
newly-produced rows, all stamped with the effective |
Source code in src/karenina/benchmark/benchmark.py
1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 | |
filter_by_custom_metadata
¶
Filter questions by custom metadata fields with AND/OR logic.
Source code in src/karenina/benchmark/benchmark.py
filter_by_metadata
¶
filter_by_metadata(
field_path: str, value: Any, match_mode: str = "exact"
) -> list[dict[str, Any]]
Filter questions by a metadata field using dot notation.
Source code in src/karenina/benchmark/benchmark.py
filter_questions
¶
filter_questions(
finished: bool | None = None,
has_template: bool | None = None,
has_rubric: bool | None = None,
author: str | None = None,
custom_filter: Any = None,
) -> list[dict[str, Any]]
Filter questions based on criteria.
Source code in src/karenina/benchmark/benchmark.py
generate_all_templates
¶
generate_all_templates(
model: str = "claude-haiku-4-5",
model_provider: str = "anthropic",
temperature: float = 0,
interface: str = "langchain",
force_regenerate: bool = False,
progress_callback: Callable[
[TemplateProgressEvent], None
]
| None = None,
only_missing: bool = True,
endpoint_base_url: str | None = None,
endpoint_api_key: str | None = None,
progressive_backup: bool = True,
backup_path: Path | None = None,
max_workers: int | None = None,
cancel_event: Event | None = None,
) -> dict[str, dict[str, Any]]
Generate templates for all questions in the benchmark using LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
¶ |
str
|
Model name. |
'claude-haiku-4-5'
|
model_provider
¶ |
str
|
Model provider. |
'anthropic'
|
temperature
¶ |
float
|
Generation temperature. |
0
|
interface
¶ |
str
|
Adapter interface. |
'langchain'
|
force_regenerate
¶ |
bool
|
If True, regenerate existing templates. |
False
|
progress_callback
¶ |
Callable[[TemplateProgressEvent], None] | None
|
Optional progress callback. |
None
|
only_missing
¶ |
bool
|
If True, only generate for questions without templates. |
True
|
endpoint_base_url
¶ |
str | None
|
Optional custom endpoint URL. |
None
|
endpoint_api_key
¶ |
str | None
|
Optional API key for custom endpoint. |
None
|
progressive_backup
¶ |
bool
|
If True (default), save generated templates to a backup file after each successful generation so interrupted runs can be resumed. |
True
|
backup_path
¶ |
Path | None
|
Path for the backup file. Defaults to
|
None
|
max_workers
¶ |
int | None
|
Number of parallel workers. None reads from KARENINA_ASYNC_MAX_WORKERS env var (default 1). 1 = sequential. |
None
|
cancel_event
¶ |
Event | None
|
If set, stops generation after the current task(s) complete. |
None
|
Source code in src/karenina/benchmark/benchmark.py
generate_template_for_question
¶
generate_template_for_question(
question_id: str,
model: str = "claude-haiku-4-5",
model_provider: str = "anthropic",
temperature: float = 0,
interface: str = "langchain",
force_regenerate: bool = False,
endpoint_base_url: str | None = None,
endpoint_api_key: str | None = None,
) -> dict[str, Any]
Generate an answer template for a specific question using LLM.
Source code in src/karenina/benchmark/benchmark.py
generate_templates
¶
generate_templates(
question_ids: list[str],
model: str = "claude-haiku-4-5",
model_provider: str = "anthropic",
temperature: float = 0,
interface: str = "langchain",
force_regenerate: bool = False,
progress_callback: Callable[
[TemplateProgressEvent], None
]
| None = None,
endpoint_base_url: str | None = None,
endpoint_api_key: str | None = None,
max_workers: int | None = None,
cancel_event: Event | None = None,
) -> dict[str, dict[str, Any]]
Generate templates for multiple questions using LLM.
Source code in src/karenina/benchmark/benchmark.py
get_all_custom_properties
¶
get_all_questions
¶
get_all_run_names
¶
Get all verification run names.
Source code in src/karenina/benchmark/benchmark.py
get_custom_property
¶
get_finished_questions
¶
Get questions that are marked as finished.
get_finished_templates
¶
get_finished_templates(
question_ids: set[str] | None = None,
) -> list[FinishedTemplate]
Get all finished templates for verification.
get_global_dynamic_rubric
¶
get_global_dynamic_rubric() -> DynamicRubric | None
get_health_report
¶
get_merged_dynamic_rubric_for_question
¶
get_merged_dynamic_rubric_for_question(
question_id: str,
) -> DynamicRubric | None
Get merged dynamic rubric for a question (global + question-specific).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question_id
¶ |
str
|
The question ID. |
required |
Returns:
| Type | Description |
|---|---|
DynamicRubric | None
|
Merged DynamicRubric or None if neither global nor question-level exists. |
Source code in src/karenina/benchmark/benchmark.py
get_missing_templates
¶
Get questions that don't have non-default templates.
get_progress
¶
get_question
¶
get_question_author
¶
get_question_custom_property
¶
Get a custom property from question metadata.
get_question_ids
¶
get_question_metadata
¶
get_question_rubric
¶
get_question_rubric(question_id: str) -> Rubric | None
Get the question-specific rubric for a question.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question_id
¶ |
str
|
The question ID. |
required |
Returns:
| Type | Description |
|---|---|
Rubric | None
|
Rubric containing the question-specific traits, or None. |
Source code in src/karenina/benchmark/benchmark.py
get_question_sources
¶
get_question_timestamps
¶
Get creation and modification timestamps for a question.
get_questions_by_author
¶
get_questions_with_rubric
¶
get_results_statistics_by_run
¶
Get verification statistics for each run.
Source code in src/karenina/benchmark/benchmark.py
get_scenario
¶
get_scenario(name: str) -> ScenarioDefinition
Get a scenario by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
¶ |
str
|
The scenario name. |
required |
Returns:
| Type | Description |
|---|---|
ScenarioDefinition
|
The ScenarioDefinition. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no scenario with that name exists. |
Source code in src/karenina/benchmark/benchmark.py
get_scenarios
¶
get_scenarios() -> list[ScenarioDefinition]
Get all scenario definitions.
Returns:
| Type | Description |
|---|---|
list[ScenarioDefinition]
|
List of ScenarioDefinition instances. |
get_statistics
¶
get_summary
¶
get_template
¶
get_unfinished_questions
¶
Get questions that are not marked as finished.
get_verification_history
¶
get_verification_history(
question_id: str | None = None,
) -> dict[str, dict[str, VerificationResult]]
Get verification history organized by run name.
Source code in src/karenina/benchmark/benchmark.py
get_verification_results
¶
get_verification_results(
question_ids: list[str] | None = None,
run_name: str | None = None,
) -> dict[str, VerificationResult]
Get verification results for specific questions and/or runs.
Source code in src/karenina/benchmark/benchmark.py
get_verification_summary
¶
Get summary statistics for verification results.
Source code in src/karenina/benchmark/benchmark.py
has_template
¶
import_generated_templates
¶
Import templates from a JSON file generated by export_generated_templates.
Source code in src/karenina/benchmark/benchmark.py
load
classmethod
¶
load(
path: Path, workspace_root: Path | None = None
) -> Benchmark
Load a benchmark from a JSON-LD file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
¶ |
Path
|
Path to the JSON-LD benchmark file. |
required |
workspace_root
¶ |
Path | None
|
Optional root directory for task workspaces. |
None
|
Source code in src/karenina/benchmark/benchmark.py
load_from_db
classmethod
¶
load_from_db(
benchmark_name: str, storage: str
) -> Benchmark
Load a benchmark from a database.
Source code in src/karenina/benchmark/benchmark.py
load_verification_results_from_file
¶
load_verification_results_from_file(
file_path: Path, run_name: str | None = None
) -> dict[str, VerificationResult]
Load verification results from a previously exported file.
Source code in src/karenina/benchmark/benchmark.py
mark_finished
¶
mark_finished_batch
¶
mark_unfinished
¶
mark_unfinished_batch
¶
optimization_history
¶
optimization_history(
tracker_path: Path
| str = "~/.karenina/optimization_history.db",
limit: int = 20,
) -> list[OptimizationRun]
Get optimization history for this benchmark.
Source code in src/karenina/benchmark/benchmark.py
optimize
¶
optimize(
targets: list[str],
config: VerificationConfig | None = None,
train_ratio: float = 0.8,
val_ratio: float = 0.2,
test_ratio: float | None = None,
seed: int | None = None,
reflection_model: str = "openai/gpt-4o",
max_metric_calls: int = 150,
objective_config: ObjectiveConfig | None = None,
frontier_type: FrontierType = "objective",
seed_prompts: dict[str, str] | None = None,
tracker_path: Path | str | None = None,
export_preset_path: Path | str | None = None,
progress_callback: Callable[[float, str], None]
| None = None,
verbose: bool = False,
) -> KareninaOutput
Optimize text components using GEPA with karenina verification as the metric.
Requires the 'gepa' optional dependency: pip install karenina[gepa]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
targets
¶ |
list[str]
|
List of components to optimize. Valid values: "answering_system_prompt", "parsing_instructions", "mcp_tool_descriptions" |
required |
config
¶ |
VerificationConfig | None
|
Base VerificationConfig to use. If None, uses default minimal config. |
None
|
train_ratio
¶ |
float
|
Fraction of questions for training (default 0.8) |
0.8
|
val_ratio
¶ |
float
|
Fraction of questions for validation (default 0.2) |
0.2
|
test_ratio
¶ |
float | None
|
Optional fraction for testing. If None, no test set created. |
None
|
seed
¶ |
int | None
|
Random seed for reproducibility |
None
|
reflection_model
¶ |
str
|
Model for GEPA's reflection LLM (default: openai/gpt-4o) |
'openai/gpt-4o'
|
max_metric_calls
¶ |
int
|
Maximum GEPA optimization iterations (default: 150) |
150
|
objective_config
¶ |
ObjectiveConfig | None
|
Configuration for multi-objective optimization dimensions. |
None
|
frontier_type
¶ |
FrontierType
|
GEPA Pareto frontier tracking strategy. |
'objective'
|
seed_prompts
¶ |
dict[str, str] | None
|
Optional initial prompts. If None, uses empty strings. |
None
|
tracker_path
¶ |
Path | str | None
|
Optional path to SQLite file for tracking optimization history |
None
|
export_preset_path
¶ |
Path | str | None
|
Optional path to export optimized config as preset |
None
|
progress_callback
¶ |
Callable[[float, str], None] | None
|
Optional callback for progress updates (percentage, message) |
None
|
verbose
¶ |
bool
|
If True, display detailed progress during optimization |
False
|
Returns:
| Type | Description |
|---|---|
KareninaOutput
|
KareninaOutput with optimized prompts and metrics |
Example
result = benchmark.optimize( ... targets=["answering_system_prompt"], ... reflection_model="openai/gpt-4o", ... max_metric_calls=100, ... ) print(f"Improvement: {result.improvement:.1%}")
Source code in src/karenina/benchmark/benchmark.py
1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 | |
remove_custom_property
¶
remove_question
¶
remove_question_custom_property
¶
Remove a custom property from question metadata.
remove_question_rubric
¶
remove_scenario
¶
remove_scenario(name: str) -> None
Remove a scenario by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
¶ |
str
|
The scenario name. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no scenario with that name exists. |
Source code in src/karenina/benchmark/benchmark.py
resume_verification
¶
resume_verification(
state_path: str | Path,
*,
config: VerificationConfig | None = None,
question_ids: list[str] | None = None,
run_name: str | None = None,
async_enabled: bool | None = None,
progress_callback: Callable[[float, str], None]
| None = None,
) -> VerificationResultSet
Resume a progressive-save run from its .state file.
Reconstructs a :class:ProgressiveFileSink from state_path,
populates config.skip_triples via the sink, and delegates to
:meth:run_verification. The config stored in the state file is
used unless config is provided explicitly (useful for tweaking
e.g. request_timeout before the retry pass).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_path
¶ |
str | Path
|
Path to the |
required |
config
¶ |
VerificationConfig | None
|
Optional override config; defaults to the one snapshot in the state file. |
None
|
question_ids
¶ |
list[str] | None
|
Optional subset of questions. |
None
|
run_name
¶ |
str | None
|
Optional run label (defaults to the state's label). |
None
|
async_enabled
¶ |
bool | None
|
Override for async execution. |
None
|
progress_callback
¶ |
Callable[[float, str], None] | None
|
UI progress callback. |
None
|
Returns:
| Type | Description |
|---|---|
VerificationResultSet
|
The batch's :class: |
VerificationResultSet
|
results remain in the sink's buffer; the returned set reflects |
VerificationResultSet
|
whatever the executor produced in this resume pass. |
Source code in src/karenina/benchmark/benchmark.py
run_verification
¶
run_verification(
config: VerificationConfig,
question_ids: list[str] | None = None,
run_name: str | None = None,
async_enabled: bool | None = None,
progress_callback: Callable[[float, str], None]
| None = None,
sink: Any = None,
) -> VerificationResultSet
Run verification on the benchmark using existing execution system.
For scenario benchmarks, dispatches to _run_scenario_verification
which iterates over the scenario x model cross-product.
For standalone question benchmarks, delegates to VerificationManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
VerificationConfig
|
Verification configuration. |
required |
question_ids
¶ |
list[str] | None
|
Optional filter for which questions to run. |
None
|
run_name
¶ |
str | None
|
Optional run label. |
None
|
async_enabled
¶ |
bool | None
|
Whether to run in parallel. |
None
|
progress_callback
¶ |
Callable[[float, str], None] | None
|
Optional UI progress callback. |
None
|
sink
¶ |
Any
|
Optional :class: |
None
|
Source code in src/karenina/benchmark/benchmark.py
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 | |
save
¶
save(
path: Path, save_deep_judgment_config: bool = False
) -> None
Save the benchmark to a JSON-LD file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
¶ |
Path
|
Path where to save the benchmark. |
required |
save_deep_judgment_config
¶ |
bool
|
If True, include deep judgment configuration in LLM rubric traits. If False (default), deep judgment settings are stripped before saving. |
False
|
Source code in src/karenina/benchmark/benchmark.py
save_to_db
¶
save_to_db(
storage: str, checkpoint_path: Path | None = None
) -> Benchmark
Save this benchmark to a database.
Source code in src/karenina/benchmark/benchmark.py
search_questions
¶
search_questions(
query: str | list[str],
match_all: bool = True,
fields: list[str] | None = None,
case_sensitive: bool = False,
regex: bool = False,
) -> list[dict[str, Any]]
Search for questions containing the query text (unified search method).
Source code in src/karenina/benchmark/benchmark.py
set_custom_property
¶
set_global_dynamic_rubric
¶
set_global_dynamic_rubric(
dynamic_rubric: DynamicRubric | None,
) -> None
Set or clear the global dynamic rubric.
Persists the rubric to the checkpoint so it survives save/load cycles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dynamic_rubric
¶ |
DynamicRubric | None
|
The DynamicRubric to set, or None to clear. |
required |
Source code in src/karenina/benchmark/benchmark.py
set_metadata
¶
set_multiple_custom_properties
¶
set_question_author
¶
set_question_custom_property
¶
Set a custom property on question metadata.
set_question_rubric
¶
set_question_rubric(
question_id: str, rubric: Rubric
) -> None
Set the complete question-specific rubric (replaces existing).
set_question_sources
¶
Set source documents for a question.
set_workspace_root
¶
set_workspace_root(path: Path) -> None
Set the root directory for task workspaces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
¶ |
Path
|
Directory containing task workspace subdirectories. Question workspace paths are resolved relative to this root. |
required |
Source code in src/karenina/benchmark/benchmark.py
store_verification_results
¶
store_verification_results(
results: VerificationResultSet
| dict[str, VerificationResult],
run_name: str | None = None,
) -> None
Store verification results in the benchmark metadata.
Source code in src/karenina/benchmark/benchmark.py
to_csv
¶
to_dict
¶
to_markdown
¶
toggle_finished
¶
update_question_metadata
¶
update_template
¶
update_template(
question_id: str, template_code: str | type
) -> None
validate
¶
Validate the benchmark structure and all templates.
Source code in src/karenina/benchmark/benchmark.py
validate_rubrics
¶
validate_templates
¶
CurationWorkbookSummary
dataclass
¶
Summary returned after writing a benchmark curation workbook.
Source code in src/karenina/benchmark/curation_workbook.py
FinishedTemplate
¶
Bases: BaseModel
Metadata for a finished answer template.
Source code in src/karenina/schemas/verification/api_models.py
MaskStats
¶
ModelConfig
¶
Bases: BaseModel
Configuration for a single model.
Source code in src/karenina/schemas/config/models.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
Functions¶
validate_anthropic_connection_fields
¶
validate_anthropic_connection_fields() -> ModelConfig
Prevent Anthropic credentials from being silently ignored.
The dedicated fields are consumed by the Claude adapters and by Anthropic-backed LangChain adapters. Other interfaces must reject them so a configured credential can never fall back to the environment at a different host.
Source code in src/karenina/schemas/config/models.py
validate_interface_registered
¶
validate_interface_registered() -> ModelConfig
Validate that the interface is registered in AdapterRegistry.
Skips validation while the registry is initializing to avoid re-entrant initialization when registration modules create ModelConfig instances during _load_builtins().
Source code in src/karenina/schemas/config/models.py
validate_manual_interface
¶
validate_manual_interface() -> ModelConfig
Validate manual interface configuration and set defaults.
Source code in src/karenina/schemas/config/models.py
PostHocJudgment
dataclass
¶
Rubric scores for one stored row or parser-collapsed trace.
Source code in src/karenina/benchmark/verification/post_hoc.py
ProgressiveFileSink
¶
Append-only JSONL sidecar + .state manifest for crash recovery.
On disk during a run (paths relative to output_path):
<output>.state: JSON manifest. Contains the task manifest, the completed / failed triple sets, a config snapshot, and a config hash. Rewritten atomically on every completion.<output>.results.jsonl: one JSON-serialized :class:VerificationResultper line, appended as tasks complete.
On successful completion (:meth:on_finalize with all_complete=True):
- The JSONL sidecar is reassembled into the final frontend-export JSON
at
output_pathvia :func:export_verification_results_json_stream. - The
.stateand.results.jsonlfiles are deleted.
On partial completion (:meth:on_finalize with all_complete=False):
- Both sidecars are kept so
--resumecan continue.
Resume path: :meth:load_for_resume reads the state and JSONL and
returns a sink populated with the already-completed triples.
Source code in src/karenina/benchmark/verification/sinks.py
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 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 | |
Attributes¶
Functions¶
__init__
¶
__init__(
output_path: Path,
config: VerificationConfig,
benchmark_path: str,
global_rubric: Rubric | None = None,
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
¶ |
Path
|
Final export target (e.g. |
required |
config
¶ |
VerificationConfig
|
Verification configuration to snapshot into the state. |
required |
benchmark_path
¶ |
str
|
Path of the benchmark file, stored in the state for reference and diagnostics. |
required |
global_rubric
¶ |
Rubric | None
|
Optional rubric folded into the final export. |
None
|
Source code in src/karenina/benchmark/verification/sinks.py
completed_triples
¶
Return already-persisted triples for config.skip_triples.
Source code in src/karenina/benchmark/verification/sinks.py
get_all_results
¶
get_all_results() -> list[VerificationResult]
get_result_set
¶
get_result_set() -> VerificationResultSet
Return buffered results as a :class:VerificationResultSet.
iter_results
¶
iter_results() -> Iterable[VerificationResult]
Iterate over a snapshot of buffered completed results.
Used by the batch runner to hydrate the workspace
:class:AnswerTraceCache on resume so new parser variants for
already-completed answerer triples reuse the prior trace instead
of regenerating it. The snapshot is taken under the sink lock so
the iterator stays valid even if results land concurrently.
Source code in src/karenina/benchmark/verification/sinks.py
load_for_resume
classmethod
¶
load_for_resume(
state_path: Path,
*,
global_rubric: Rubric | None = None,
config_updater: Callable[
[VerificationConfig], VerificationConfig
]
| None = None,
manual_traces: Any | None = None,
) -> ProgressiveFileSink
Reconstruct a sink from an existing .state + JSONL pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_path
¶ |
Path
|
Path to the |
required |
global_rubric
¶ |
Rubric | None
|
Rubric to attach to the sink for final export. |
None
|
config_updater
¶ |
Callable[[VerificationConfig], VerificationConfig] | None
|
Optional transform applied to the rehydrated stored config, for example to re-inject secrets that pydantic masked when serializing the state file. |
None
|
manual_traces
¶ |
Any | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
ProgressiveFileSink
|
A |
ProgressiveFileSink
|
the set of triples already persisted, and whose internal |
ProgressiveFileSink
|
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
ValueError
|
If the state format version is incompatible. |
Source code in src/karenina/benchmark/verification/sinks.py
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 | |
mark_failed
¶
Record a task that was attempted but did not produce a result.
Optional helper for the batch runner so partial-failure state can
be preserved across resumes. Not part of the :class:ResultSink
protocol.
Source code in src/karenina/benchmark/verification/sinks.py
on_finalize
¶
Handle terminal state.
On all_complete=True, write the final frontend-export JSON at
:attr:output_path and remove the sidecars. On partial completion,
keep the sidecars intact so resume can continue.
Source code in src/karenina/benchmark/verification/sinks.py
on_result
¶
on_result(result: VerificationResult) -> None
Append a completed result to the JSONL and refresh the state.
The JSONL line is always written. The _completed set is
idempotent: scenario runs emit one on_result per turn, all
sharing the same combo-level task key (scenario_id-keyed), and the
combo is only marked complete once even though N turn lines are
appended. QA runs emit exactly one result per task so the guard
is a no-op.
Source code in src/karenina/benchmark/verification/sinks.py
on_start
¶
on_start(
manifest: list[str], config: VerificationConfig
) -> None
Record the manifest and write the initial state file.
Merge semantics: the stored manifest is unioned with the provided
one, preserving insertion order. This handles both the resume path
(provided manifest is a subset of the stored full manifest) and
the seeded-extend path (stored holds prior keys from
:meth:seed_prior_results, provided holds the new-task keys
from :func:generate_task_queue). Repeated keys are dropped.
Source code in src/karenina/benchmark/verification/sinks.py
open_or_resume
classmethod
¶
open_or_resume(
output_path: Path,
config: VerificationConfig,
benchmark_path: str,
*,
global_rubric: Rubric | None = None,
config_updater: Callable[
[VerificationConfig], VerificationConfig
]
| None = None,
) -> ProgressiveFileSink
Resume from an existing state sidecar or create a fresh sink.
Resumes when the .state sidecar for output_path exists,
otherwise creates parent directories and a fresh sink. On resume,
config is not used for the sink itself (the stored config is
rehydrated), but callers that rebuild their config each run should
keep passing the fresh config to run_verification, which
overwrites the sink's copy on start.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
¶ |
Path
|
Destination results file. |
required |
config
¶ |
VerificationConfig
|
Config for a fresh run. |
required |
benchmark_path
¶ |
str
|
Benchmark checkpoint path recorded in state. |
required |
global_rubric
¶ |
Rubric | None
|
Optional global rubric to attach. |
None
|
config_updater
¶ |
Callable[[VerificationConfig], VerificationConfig] | None
|
Optional transform applied to the rehydrated stored config on resume, for example to re-inject secrets. |
None
|
Returns:
| Type | Description |
|---|---|
ProgressiveFileSink
|
A fresh or resumed sink. |
Source code in src/karenina/benchmark/verification/sinks.py
seed_prior_results
¶
seed_prior_results(
prior_results: VerificationResultSet,
) -> None
Pre-populate JSONL, _results, _completed, _manifest.
Called by the extend_* facades before run_verification so
the sink's final export covers prior rows in addition to the new
rows produced by the pipeline. Idempotent: rows whose triple is
already tracked are skipped. Does not require :meth:on_start to
have run first; the JSONL file is created on demand.
Source code in src/karenina/benchmark/verification/sinks.py
write_final_export
¶
write_final_export(output_path: Path | None = None) -> Path
Assemble and atomically write the frontend-export JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
¶ |
Path | None
|
Destination. Defaults to :attr: |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The path the export was written to. |
Source code in src/karenina/benchmark/verification/sinks.py
RepairOutcome
¶
Bases: BaseModel
Paths and counts produced by a completed repair.
Source code in src/karenina/benchmark/verification/repair.py
RepairSelection
¶
Bases: BaseModel
Declarative row filters for completed-run repair.
Source code in src/karenina/benchmark/verification/repair.py
Functions¶
has_filters
¶
Return whether at least one explicit selection constraint exists.
Source code in src/karenina/benchmark/verification/repair.py
matches
¶
matches(result: VerificationResult) -> bool
Return whether a result satisfies every configured filter.
Source code in src/karenina/benchmark/verification/repair.py
ResultsIOManager
¶
Manager for verification result export and import operations.
Handles CSV and JSON serialization/deserialization logic for ResultsManager.
Source code in src/karenina/benchmark/core/results_io.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 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 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 | |
Functions¶
export_to_csv
staticmethod
¶
export_to_csv(
results: dict[str, VerificationResult],
global_rubric: Rubric | None = None,
) -> str
Export results to CSV format matching frontend format exactly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
¶ |
dict[str, VerificationResult]
|
Dictionary of verification results |
required |
global_rubric
¶ |
Rubric | None
|
Optional global rubric for trait separation |
None
|
Returns:
| Type | Description |
|---|---|
str
|
CSV string in frontend format |
Source code in src/karenina/benchmark/core/results_io.py
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 | |
export_to_json
staticmethod
¶
export_to_json(
results: dict[str, VerificationResult],
) -> str
Export results to JSON format matching frontend format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
¶ |
dict[str, VerificationResult]
|
Dictionary of verification results |
required |
Returns:
| Type | Description |
|---|---|
str
|
JSON string with results array including row_index |
Source code in src/karenina/benchmark/core/results_io.py
iter_from_json
staticmethod
¶
iter_from_json(
file_path: Path, *, raw: bool = False
) -> (
Iterator[VerificationResult] | Iterator[dict[str, Any]]
)
Stream rows from a results JSON export.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
¶ |
Path
|
Path to a v2.2 export or legacy array export. |
required |
raw
¶ |
bool
|
Yield dictionaries instead of validating current result models. |
False
|
Returns:
| Type | Description |
|---|---|
Iterator[VerificationResult] | Iterator[dict[str, Any]]
|
An iterator over results or raw row dictionaries. |
Source code in src/karenina/benchmark/core/results_io.py
load_from_csv
staticmethod
¶
load_from_csv(
file_path: Path,
) -> dict[str, VerificationResult]
Load results from CSV file, reconstructing nested VerificationResult objects.
Parses the flat CSV columns back into the nested sub-objects (metadata, template, rubric) that VerificationResult expects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
¶ |
Path
|
Path to the CSV file. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, VerificationResult]
|
Dictionary of loaded verification results keyed by "{question_id}_{row_index}". |
Source code in src/karenina/benchmark/core/results_io.py
load_from_json
staticmethod
¶
load_from_json(
file_path: Path,
) -> dict[str, VerificationResult]
Load results from JSON file supporting multiple formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
¶ |
Path
|
Path to the JSON file |
required |
Returns:
| Type | Description |
|---|---|
dict[str, VerificationResult]
|
Dictionary of loaded verification results |
Source code in src/karenina/benchmark/core/results_io.py
load_legacy_result_set
staticmethod
¶
load_legacy_result_set(
file_path: Path,
) -> VerificationResultSet
Load a legacy (v2.0/v2.1) verification export, migrating rows to the current schema.
Legacy exports predate nested ModelIdentity metadata and deterministic
result IDs, so load_result_set_from_json rejects their rows
(forbidden flat keys, missing answering/parsing/result_id).
This loader migrates each row instead: the forbidden flat keys are
dropped, answering_model/parsing_model strings
("provider/model") become ModelIdentity objects,
answering_replicate/parsing_replicate fold into replicate,
and a deterministic result_id is synthesized from question,
models, timestamp, and replicate when absent.
Non-legacy exports are delegated to load_result_set_from_json
unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
¶ |
Path
|
Path to a legacy (v2.0/v2.1) or current JSON export. |
required |
Returns:
| Type | Description |
|---|---|
VerificationResultSet
|
A validated result set built from the migrated rows. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any row fails migration; the message names every failing row index with its reason. |
Source code in src/karenina/benchmark/core/results_io.py
load_result_set_from_json
staticmethod
¶
load_result_set_from_json(
file_path: Path,
) -> VerificationResultSet
Load and validate a complete verification result set from JSON.
Unlike the legacy dictionary loader, this method preserves run metadata and compact scenario execution records when the export contains them. Malformed rows raise instead of being skipped, making this the preferred analysis path for saved experiment outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
¶ |
Path
|
Path to a standard JSON verification export. |
required |
Returns:
| Type | Description |
|---|---|
VerificationResultSet
|
A validated result set with optional scenario results and metadata. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the JSON shape or any result row is invalid. |
Source code in src/karenina/benchmark/core/results_io.py
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 | |
RowContext
dataclass
¶
Optional question and reference answer supplied to a row's judge.
Source code in src/karenina/benchmark/verification/post_hoc.py
RunDirectory
¶
Bases: BaseModel
Paths and mutable manifest lifecycle for one run directory.
Source code in src/karenina/benchmark/run_artifacts.py
Attributes¶
Functions¶
update_status
¶
update_status(
status: RunStatus,
*,
now: datetime | None = None,
error: BaseException | None = None,
) -> None
Update and persist the lifecycle status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
¶ |
RunStatus
|
New run status. |
required |
now
¶ |
datetime | None
|
Timestamp override for deterministic callers and tests. |
None
|
error
¶ |
BaseException | None
|
Failure recorded when status is |
None
|
Source code in src/karenina/benchmark/run_artifacts.py
write_manifest
¶
Persist the current manifest atomically.
RunManifest
¶
Bases: BaseModel
Machine-readable description of one verification run.
Source code in src/karenina/benchmark/run_artifacts.py
TemplateProgressEvent
dataclass
¶
Progress event emitted during template generation.
Consumers receive these via the progress_callback parameter. Job-level events (job_started, job_completed, job_cancelled) have question_id=None. Task-level events have the question_id set.
Source code in src/karenina/benchmark/benchmark_helpers.py
VerificationConfig
¶
Bases: BaseModel
Configuration for verification run with multiple models.
Source code in src/karenina/schemas/verification/config.py
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 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 | |
Attributes¶
rubric_enabled
property
¶
Whether rubric evaluation is enabled. Derived from evaluation_mode.
Functions¶
__init__
¶
Configuration precedence (highest to lowest): 1. Explicit arguments (including preset values) 2. Environment variables (only if set) 3. Field defaults
Source code in src/karenina/schemas/verification/config.py
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 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | |
create_preset_structure
classmethod
¶
create_preset_structure(
preset_id: str,
name: str,
description: str | None,
config_dict: dict[str, Any],
created_at: str,
updated_at: str,
) -> dict[str, Any]
Create preset structure. Delegates to config_presets.create_preset_structure.
Source code in src/karenina/schemas/verification/config.py
from_overrides
classmethod
¶
from_overrides(
base: VerificationConfig | None = None,
*,
answering_model: str | None = None,
answering_provider: str | None = None,
answering_id: str | None = None,
answering_interface: str | None = None,
parsing_model: str | None = None,
parsing_provider: str | None = None,
parsing_id: str | None = None,
parsing_interface: str | None = None,
temperature: float | None = None,
manual_traces: Any | None = None,
replicate_count: int | None = None,
abstention: bool | None = None,
sufficiency: bool | None = None,
embedding_check: bool | None = None,
deep_judgment_mode: str | None = None,
evaluation_mode: str | None = None,
embedding_threshold: float | None = None,
embedding_model: str | None = None,
async_execution: bool | None = None,
async_workers: int | None = None,
max_concurrent_requests: int | None = None,
use_full_trace_for_template: bool | None = None,
use_full_trace_for_rubric: bool | None = None,
deep_judgment_rubric_mode: str | None = None,
deep_judgment_rubric_excerpts: bool | None = None,
deep_judgment_rubric_max_excerpts: int | None = None,
deep_judgment_rubric_fuzzy_threshold: float
| None = None,
deep_judgment_rubric_retry_attempts: int | None = None,
deep_judgment_rubric_search: bool | None = None,
deep_judgment_rubric_search_tool: str | None = None,
deep_judgment_rubric_config: DeepJudgmentRubricCustomConfig
| dict[str, Any]
| None = None,
workspace_output_mode: Literal[
"none", "full", "produced"
]
| None = None,
workspace_output_dir: Path | None = None,
workspace_output_exclude_patterns: list[str]
| None = None,
) -> VerificationConfig
Create a VerificationConfig by applying overrides to an optional base config.
Implements the hierarchy: overrides > base config > defaults. Parameters set to None are not applied (base or default value is preserved).
This is the canonical way to construct a VerificationConfig with selective overrides, usable by CLI, server, and programmatic callers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
¶ |
VerificationConfig | None
|
Optional base config (e.g., from a preset). If None, starts from defaults. |
None
|
answering_model
¶ |
str | None
|
Override for the answering model name. |
None
|
answering_provider
¶ |
str | None
|
Override for the answering model provider. |
None
|
answering_id
¶ |
str | None
|
Override for the answering model identifier. |
None
|
answering_interface
¶ |
str | None
|
Override for the answering adapter interface. |
None
|
parsing_model
¶ |
str | None
|
Override for the parsing model name. |
None
|
parsing_provider
¶ |
str | None
|
Override for the parsing model provider. |
None
|
parsing_id
¶ |
str | None
|
Override for the parsing model identifier. |
None
|
parsing_interface
¶ |
str | None
|
Override for the parsing adapter interface. |
None
|
temperature
¶ |
float | None
|
Override for the LLM temperature. |
None
|
manual_traces
¶ |
Any | None
|
Override for manual traces data. |
None
|
replicate_count
¶ |
int | None
|
Override for the number of replicates. |
None
|
abstention
¶ |
bool | None
|
Override for abstention detection flag. |
None
|
sufficiency
¶ |
bool | None
|
Override for sufficiency checking flag. |
None
|
embedding_check
¶ |
bool | None
|
Override for embedding check flag. |
None
|
deep_judgment_mode
¶ |
str | None
|
Override for template deep judgment mode. |
None
|
evaluation_mode
¶ |
str | None
|
Override for evaluation mode. |
None
|
embedding_threshold
¶ |
float | None
|
Override for embedding similarity threshold. |
None
|
embedding_model
¶ |
str | None
|
Override for embedding model name. |
None
|
async_execution
¶ |
bool | None
|
Override for async execution flag. |
None
|
async_workers
¶ |
int | None
|
Override for number of async workers. |
None
|
max_concurrent_requests
¶ |
int | None
|
Override for global concurrent LLM request cap. |
None
|
use_full_trace_for_template
¶ |
bool | None
|
Override for full trace template flag. |
None
|
use_full_trace_for_rubric
¶ |
bool | None
|
Override for full trace rubric flag. |
None
|
deep_judgment_rubric_mode
¶ |
str | None
|
Override for deep judgment rubric mode. |
None
|
deep_judgment_rubric_excerpts
¶ |
bool | None
|
Override for rubric excerpts flag. |
None
|
deep_judgment_rubric_max_excerpts
¶ |
int | None
|
Override for max rubric excerpts. |
None
|
deep_judgment_rubric_fuzzy_threshold
¶ |
float | None
|
Override for rubric fuzzy threshold. |
None
|
deep_judgment_rubric_retry_attempts
¶ |
int | None
|
Override for rubric retry attempts. |
None
|
deep_judgment_rubric_search
¶ |
bool | None
|
Override for rubric search flag. |
None
|
deep_judgment_rubric_search_tool
¶ |
str | None
|
Override for rubric search tool. |
None
|
deep_judgment_rubric_config
¶ |
DeepJudgmentRubricCustomConfig | dict[str, Any] | None
|
Override for rubric config dict. |
None
|
workspace_output_mode
¶ |
Literal['none', 'full', 'produced'] | None
|
Override for workspace sidecar capture mode. |
None
|
workspace_output_dir
¶ |
Path | None
|
Override for workspace sidecar output directory. |
None
|
workspace_output_exclude_patterns
¶ |
list[str] | None
|
Additional workspace sidecar exclude patterns. |
None
|
Returns:
| Type | Description |
|---|---|
VerificationConfig
|
A new VerificationConfig with overrides applied. |
Source code in src/karenina/schemas/verification/config.py
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 | |
from_preset
classmethod
¶
from_preset(filepath: Path) -> VerificationConfig
Load a VerificationConfig from a preset file. Delegates to config_presets.load_preset.
get_few_shot_config
¶
get_few_shot_config() -> FewShotConfig | None
Get the FewShotConfig for this verification run.
Returns:
| Type | Description |
|---|---|
FewShotConfig | None
|
The FewShotConfig to use, or None if few-shot is disabled |
is_few_shot_enabled
¶
Check if few-shot prompting is enabled.
Returns:
| Type | Description |
|---|---|
bool
|
True if few-shot is enabled |
Source code in src/karenina/schemas/verification/config.py
sanitize_model_config
classmethod
¶
Sanitize model configuration. Delegates to config_presets.sanitize_model_config.
sanitize_preset_name
classmethod
¶
Convert preset name to safe filename. Delegates to config_presets.sanitize_preset_name.
save_preset
¶
save_preset(
name: str,
description: str | None = None,
presets_dir: Path | None = None,
) -> dict[str, Any]
Save this config as a preset file. Delegates to config_presets.save_preset.
Source code in src/karenina/schemas/verification/config.py
validate_preset_metadata
classmethod
¶
Validate preset metadata. Delegates to config_presets.validate_preset_metadata.
Source code in src/karenina/schemas/verification/config.py
VerificationJob
¶
Bases: BaseModel
Represents a verification job.
Source code in src/karenina/schemas/verification/job.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 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 | |
Functions¶
task_finished
¶
task_finished(
question_id: str,
success: bool,
replicate: int | None = None,
) -> None
Mark a task as finished, calculate duration, and update counts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question_id
¶ |
str
|
The question identifier |
required |
success
¶ |
bool
|
Whether the task completed successfully |
required |
replicate
¶ |
int | None
|
Optional replicate number (for multi-replicate runs) |
None
|
Source code in src/karenina/schemas/verification/job.py
task_started
¶
task_started(
question_id: str, replicate: int | None = None
) -> None
Mark a task as started and record start time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question_id
¶ |
str
|
The question identifier |
required |
replicate
¶ |
int | None
|
Optional replicate number (for multi-replicate runs) |
None
|
Source code in src/karenina/schemas/verification/job.py
to_dict
¶
Convert job to dictionary for API response.
Source code in src/karenina/schemas/verification/job.py
VerificationResult
¶
Bases: BaseModel
Result of verifying a single question.
Source code in src/karenina/schemas/verification/result.py
Functions¶
abstention_detection_instruction
¶
count_deep_judgment_reasoning_tokens
¶
count_deep_judgment_reasoning_tokens(
answer: str,
trait: LLMRubricTrait,
*,
question: str = "",
task_eval_mode: bool = True,
encoding_name: str = "o200k_base",
parsing_model: ModelConfig | None = None,
timeout: float = 10.0,
) -> int
Count the rendered first-stage deep-judgment reasoning prompt.
The count includes both system and user messages. It uses the stable
offline encoding named by encoding_name and does not contact a model
provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Response or trace passed to the reasoning stage. |
required |
|
LLMRubricTrait
|
Deep-judgment rubric trait. |
required |
|
str
|
Question rendered when TaskEval mode is disabled. |
''
|
|
bool
|
Whether to use TaskEval prompt rendering. |
True
|
|
str
|
Tiktoken encoding used for an offline count. |
'o200k_base'
|
|
ModelConfig | None
|
Optional OpenAI-compatible model whose |
None
|
|
float
|
Endpoint timeout in seconds. |
10.0
|
Returns:
| Type | Description |
|---|---|
int
|
Token count for the complete reasoning prompt. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If an exact endpoint count fails. |
Source code in src/karenina/benchmark/verification/utils/token_budget.py
count_tokens
¶
Count tokens in text under the requested tiktoken encoding.
create_run_directory
¶
create_run_directory(
root: Path,
label: str,
*,
benchmark_path: str | Path,
config: VerificationConfig,
run_name: str | None = None,
selected_question_count: int | None = None,
now: datetime | None = None,
resume: bool = False,
) -> RunDirectory
Create a timestamped run directory and running manifest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Parent directory for verification runs. |
required |
|
str
|
Filesystem-safe reviewer-facing run label. |
required |
|
str | Path
|
Benchmark source recorded for provenance. |
required |
|
VerificationConfig
|
Verification configuration to describe and sanitize. |
required |
|
str | None
|
Result metadata run name. Defaults to |
None
|
|
int | None
|
Number of questions selected for this run. |
None
|
|
datetime | None
|
Timestamp override for deterministic callers and tests. |
None
|
|
bool
|
Reopen the timestamped directory when it already exists. |
False
|
Returns:
| Type | Description |
|---|---|
RunDirectory
|
Newly created run directory descriptor. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the label is unsafe. |
FileExistsError
|
If the timestamped directory exists without resume. |
Source code in src/karenina/benchmark/run_artifacts.py
evaluate_rubric_on_results
¶
evaluate_rubric_on_results(
results: Iterable[VerificationResult],
rubric: Rubric,
parsing_model: ModelConfig,
*,
text_selector: Callable[[VerificationResult], str]
| None = None,
row_context: Callable[[VerificationResult], RowContext]
| None = None,
row_filter: Callable[[VerificationResult], bool]
| None = None,
rubric_factory: Callable[
[VerificationResult, Rubric], Rubric
]
| None = None,
sibling_identity: Callable[
[VerificationResult], Hashable
]
| None = None,
collapse_parser_siblings: bool = True,
max_workers: int = 4,
) -> Iterator[PostHocJudgment]
Judge stored result rows, optionally once per generated trace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Iterable[VerificationResult]
|
Stored verification results. |
required |
|
Rubric
|
Traits to evaluate. |
required |
|
ModelConfig
|
Model used by traits that require an LLM. |
required |
|
Callable[[VerificationResult], str] | None
|
Optional stored-text selector. |
None
|
|
Callable[[VerificationResult], RowContext] | None
|
Optional question and reference-answer selector. |
None
|
|
Callable[[VerificationResult], bool] | None
|
Optional predicate used to exclude rows. |
None
|
|
Callable[[VerificationResult, Rubric], Rubric] | None
|
Optional factory for a row-specific rubric. |
None
|
|
Callable[[VerificationResult], Hashable] | None
|
Optional parser-independent grouping identity. |
None
|
|
bool
|
Judge rows sharing trace identity once. |
True
|
|
int
|
Maximum concurrent row evaluations. |
4
|
Yields:
| Type | Description |
|---|---|
PostHocJudgment
|
Post-hoc judgments with every represented row key in |
Source code in src/karenina/benchmark/verification/post_hoc.py
evaluate_rubric_on_texts
¶
evaluate_rubric_on_texts(
items: Iterable[PostHocItem],
rubric: Rubric,
parsing_model: ModelConfig,
*,
max_workers: int = 4,
) -> Iterator[PostHocJudgment]
Judge prepared key, text, and context triples against a rubric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Iterable[PostHocItem]
|
Prepared stored-text evaluation inputs. |
required |
|
Rubric
|
Traits to evaluate. |
required |
|
ModelConfig
|
Model used by traits that require an LLM. |
required |
|
int
|
Maximum concurrent row evaluations. |
4
|
Yields:
| Type | Description |
|---|---|
PostHocJudgment
|
One judgment per input, in completion order when concurrent. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/karenina/benchmark/verification/post_hoc.py
export_curation_workbook
¶
export_curation_workbook(
benchmark: Benchmark, output_path: str | Path
) -> CurationWorkbookSummary
Write a field-level workbook for benchmark curation and review.
Template source is parsed with :mod:ast and is never executed by this
exporter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Benchmark
|
Benchmark to export. |
required |
|
str | Path
|
Destination |
required |
Returns:
| Type | Description |
|---|---|
CurationWorkbookSummary
|
Counts and the resolved workbook path. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the destination is not an Excel workbook path. |
OSError
|
If the workbook cannot be written. |
Source code in src/karenina/benchmark/curation_workbook.py
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 | |
export_verification_results_csv
¶
export_verification_results_csv(
job: VerificationJob,
results: VerificationResultSet,
global_rubric: HasTraitNames | None = None,
) -> str
Export verification results to CSV format with rubric consolidation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
VerificationJob
|
The verification job |
required |
|
VerificationResultSet
|
VerificationResultSet containing all verification results |
required |
|
HasTraitNames | None
|
Optional global rubric object that implements HasTraitNames protocol for distinguishing global vs question-specific traits. If None, all rubric traits will be consolidated into question_specific_rubrics. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
CSV string with results. Global rubric traits appear as dedicated columns |
str
|
(rubric_TraitName), while question-specific traits are consolidated into |
str
|
a single JSON column (question_specific_rubrics). |
Note
The function gracefully handles errors in trait name extraction and JSON serialization, logging warnings and continuing with fallback values.
Source code in src/karenina/benchmark/verification/stages/helpers/results_exporter.py
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 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 | |
export_verification_results_json_stream
¶
export_verification_results_json_stream(
job: VerificationJob,
results_iter: Iterable[VerificationResult],
global_rubric: HasTraitNames | None = None,
*,
is_complete: bool = False,
scenario_results: Iterable[Any] | None = None,
out_path: Path,
) -> None
Stream the v2.2 JSON export directly to out_path.
Writes to out_path.with_suffix(out_path.suffix + '.partial') and
atomically renames it into place on success. On any exception raised
by the iterator or I/O, removes the .partial file and reraises.
The on-disk schema matches the v2.2 export format byte-for-byte at the top-level keys and per-result fields; only whitespace differs (compact outer + one compact JSON line per result, separated by ",\n").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
VerificationJob
|
The verification job whose metadata heads the export. |
required |
|
Iterable[VerificationResult]
|
Single-pass iterable over VerificationResult. Lists, generators, and JSONL-backed iterators all work. |
required |
|
HasTraitNames | None
|
Optional rubric folded into shared_data. Must expose
either a |
None
|
|
bool
|
Written into |
False
|
|
Path
|
Target path (required kwarg, no default). |
required |
Source code in src/karenina/benchmark/verification/stages/helpers/results_exporter.py
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 | |
format_trace_messages
¶
Format stored message records using Karenina's canonical trace format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Iterable[Message | Mapping[str, Any]]
|
Live |
required |
Returns:
| Type | Description |
|---|---|
str
|
The canonical raw trace, including assistant text, tool calls, and tool |
str
|
results. |
Source code in src/karenina/benchmark/trace.py
managed_run_directory
¶
managed_run_directory(
root: Path,
label: str,
*,
benchmark_path: str | Path,
config: VerificationConfig,
run_name: str | None = None,
selected_question_count: int | None = None,
now: datetime | None = None,
resume: bool = False,
) -> Iterator[RunDirectory]
Create a run directory and maintain its terminal manifest status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Parent directory for verification runs. |
required |
|
str
|
Filesystem-safe reviewer-facing run label. |
required |
|
str | Path
|
Benchmark source recorded for provenance. |
required |
|
VerificationConfig
|
Verification configuration to describe and sanitize. |
required |
|
str | None
|
Result metadata run name. Defaults to |
None
|
|
int | None
|
Number of selected questions. |
None
|
|
datetime | None
|
Creation timestamp override. |
None
|
|
bool
|
Reopen the timestamped directory when it already exists. |
False
|
Yields:
| Type | Description |
|---|---|
RunDirectory
|
The running directory descriptor. |
Source code in src/karenina/benchmark/run_artifacts.py
mask_graphql_schema_messages
¶
mask_graphql_schema_messages(trace: str) -> MaskStats
Mask GraphQL schema introspection responses in tool messages.
Source code in src/karenina/benchmark/verification/utils/trace_masking.py
mask_run_configuration
¶
mask_run_configuration(
configuration: Mapping[str, JsonValue],
) -> dict[str, JsonValue]
Return a JSON configuration snapshot with credential fields masked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Mapping[str, JsonValue]
|
Configuration mapping to sanitize. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, JsonValue]
|
A deep copy safe to write into a run manifest. |
Source code in src/karenina/benchmark/run_artifacts.py
repair_results_export
¶
repair_results_export(
benchmark: _RepairBenchmark,
source_path: Path,
config: VerificationConfig,
selection: RepairSelection
| Callable[[VerificationResult], bool],
*,
mode: RepairMode = "replay",
output_path: Path | None = None,
dry_run: bool = False,
now: datetime | None = None,
) -> RepairOutcome
Rerun and splice selected rows of a completed JSON export.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
_RepairBenchmark
|
Loaded |
required |
|
Path
|
Completed result export to load with |
required |
|
VerificationConfig
|
Full model configuration corresponding to the source run. |
required |
|
RepairSelection | Callable[[VerificationResult], bool]
|
Declarative filters or a Python predicate. |
required |
|
RepairMode
|
|
'replay'
|
|
Path | None
|
Destination. Defaults to replacing |
None
|
|
bool
|
Select and report rows without model calls or file changes. |
False
|
|
datetime | None
|
Timestamp override for backup and provenance names. |
None
|
Returns:
| Type | Description |
|---|---|
RepairOutcome
|
Repair paths, counts, mode, and selected identities. |
Source code in src/karenina/benchmark/verification/repair.py
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 | |
run_question_verification
¶
run_question_verification(
question_id: str,
question_text: str,
template_code: str,
answering_model: ModelConfig,
parsing_model: ModelConfig,
run_name: str | None = None,
replicate: int | None = None,
rubric: Rubric | None = None,
dynamic_rubric: DynamicRubric | None = None,
keywords: list[str] | None = None,
raw_answer: str | None = None,
few_shot_examples: list[dict[str, str]] | None = None,
few_shot_enabled: bool = False,
abstention_enabled: bool = False,
sufficiency_enabled: bool = False,
deep_judgment_mode: str = "disabled",
rubric_evaluation_strategy: str = "batch",
deep_judgment_max_excerpts_per_attribute: int = DEFAULT_DEEP_JUDGMENT_MAX_EXCERPTS,
deep_judgment_fuzzy_match_threshold: float = DEFAULT_DEEP_JUDGMENT_FUZZY_THRESHOLD,
deep_judgment_excerpt_retry_attempts: int = DEFAULT_DEEP_JUDGMENT_RETRY_ATTEMPTS,
deep_judgment_search_enabled: bool = False,
deep_judgment_search_tool: str | Any = "tavily",
deep_judgment_rubric_mode: str = "disabled",
deep_judgment_rubric_global_excerpts: bool = True,
deep_judgment_rubric_config: DeepJudgmentRubricCustomConfig
| None = None,
deep_judgment_rubric_max_excerpts_default: int = DEFAULT_RUBRIC_MAX_EXCERPTS,
deep_judgment_rubric_fuzzy_match_threshold_default: float = DEFAULT_DEEP_JUDGMENT_FUZZY_THRESHOLD,
deep_judgment_rubric_excerpt_retry_attempts_default: int = DEFAULT_DEEP_JUDGMENT_RETRY_ATTEMPTS,
deep_judgment_rubric_search_enabled: bool = False,
deep_judgment_rubric_search_tool: str | Any = "tavily",
evaluation_mode: str = "template_only",
cached_answer_data: dict[str, Any] | None = None,
prompt_config: PromptConfig | None = None,
use_full_trace_for_template: bool = False,
use_full_trace_for_rubric: bool = True,
allow_partial_trace_scoring: bool = True,
agentic_parsing: bool = False,
agentic_parsing_trigger: str = "always",
agentic_judge_context: str = "workspace_only",
agentic_parsing_max_turns: int = 15,
agentic_parsing_timeout: float = 120.0,
agentic_parsing_materialize_trace: bool = False,
agentic_parsing_persist_trace: bool = False,
workspace_root: Path | None = None,
workspace_copy: bool = True,
workspace_cleanup: bool = True,
workspace_output_mode: str = "none",
workspace_output_dir: Path | None = None,
workspace_output_exclude_patterns: list[str]
| None = None,
question_workspace_path: str | None = None,
agentic_rubric_strategy: str = "individual",
agentic_rubric_parallel: bool = False,
embedding_check_enabled: bool = False,
embedding_check_model: str | None = None,
embedding_check_threshold: float | None = None,
trait_provenance: dict[str, str] | None = None,
custom_error_patterns: list[ErrorPatternConfig]
| None = None,
replay_store: Any = None,
replay_parse_on_hydration_mismatch: str = "fall_through",
task_eval_mode: bool = False,
callable_registry: dict[str, RubricCallable]
| None = None,
) -> VerificationResult
Run verification for a single question with specific answering and parsing models.
This function uses a stage-based pipeline architecture for modularity and testability. Each verification step (validation, generation, parsing, verification, etc.) is implemented as a discrete stage that can be independently tested and configured.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Unique identifier for the question. For manual interface, this MUST be a 32-character hexadecimal MD5 hash (generated during question extraction). |
required |
|
str
|
The question to ask the LLM |
required |
|
str
|
Python code defining the Answer class |
required |
|
ModelConfig
|
Configuration for the answering model |
required |
|
ModelConfig
|
Configuration for the parsing model |
required |
|
str | None
|
Optional run name for tracking |
None
|
|
int | None
|
Optional replicate number for repeated runs of the same question |
None
|
|
Rubric | None
|
Optional rubric for qualitative evaluation |
None
|
|
list[str] | None
|
Optional keywords associated with the question |
None
|
|
list[dict[str, str]] | None
|
Optional list of question-answer pairs for few-shot prompting |
None
|
|
bool
|
Whether to use few-shot prompting (disabled by default) |
False
|
|
bool
|
Whether to enable abstention detection |
False
|
|
bool
|
Whether to enable trace sufficiency detection |
False
|
|
str
|
Template deep-judgment mode ("disabled", "reasoning_only", "full") |
'disabled'
|
|
str
|
Strategy for evaluating LLM rubric traits: - "batch": All traits evaluated in single LLM call (default, efficient) - "sequential": Traits evaluated one-by-one (reliable, more expensive) |
'batch'
|
|
dict[str, RubricCallable] | None
|
Runtime callable overrides keyed by callable trait name. |
None
|
|
int
|
Max excerpts per attribute (deep-judgment) |
DEFAULT_DEEP_JUDGMENT_MAX_EXCERPTS
|
|
float
|
Similarity threshold for excerpts (deep-judgment) |
DEFAULT_DEEP_JUDGMENT_FUZZY_THRESHOLD
|
|
int
|
Retry attempts for excerpt validation (deep-judgment) |
DEFAULT_DEEP_JUDGMENT_RETRY_ATTEMPTS
|
|
bool
|
Whether to enable search enhancement (deep-judgment) |
False
|
|
str | Any
|
Search tool name or callable (deep-judgment) |
'tavily'
|
|
str
|
Evaluation mode determining which stages run: - "template_only": Template verification only (default) - "template_and_rubric": Template verification + rubric evaluation - "rubric_only": Skip template, only evaluate rubrics on raw response |
'template_only'
|
|
dict[str, Any] | None
|
Optional cached answer data from previous generation. If provided, the GenerateAnswerStage will skip LLM invocation and use this cached data. Used to share answers across multiple judges. |
None
|
Returns:
| Type | Description |
|---|---|
VerificationResult
|
VerificationResult with all details and optional rubric scores |
Raises:
| Type | Description |
|---|---|
ValueError
|
If question_id is not a valid MD5 hash when using manual interface |
RuntimeError
|
If stage orchestration fails critically |
Source code in src/karenina/benchmark/verification/runner.py
52 53 54 55 56 57 58 59 60 61 62 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 | |
select_repair_rows
¶
select_repair_rows(
results: Iterable[VerificationResult],
selection: RepairSelection
| Callable[[VerificationResult], bool],
) -> list[VerificationResult]
Select completed rows for repair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Iterable[VerificationResult]
|
Validated verification results. |
required |
|
RepairSelection | Callable[[VerificationResult], bool]
|
Declarative filters or a Python predicate. |
required |
Returns:
| Type | Description |
|---|---|
list[VerificationResult]
|
Selected rows in source order. |
Source code in src/karenina/benchmark/verification/repair.py
splice_repaired_rows
¶
splice_repaired_rows(
original: Iterable[VerificationResult],
replacements: Iterable[VerificationResult],
) -> list[VerificationResult]
Replace exact row identities while preserving source order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Iterable[VerificationResult]
|
Complete original result rows. |
required |
|
Iterable[VerificationResult]
|
Newly evaluated rows with matching identities. |
required |
Returns:
| Type | Description |
|---|---|
list[VerificationResult]
|
Original rows with exact matching replacements spliced in. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If either input contains duplicates or a replacement has no corresponding original row. |
Source code in src/karenina/benchmark/verification/repair.py
truncate_to_token_budget
¶
truncate_to_token_budget(
text: str,
max_tokens: int,
encoding_name: str = "o200k_base",
) -> tuple[str, bool]
Middle-truncate text so its encoded form fits a token budget.
The head and tail are retained around an omission marker so both the beginning of a trace and its final messages remain available to a judge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Text to constrain. |
required |
|
int
|
Positive maximum number of encoded tokens. |
required |
|
str
|
Tiktoken encoding used to count and truncate. |
'o200k_base'
|
Returns:
| Type | Description |
|---|---|
tuple[str, bool]
|
The possibly truncated text and whether truncation occurred. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/karenina/benchmark/verification/utils/token_budget.py
validate_answer_template
¶
validate_answer_template(
template_code: str,
) -> tuple[bool, str | None, type | None]
Validate that template code defines a proper Answer class.
Discovers the answer class by scanning for the leaf BaseAnswer subclass, supporting custom class names (not just "Answer").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Python source code defining a BaseAnswer subclass. |
required |
Returns:
| Type | Description |
|---|---|
tuple[bool, str | None, type | None]
|
Tuple of (is_valid, error_message, Answer_class). |