Safety Benchmark¶
safety_benchmark
¶
Safety Benchmark — standardised performance benchmarks for safety controls.
Evaluates detection latency, false-positive/negative rates, coverage, throughput, and resource cost of the sandbox's safety controls under controlled, reproducible workloads. Produces benchmark reports with grading, comparisons across configurations, and regression detection.
Use it to answer: "Are our safety controls fast enough, accurate enough, and complete enough?"
Usage (Python API)::
from replication.safety_benchmark import (
SafetyBenchmark, BenchmarkSuite, BenchmarkConfig,
ControlUnderTest, Workload,
)
bench = SafetyBenchmark()
# Run the full suite
report = bench.run_suite(BenchmarkSuite.STANDARD)
print(report.summary())
print(f"Overall grade: {report.grade}")
# Benchmark a single control
result = bench.run_one(ControlUnderTest.KILL_SWITCH)
print(f"Latency p50: {result.latency_p50_ms:.1f}ms")
print(f"False positive rate: {result.false_positive_rate:.2%}")
# Compare two configurations
baseline = bench.run_suite(BenchmarkSuite.STANDARD)
candidate = bench.run_suite(BenchmarkSuite.STANDARD)
diff = bench.compare(baseline, candidate)
for d in diff.regressions:
print(f"âš {d.control}: {d.metric} regressed {d.delta:+.1f}")
# Export
report.to_json("benchmark.json")
CLI::
python -m replication safety-benchmark --suite standard
python -m replication safety-benchmark --control kill-switch
python -m replication safety-benchmark --suite stress --iterations 50
python -m replication safety-benchmark --compare baseline.json candidate.json
python -m replication safety-benchmark --format json --output bench.json
ControlUnderTest
¶
Bases: Enum
Safety controls that can be benchmarked.
Source code in src/replication/safety_benchmark.py
BenchmarkSuite
¶
BenchmarkGrade
¶
WorkloadIntensity
¶
Workload
dataclass
¶
A benchmark workload definition.
Source code in src/replication/safety_benchmark.py
BenchmarkConfig
dataclass
¶
Configuration for a benchmark run.
Source code in src/replication/safety_benchmark.py
LatencyStats
dataclass
¶
Latency statistics for a benchmark.
Source code in src/replication/safety_benchmark.py
ControlBenchmarkResult
dataclass
¶
Result of benchmarking a single safety control.
Source code in src/replication/safety_benchmark.py
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 | |
RegressionItem
dataclass
¶
A single regression detected in a comparison.
Source code in src/replication/safety_benchmark.py
ComparisonReport
dataclass
¶
Comparison of two benchmark runs.
Source code in src/replication/safety_benchmark.py
BenchmarkReport
dataclass
¶
Full benchmark report.
Source code in src/replication/safety_benchmark.py
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 | |
summary() -> str
¶
Human-readable summary.
Source code in src/replication/safety_benchmark.py
to_json(path: Optional[str] = None) -> str
¶
Serialise to JSON. If path is given, also write to file.
Source code in src/replication/safety_benchmark.py
from_json(text: str) -> 'BenchmarkReport'
classmethod
¶
Deserialise a report from JSON.
Source code in src/replication/safety_benchmark.py
SafetyBenchmark
¶
Runs standardised safety control benchmarks.
Source code in src/replication/safety_benchmark.py
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 | |
run_one(control: ControlUnderTest, config: Optional[BenchmarkConfig] = None) -> ControlBenchmarkResult
¶
Benchmark a single safety control.
Source code in src/replication/safety_benchmark.py
run_suite(suite: BenchmarkSuite = BenchmarkSuite.STANDARD, config: Optional[BenchmarkConfig] = None) -> BenchmarkReport
¶
Run a predefined benchmark suite.
Source code in src/replication/safety_benchmark.py
compare(baseline: BenchmarkReport, candidate: BenchmarkReport, regression_threshold: float = 0.05) -> ComparisonReport
¶
Compare two benchmark reports and find regressions/improvements.
Source code in src/replication/safety_benchmark.py
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 | |
main(argv: Optional[list] = None) -> None
¶
CLI entry point for safety benchmarks.
Source code in src/replication/safety_benchmark.py
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 | |