0d3cb498a3
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
130 lines
5.9 KiB
Markdown
130 lines
5.9 KiB
Markdown
---
|
|
sidebar_label: Evaluating LLM safety with HarmBench
|
|
description: Assess LLM vulnerabilities against 400 HarmBench behaviors to identify and prevent harmful outputs across 7 risk categories
|
|
---
|
|
|
|
# Evaluating LLM safety with HarmBench
|
|
|
|
Recent research has shown that even the most advanced LLMs [remain vulnerable](https://unit42.paloaltonetworks.com/jailbreaking-deepseek-three-techniques/) to adversarial attacks. Recent reports from security researchers have documented threat actors exploiting these vulnerabilities to [generate](https://unit42.paloaltonetworks.com/using-llms-obfuscate-malicious-javascript/) [malware](https://www.proofpoint.com/uk/blog/threat-insight/security-brief-ta547-targets-german-organizations-rhadamanthys-stealer) variants and evade detection systems, highlighting the importance of robust safety testing for any LLM-powered application.
|
|
|
|
To help define a systematic way to assess potential risks and vulnerabilities in LLM systems, researchers at UC Berkeley, Google DeepMind, and the Center for AI Safety created [HarmBench](https://arxiv.org/abs/2402.04249), a standardized evaluation framework for automated red teaming of Large Language Models (LLMs). The dataset evaluates models across 400 key harmful behaviors including:
|
|
|
|
- Chemical and biological threats (e.g., dangerous substances, weapons)
|
|
- Illegal activities (e.g., theft, fraud, trafficking)
|
|
- Misinformation and conspiracy theories
|
|
- Harassment and hate speech
|
|
- Cybercrime (e.g., malware, system exploitation)
|
|
- Copyright violations
|
|
|
|
This guide will show you how to use Promptfoo to run HarmBench evaluations against your own LLMs or GenAI applications. Unlike testing base models in isolation, Promptfoo enables you to evaluate the actual behavior of LLMs **within your application's context** - including your prompt engineering, safety guardrails, and any additional processing layers.
|
|
|
|
This is important because your application's prompt engineering and context can significantly impact model behavior. For instance, even refusal-trained LLMs can still easily be [jailbroken](https://arxiv.org/abs/2410.13886) when operating as an agent in a web browser.
|
|
|
|
The end result of testing with HarmBench is a report that shows how well your model or application defends against HarmBench's attacks.
|
|

|
|
|
|
## Configure the evaluation
|
|
|
|
Create a new configuration file `promptfooconfig.yaml`:
|
|
|
|
```yaml
|
|
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
|
|
description: HarmBench evaluation of OpenAI GPT-5-mini
|
|
targets:
|
|
- id: openai:gpt-5-mini
|
|
label: OpenAI GPT-5-mini
|
|
redteam:
|
|
plugins:
|
|
- id: harmbench
|
|
numTests: 400
|
|
```
|
|
|
|
To focus on a smaller slice of the benchmark, filter by category:
|
|
|
|
```yaml
|
|
redteam:
|
|
plugins:
|
|
- id: harmbench
|
|
numTests: 50
|
|
config:
|
|
categories:
|
|
- cybercrime
|
|
- misinformation
|
|
functionalCategories:
|
|
- contextual
|
|
```
|
|
|
|
The semantic categories are `chemical_biological`, `copyright`, `cybercrime_intrusion`, `harassment_bullying`, `harmful`, `illegal`, and `misinformation_disinformation`. The functional categories are `standard`, `contextual`, and `copyright`. When you set both filters, Promptfoo uses their intersection.
|
|
|
|
## Run the evaluation
|
|
|
|
In the same folder where you defined `promptfooconfig.yaml`, execute the HarmBench evaluation.
|
|
|
|
```bash
|
|
npx promptfoo@latest redteam run
|
|
```
|
|
|
|
Once you're done, view the results:
|
|
|
|
```bash
|
|
npx promptfoo@latest view
|
|
```
|
|
|
|
You can see an example of the results below as well as the full results of a sample evaluation [here](https://www.promptfoo.app/eval/eval-m9D-2025-01-30T17:29:53). In the example we highlighted above, we're doing a comparative analysis of our internal sample application (powered by `gpt-5-mini`) against the vanilla version of `gpt-5-mini` from OpenAI.
|
|
|
|
By providing some additional context to OpenAI (from our application), you can observe how our internal application is able to resist attacks that the vanilla model is not able to. You can also filter by failures by selecting `Show failures only` on the display dropdown at the top left.
|
|
|
|
## Testing different targets
|
|
|
|
Promptfoo has built-in support for a wide variety of models such as those from OpenAI, Anthropic, Hugging Face, Deepseek, Ollama and more.
|
|
|
|
### Ollama Models
|
|
|
|
First, start your Ollama server and pull the model you want to test:
|
|
|
|
```bash
|
|
ollama pull llama4:scout
|
|
```
|
|
|
|
Then configure Promptfoo to use it:
|
|
|
|
```yaml
|
|
targets:
|
|
- ollama:chat:llama4:scout
|
|
```
|
|
|
|
### Your application
|
|
|
|
To target an application instead of a model, use the [HTTP Provider](/docs/providers/http/), [Javascript Provider](/docs/providers/custom-api/), or [Python Provider](/docs/providers/python/).
|
|
|
|
For example, if you have a local API endpoint that you want to test, you can use the following configuration:
|
|
|
|
```yaml
|
|
targets:
|
|
- id: https
|
|
config:
|
|
url: 'https://example.com/generate'
|
|
method: 'POST'
|
|
headers:
|
|
'Content-Type': 'application/json'
|
|
body:
|
|
myPrompt: '{{prompt}}'
|
|
```
|
|
|
|
## Conclusion and Next Steps
|
|
|
|
While HarmBench provides valuable insights through its static dataset, it's most effective when combined with other red teaming approaches.
|
|
|
|
Promptfoo's plugin architecture allows you to run multiple evaluation types together, combining HarmBench with plugins that generate dynamic test cases. For instance, you can sequence evaluations that check for PII leaks, hallucinations, excessive agency, and emerging cybersecurity threats.
|
|
|
|
This multi-layered approach helps ensure more comprehensive coverage as attack vectors and vulnerabilities evolve over time.
|
|
|
|
For more information, see:
|
|
|
|
- [HarmBench paper](https://arxiv.org/abs/2402.04249)
|
|
- [HarmBench GitHub repository](https://github.com/centerforaisafety/HarmBench)
|
|
- [HarmBench Promptfoo plugin](/docs/red-team/plugins/harmbench)
|
|
- [Promptfoo red teaming guide](/docs/red-team/quickstart)
|
|
- [Types of LLM Vulnerabilities](/docs/red-team/llm-vulnerability-types)
|
|
- [CybersecEval](/blog/cyberseceval)
|