Python API

The CLI covers most use cases, but sometimes you need ai-blackteam inside your own scripts — automated pipelines, custom reporting, or integration with other tools. The Blackteam class gives you the same capabilities as the CLI without subprocess calls.

Quick Start

The Blackteam Class

Constructor

The constructor loads your config (including API keys from environment variables) and initializes the engine.

run()

Run a single attack against a model.
Returns a list of PromptResult objects, one per prompt variant the attack generates.

batch()

Run multiple attacks against a model.
Returns a list of result objects across all attacks.

taxonomy()

Get the full attack taxonomy.
Returns a dict mapping technique IDs to their metadata (name, category, severity, OWASP mappings, MITRE ATLAS mappings).

Working with Results

Each result from run() contains:

Using the Registry Directly

For lower-level access, you can use the attack and provider registries directly:

Using the Engine Directly

The engine handles execution, evaluation, and storage:

Example: Custom Safety Pipeline