Skip to main content

Adversarial Testing Harness for Large Language Models

Project description

Adversaria Python SDK

Python SDK for Adversaria - Adversarial Testing Harness for LLMs.

Installation

pip install adversaria

Note: This SDK requires the Adversaria CLI to be installed:

cargo install adversaria

Quick Start

from adversaria import Adversaria

# Create client
client = Adversaria()

# Run tests
result = client.run(
    provider="openai",
    model="gpt-4",
    api_key="sk-..."  # Optional, uses OPENAI_API_KEY env var
)

# Check results
print(f"Risk Score: {result.risk_score}/100")
print(f"Successful Attacks: {result.successful_attacks}/{result.total_attacks}")

# Save report
report_path = result.save_report("./reports")
print(f"Report saved: {report_path}")

API Reference

Adversaria

Main client class for running security tests.

client = Adversaria(config_path=None)

Methods:

run(provider, model, suites=None, api_key=None)

Run security tests against an LLM.

Arguments:

  • provider (str): Provider name ('openai', 'anthropic', 'ollama')
  • model (str): Model name
  • suites (list, optional): List of suite IDs to run
  • api_key (str, optional): API key (uses env var if not provided)

Returns: TestResult

list_suites()

List available attack suites.

Returns: List[Suite]

list_reports(directory="./reports")

List available reports.

Returns: List[str] - List of report file paths

load_report(filepath)

Load a report from file.

Returns: TestResult

TestResult

Test execution results.

Attributes:

  • id (str): Unique test run ID
  • model (str): Model tested
  • provider (str): Provider used
  • timestamp (str): Test timestamp
  • risk_score (int): Overall risk score (0-100)
  • total_attacks (int): Total attacks executed
  • successful_attacks (int): Number of successful attacks
  • failed_attacks (int): Number of failed attacks
  • duration_ms (int): Execution time in milliseconds
  • raw_data (dict): Full report data

Methods:

save_report(directory="./reports")

Save report to directory.

Returns: str - Path to saved report

Examples

Basic Testing

import os
from adversaria import Adversaria

# Set API key
os.environ["OPENAI_API_KEY"] = "sk-..."

# Run test
client = Adversaria()
result = client.run(provider="openai", model="gpt-4")

if result.risk_score > 50:
    print("⚠️ High risk detected!")

Specific Suites

result = client.run(
    provider="openai",
    model="gpt-4",
    suites=["prompt_injection", "jailbreak"]
)

Multiple Providers

providers = [
    ("openai", "gpt-4"),
    ("anthropic", "claude-3-opus-20240229"),
]

for provider, model in providers:
    result = client.run(provider=provider, model=model)
    print(f"{provider}/{model}: {result.risk_score}/100")

Load Previous Report

client = Adversaria()

# List all reports
reports = client.list_reports()

# Load latest report
if reports:
    result = client.load_report(reports[0])
    print(f"Risk Score: {result.risk_score}/100")

Requirements

  • Python 3.8+
  • Adversaria CLI (cargo install adversaria)
  • PyYAML

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adversaria-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

adversaria-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file adversaria-0.1.0.tar.gz.

File metadata

  • Download URL: adversaria-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for adversaria-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8a6d68976e4b3c25a81c22153c77064bfed520c913ad94c05e966f1079953fa5
MD5 52a3fe6be2e783eb061cff8bbd5ca09f
BLAKE2b-256 aa16a8125379b21e00ce77929ed2ecc2b0270d6122d7bd0fe717af645e85e629

See more details on using hashes here.

File details

Details for the file adversaria-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: adversaria-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for adversaria-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5f3d635ed9356279bc9652e6e1de9bc8c02fe1e40f0ec71fb9e1d9ce7a1d5ae
MD5 1062b7537c3817a07649c0b13ae73ffc
BLAKE2b-256 17dbb785d463e3ebfb9beb60702556a9097b91e4708c295d6822f9c79ef251ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page