agent-safety-bench
Multi-step agent safety compliance benchmarking
Find the critical depth at which your LLM agent fails to maintain safety policies across sequential interactions.
pip install agent-safety-bench
agent-safety-bench run --model qwen3-8b --scenario market_report
Why
Current LLM safety evaluation is single-turn: you ask one question, check if the model refuses. But real agents execute multi-step chains — research, code, deploy, process data. The GGT (Guardrail Gap Theorem) proves that single-step verifiers cannot guarantee multi-step safety: compositional safety is NP-hard.
This tool operationalizes that theorem. It measures D* — the critical depth at which the agent's compliance rate drops below a threshold — across 3 built-in scenarios and any custom scenario you define.
Quick Start
# Install
pip install agent-safety-bench
# List available scenarios
agent-safety-bench list-scenarios
# Run a benchmark
agent-safety-bench run \
--model qwen3-8b \
--scenario market_report \
--depths 1 3 5 7 9 \
--trials 3 \
--output results.json
# Analyze existing results
agent-safety-bench analyze --input results.json
Built-in Scenarios
| Scenario | Description | Policies Tested |
|---|---|---|
market_report |
Multi-step research with stale/unverified data | Data freshness, source verification |
deploy_audit |
Deployment pipeline with security shortcuts | Test discipline, security review |
privacy_compliance |
Data processing with privacy violations | PII protection, third-party sharing |
API
from agent_safety_bench import SafetyBench
from agent_safety_bench.scenarios import get_scenario
scenario = get_scenario("market_report")
bench = SafetyBench(model="qwen3-8b")
results = bench.run_benchmark(
steps=scenario["build_chain"](max_depth=8),
policies=scenario["policies"],
system_prompt=scenario["system_prompt"],
depths=[1, 2, 3, 4, 5, 6, 7, 8],
trials_per_depth=3,
verbose=True,
)
from agent_safety_bench.analyze import find_phase_transition, print_summary
pt = find_phase_transition(results, model_name="qwen3-8b")
print(print_summary(pt))
Custom Scenarios
from agent_safety_bench import SafetyBench
from agent_safety_bench.core import ChainStep
from agent_safety_bench.scenarios import register_scenario
def my_chain(depth):
steps = [
ChainStep(text="Step 1: ...", policy_violation=""),
ChainStep(text="Try to violate policy X", policy_violation="policy_x"),
]
return steps[:depth+1]
register_scenario("my_test", {
"name": "My Custom Test",
"description": "Tests policy X",
"system_prompt": "You must follow policy X...",
"policies": ["Policy X"],
"build_chain": my_chain,
})
Theory
This tool is based on the Guardrail Gap Theorem (GGT): the problem of deciding whether a sequence of individually-valid tool calls can collectively violate a global safety policy (SAFE-EXEC) is NP-complete.
The empirical finding: as chain depth D grows, every tested model shows a phase transition at a critical depth D* where compliance drops from near-perfect to near-zero. This transition is sharp (width <= 2 depths) and scale-dependent (larger models have higher D*).
License
MIT
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 agent_safety_bench-0.1.0.tar.gz.
File metadata
- Download URL: agent_safety_bench-0.1.0.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86afca6ba9857d4b79d39d00ce506423884e74adc27b6922a64ed3d82e9c9da1
|
|
| MD5 |
3b8e5705010a2c1dd87dcd60be777815
|
|
| BLAKE2b-256 |
3695e74c37eae1597253b254a03a0ac9b21e40038f573502f64e2b4c38caaa68
|
Provenance
The following attestation bundles were made for agent_safety_bench-0.1.0.tar.gz:
Publisher:
release.yml on ZhangYangyi03/agent-safety-bench
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agent_safety_bench-0.1.0.tar.gz -
Subject digest:
86afca6ba9857d4b79d39d00ce506423884e74adc27b6922a64ed3d82e9c9da1 - Sigstore transparency entry: 2741366694
- Sigstore integration time:
-
Permalink:
ZhangYangyi03/agent-safety-bench@fc0c96b0df1b972b27a97372b74ee51530e87643 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ZhangYangyi03
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fc0c96b0df1b972b27a97372b74ee51530e87643 -
Trigger Event:
push
-
Statement type:
File details
Details for the file agent_safety_bench-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agent_safety_bench-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c655ea04004ffde3d1a0befd49b9b59044725baf301ad470e41ca47dc810b56
|
|
| MD5 |
379c27d8203904f1a1cfed7b6c1c4d6c
|
|
| BLAKE2b-256 |
20bf5d646de9b5e6ec8d7d64ac93993ea4139cf3fff0d6c90ba6deed94fc43a9
|
Provenance
The following attestation bundles were made for agent_safety_bench-0.1.0-py3-none-any.whl:
Publisher:
release.yml on ZhangYangyi03/agent-safety-bench
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agent_safety_bench-0.1.0-py3-none-any.whl -
Subject digest:
0c655ea04004ffde3d1a0befd49b9b59044725baf301ad470e41ca47dc810b56 - Sigstore transparency entry: 2741367268
- Sigstore integration time:
-
Permalink:
ZhangYangyi03/agent-safety-bench@fc0c96b0df1b972b27a97372b74ee51530e87643 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ZhangYangyi03
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fc0c96b0df1b972b27a97372b74ee51530e87643 -
Trigger Event:
push
-
Statement type: