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:0xSteph Pentest ai Playbook from dict

From Leeroopedia
Knowledge Sources
Domains Security_Testing, Methodology
Last Updated 2026-10-23 12:00 GMT

Overview

Concrete YAML playbook parser that validates and constructs a Playbook dataclass from a raw dict, enforcing safety constraints like refusing bare credential keys.

Description

The Playbook.from_dict classmethod parses a raw dict (typically from `yaml.safe_load()`) into a Playbook dataclass. It validates required fields (name, phases), refuses bare credential keys (password, token, secret — use auth_profile instead), and constructs Phase and PlaybookInput objects.

The Playbook dataclass contains: name, description, version, authors, intensity, inputs, phases, path, auth_profile.

The Phase dataclass contains: id, tools, depends_on, condition, args, manual, checklist.

Validation (via `validate()`) checks: duplicate phase IDs, dangling dependencies, intensity constraints (stealth/normal/aggressive).

Usage

Import this when you need to:

  • Parse a YAML playbook file into a Playbook dataclass
  • Validate a playbook's structure and safety constraints
  • Load, discover, or find playbooks by name or path

Code Reference

Source Location

Signature

@dataclass
class Playbook:
    name: str
    description: str = ""
    version: str = "0.1.0"
    authors: list[str] = field(default_factory=list)
    intensity: str = "normal"
    inputs: dict[str, PlaybookInput] = field(default_factory=dict)
    phases: list[Phase] = field(default_factory=list)
    path: str = ""
    auth_profile: str = ""

    @classmethod
    def from_dict(cls, raw: dict[str, Any], path: str = "") -> Playbook:
        """Parse from raw dict. Raises PlaybookError on invalid input."""

    def validate(self) -> None:
        """Raise PlaybookError on semantic issues (dupes, dangling deps, ...)."""

def load_playbook(path: str | Path) -> Playbook:
    """Load and validate a single playbook from a YAML file."""

def discover_playbooks(extra_dirs: list[Path] | None = None) -> list[Playbook]:
    """Return all playbooks found under builtin + user + extra directories."""

def find_playbook(name_or_path: str) -> Playbook:
    """Resolve by bare name (searches builtin + user dirs) or by path."""

Import

from engine.playbook import Playbook, Phase, PlaybookInput, load_playbook, discover_playbooks, find_playbook, PlaybookError

I/O Contract

Inputs

Name Type Required Description
raw dict[str, Any] Yes Parsed YAML with name, description, version, authors, intensity, inputs, phases, auth_profile
path str No File path for error messages

Outputs

Name Type Description
returns Playbook Dataclass with name, phases, inputs, intensity, auth_profile
raises PlaybookError Missing name, no phases, bare credential keys

Usage Examples

Loading a Playbook

import yaml
from engine.playbook import Playbook, load_playbook, find_playbook

# Load from file
pb = load_playbook("playbooks/builtin/web-app-quick.yaml")
pb.validate()
print(f"Playbook: {pb.name}, {len(pb.phases)} phases")

# Find by name (searches builtin + user dirs)
pb = find_playbook("web-app-quick")

# Parse from raw dict
raw = yaml.safe_load(open("my-playbook.yaml"))
pb = Playbook.from_dict(raw, path="my-playbook.yaml")
pb.validate()

Related Pages

Implements Principle

Requires Environment

Page Connections

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