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 CampaignSpec

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

Overview

Concrete tool for defining the complete schema of an AI red-team campaign — what to attack, with what, and how to judge it — provided by the HackAgent orchestrator.

Description

CampaignSpec is a frozen pydantic model that holds the entire declarative campaign specification. It reads top to bottom as the run does: load the dataset, send every goal through each of the attacks to the target (optionally behind guardrails), score the replies with the evaluation judges, and run it all under the execution policy. All sub-specs (CampaignMetadata, AttackSpec, EvaluationSpec, ExecutionSpec, AuditSpec, GuardrailsSpec, OutputSpec, StorageSpec, etc.) are frozen pydantic models with extra="forbid", so unknown keys are rejected at load time. The spec also carries a recorded() method that produces a credential-redacted dict for storage and reproducibility.

Usage

  • Loading campaigns: Created by load_campaign from a YAML file or mapping; pass to resolve_campaign to build runtime objects.
  • Dry-run validation: Construct directly via CampaignSpec.model_validate() to check a campaign without running it.
  • Reproducibility: Call recorded() on a spec to get a redacted dict safe to persist alongside run results.

Code Reference

Source Location

Signature

class CampaignSpec(_Spec):
    """A complete campaign: what to attack, with what, and how to judge it."""

    version: Literal[1] = Field(description="Version of the campaign format. Always 1.")
    campaign: CampaignMetadata = Field(description="Name and description of the run.")
    dataset: CampaignDatasetSpec = Field(description="Where the goals come from and which of them to run.")
    target: ModelConfig = Field(description="The model or agent under test.")
    guardrails: GuardrailsSpec = Field(default_factory=GuardrailsSpec)
    attacks: tuple[AttackSpec, ...] = Field(min_length=1, description="The attack techniques to run. At least one.")
    evaluation: EvaluationSpec = Field(default_factory=EvaluationSpec)
    execution: ExecutionSpec = Field(default_factory=ExecutionSpec)

    def recorded(self) -> dict[str, Any]:
        """The campaign as it is written to disk and stored with the run (credentials redacted)."""

Import

from hackagent.orchestrator.campaign.spec import CampaignSpec

I/O Contract

Inputs

Name Type Required Description
data dict[str, Any] Yes Raw YAML-decoded mapping to validate via model_validate

Outputs

Name Type Description
return CampaignSpec Frozen, validated campaign specification instance
recorded() dict[str, Any] Credential-redacted dict safe for storage/reproducibility

Usage Examples

Validate a Campaign Dict

from hackagent.orchestrator.campaign.spec import CampaignSpec

spec = CampaignSpec.model_validate({
    "version": 1,
    "campaign": {"name": "Flipattack multi-judge"},
    "dataset": {"source": {"preset": "harmbench_standard"}},
    "target": {"name": "victim", "connection": {"type": "litellm", "model": "gpt-4o"}},
    "attacks": [{"name": "flipattack"}],
    "evaluation": {
        "judges": [{"name": "judge-1", "connection": {"type": "litellm", "model": "gpt-4o-mini"}}],
        "aggregation": "majority",
    },
})
print(f"Loaded: {spec.campaign.name}, {len(spec.attacks)} attacks, {len(spec.evaluation.judges)} judges")

Generate JSON Schema for Editor Autocomplete

from hackagent.orchestrator.campaign.spec import campaign_json_schema

# Print the campaign format as a JSON Schema document
import json
print(json.dumps(campaign_json_schema(), indent=2))

Related Pages

Implements Principle

Page Connections

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