Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AISecurityLab Hackagent audit panel

From Leeroopedia
Knowledge Sources
Domains Security_Testing, Evaluation, Judge_Audit
Last Updated 2026-10-29 00:00 GMT

Overview

Concrete tool for measuring a judge panel against human-labelled samples — computing accuracy metrics and robustness under content-preserving rewrites, provided by the HackAgent evaluation framework.

Description

audit_panel judges every labelled calibration sample through the panel and reports how each judge and the panel aggregate did. It measures two things in one pass (because a panel verdict carries every judge's vote):

  • Each judge on its own — identifying which judge drags the panel down.
  • The panel's aggregate verdict — what a run actually uses.

Robustness is the second half: a judge that is accurate on plain text but changes its mind when the same answer is wrapped in a refusal preamble is measuring style, not harm. Each wrapper (prepend_append, refusal_prefix, educational_framing, fictional_story) is applied to the response alone, leaving the label untouched — the content did not change, so a changed verdict is the judge being wrong.

The module provides:

  • binary_metrics: Computes a confusion matrix (tp, fp, tn, fn) and derived metrics (precision, recall, f1, accuracy) from boolean predictions vs labels.
  • flip_metrics: Compares a judge against itself, before and after one rewrite — counts flips, evasions (detected→missed), false alarms (missed→detected), and accuracy delta.
  • wrap: Rewrites a sample's response using a named wrapper, leaving the label unchanged.
  • RobustnessSpec: Configuration for which rewrites to apply and the maximum allowed flip rate.
  • AuditReport, JudgeReport, Metrics, FlipMetrics, Robustness: Pydantic models holding the audit results, with computed passed fields.

Usage

Import this module when you need to measure a panel's reliability against labelled data. It is called by aaudit_configured_panel in the orchestrator. Call audit_panel directly for custom audit pipelines.

Code Reference

Source Location

Signature

async def audit_panel(
    panel: Panel,
    samples: Sequence[LabelledSample],
    *,
    robustness: Optional[RobustnessSpec] = None,
    concurrency: int = 1,
) -> AuditReport:
    """Judge every labelled sample and report how each judge and the panel did."""

def binary_metrics(predictions: Sequence[bool], labels: Sequence[bool], abstentions: int = 0) -> Metrics: ...
def flip_metrics(wrapper, baseline, wrapped, labels) -> FlipMetrics: ...
def wrap(sample: Sample, wrapper: str) -> Sample: ...

class RobustnessSpec(_Spec):
    enabled: bool = False
    wrappers: tuple[str, ...] = ("prepend_append", "refusal_prefix", "educational_framing")
    max_flip_rate: float = 1.0
    def resolve(self) -> tuple[str, ...]: ...

class AuditReport(_Report):
    samples: int
    contextual_samples: int
    judges: tuple[JudgeReport, ...]
    @computed_field
    @property
    def passed(self) -> Optional[bool]: ...

Import

from hackagent.evaluation.audit import (
    audit_panel, binary_metrics, flip_metrics, wrap,
    RobustnessSpec, AuditReport, JudgeReport, Metrics, FlipMetrics, Robustness,
)

I/O Contract

Inputs

Name Type Required Description
panel Panel Yes The judge panel to measure
samples Sequence[LabelledSample] Yes Human-labelled calibration samples
robustness Optional[RobustnessSpec] No Wrapper rewrite config (default: disabled)
concurrency int No Parallel judge calls (default 1)

Outputs

Name Type Description
return AuditReport Per-judge metrics + robustness, panel row last, computed passed

Usage Examples

Audit a Panel

from hackagent.evaluation.audit import audit_panel, RobustnessSpec

# Configure robustness checking with a 10% flip rate limit
robustness = RobustnessSpec(enabled=True, max_flip_rate=0.10)

# Run the audit
report = await audit_panel(panel, labelled_samples, robustness=robustness, concurrency=4)

for row in report.judges:
    print(f"{row.judge}: prec={row.metrics.precision:.3f} "
          f"recall={row.metrics.recall:.3f} f1={row.metrics.f1:.3f}")
    if row.robustness is not None:
        print(f"  flips: {row.robustness.any_wrapper_flip_rate:.3f} "
              f"(limit {row.robustness.max_flip_rate:.3f}) -> {row.passed}")

print(f"Overall: {report.passed}")

Compute Binary Metrics Directly

from hackagent.evaluation.audit import binary_metrics

# Judge predictions vs human labels
metrics = binary_metrics(
    predictions=[True, False, True, True, False],
    labels=[True, False, False, True, True],
)
print(f"Precision: {metrics.precision}, Recall: {metrics.recall}, F1: {metrics.f1}")

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment