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 namesuites(list, optional): List of suite IDs to runapi_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 IDmodel(str): Model testedprovider(str): Provider usedtimestamp(str): Test timestamprisk_score(int): Overall risk score (0-100)total_attacks(int): Total attacks executedsuccessful_attacks(int): Number of successful attacksfailed_attacks(int): Number of failed attacksduration_ms(int): Execution time in millisecondsraw_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a6d68976e4b3c25a81c22153c77064bfed520c913ad94c05e966f1079953fa5
|
|
| MD5 |
52a3fe6be2e783eb061cff8bbd5ca09f
|
|
| BLAKE2b-256 |
aa16a8125379b21e00ce77929ed2ecc2b0270d6122d7bd0fe717af645e85e629
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5f3d635ed9356279bc9652e6e1de9bc8c02fe1e40f0ec71fb9e1d9ce7a1d5ae
|
|
| MD5 |
1062b7537c3817a07649c0b13ae73ffc
|
|
| BLAKE2b-256 |
17dbb785d463e3ebfb9beb60702556a9097b91e4708c295d6822f9c79ef251ca
|