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
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 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 | |
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: list[dict[str, Any]],
) -> list[str]
Add multiple questions at once.
Each dict is passed to add_question(), so all dict keys supported
there are accepted here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
questions_data
¶ |
list[dict[str, Any]]
|
List of dicts with question data. |
required |
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_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
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 = "gemini-2.0-flash",
model_provider: str = "google_genai",
temperature: float = 0,
interface: str = "langchain",
force_regenerate: bool = False,
progress_callback: Callable[[float, str], None]
| None = None,
only_missing: bool = True,
endpoint_base_url: str | None = None,
endpoint_api_key: str | None = None,
) -> dict[str, dict[str, Any]]
Generate templates for all questions in the benchmark using LLM.
Source code in src/karenina/benchmark/benchmark.py
generate_template_for_question
¶
generate_template_for_question(
question_id: str,
model: str = "gemini-2.0-flash",
model_provider: str = "google_genai",
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 = "gemini-2.0-flash",
model_provider: str = "google_genai",
temperature: float = 0,
interface: str = "langchain",
force_regenerate: bool = False,
progress_callback: Callable[[float, str], None]
| None = None,
endpoint_base_url: str | None = None,
endpoint_api_key: str | 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_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_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_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.
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.
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
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 | |
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
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,
) -> 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.
Source code in src/karenina/benchmark/benchmark.py
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_global_rubric
¶
set_global_rubric(rubric: Rubric) -> None
Set the complete global rubric (replaces existing).
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).
Source code in src/karenina/benchmark/benchmark.py
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
¶
FinishedTemplate
¶
Bases: BaseModel
Metadata for a finished answer template.
Source code in src/karenina/schemas/verification/api_models.py
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 | |
Functions¶
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
VerificationConfig
¶
Bases: BaseModel
Configuration for verification run with multiple models.
Source code in src/karenina/schemas/verification/config.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 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 | |
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
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 | |
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: bool | 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,
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: dict[str, Any]
| 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
¶ |
bool | None
|
Override for deep judgment flag. |
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
|
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
¶ |
dict[str, Any] | None
|
Override for rubric config dict. |
None
|
Returns:
| Type | Description |
|---|---|
VerificationConfig
|
A new VerificationConfig with overrides applied. |
Source code in src/karenina/schemas/verification/config.py
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 | |
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 |
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¶
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
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 | |
export_verification_results_json
¶
export_verification_results_json(
job: VerificationJob,
results: VerificationResultSet,
global_rubric: HasTraitNames | None = None,
) -> str
Export verification results to JSON format with metadata (v2.0 format).
The v2.0 format optimizations: - Stores rubric definition once in shared_data (not per-result) - Stores trace filtering fields (evaluation_input, used_full_trace, trace_extraction_error) at result root level (shared by template and rubric evaluation) - 50-70% size reduction compared to legacy format
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
VerificationJob
|
The verification job |
required |
|
VerificationResultSet
|
VerificationResultSet containing all verification results |
required |
|
HasTraitNames | None
|
Optional global rubric to include in shared_data for rubric definition |
None
|
Returns:
| Type | Description |
|---|---|
str
|
JSON string with results and metadata in v2.0 format |
Source code in src/karenina/benchmark/verification/stages/helpers/results_exporter.py
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_enabled: bool = False,
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: dict[str, Any]
| 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,
agentic_parsing: bool = False,
agentic_judge_context: str = "workspace_only",
agentic_parsing_max_turns: int = 15,
agentic_parsing_timeout: float = 120.0,
workspace_root: Path | None = None,
workspace_copy: bool = True,
workspace_cleanup: bool = True,
question_workspace_path: str | None = None,
agentic_rubric_strategy: str = "individual",
agentic_rubric_parallel: bool = False,
) -> 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
|
|
bool
|
Whether to enable deep-judgment parsing |
False
|
|
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'
|
|
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
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 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 | |
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). |