Files
LLM-Labs/content/labs/lab-6-evaluation-and-red-teaming.md
T
2026-03-29 16:39:07 -06:00

166 lines
7.4 KiB
Markdown

<!-- breakout-style: instruction-rails -->
<!-- step-style: underline -->
<!-- objective-style: divider -->
# Lab 6 - Evaluation and Red Teaming
In this lab, we will:
* Perform Prompt Injection against three layers of model protection
* Use PromptFoo to programmatically evaluate a model's security protections
## Objective 1 Explore: Direct Prompt Injection
For part 1 of our lab, we're going to explore Direct Prompt Injection. There are three levels for this lab:
1. System Prompt Instructional Guardrail
2. System Prompt + Regex
3. System Prompt + LLM Evaluation
Each level will be more difficult than the last, based on how the protection interacts with the generated output.
<div class="lab-callout lab-callout--warning">
<strong>Warning:</strong> Due to the limitations of Open WebUI, you will see generated outputs BEFORE safety evaluation. A passing answer involves the protection missing the final output.
</div>
To access the lab, navigate to https://ai.zuccaro.me. You can log in with the following information:
* `Username` - student@zuccaro.me
* `Password` - Student9205!
<br>
<figure style="text-align: center;">
<a href="https://i.imgur.com/YSgw3wq.png" target="_blank">
<img
src="https://i.imgur.com/YSgw3wq.png"
style="width: 50%; display: block; margin-left: auto; margin-right: auto; border: 5px solid black;">
</a>
<figcaption style="margin-top: 8px; font-size: 1.1em;">
Chapter 1 - 1024 Chunks, Recursive Character. This strategy nicely breaks paragraphs up.
</figcaption>
</figure>
<br>
Good luck and have fun!
<div class="lab-callout lab-callout--info">
<strong>Tip:</strong> Conversations for this Open WebUI instance will not be saved. Ensure you take steps to save any interactions you wish to keep!
</div>
## Objective 2 Explore: PromptFoo
While manual interaction with a model is often required for a successful jailbreak, it is often unnecessary for a quick "Vulnerability Scan" style of red team. Often, we're concerned about ensuring our model won't respond poorly during typical user interactions. For testing a wide set of prompts against a model or application, Promptfoo is a great open source project to empower us with the ability to test a wide set of mutated prompts.
Promptfoo is available on our lab machine at https://<YOUR STUDENT IP>:15500. We can start working with Promptfoo by creating a new Red Team configuration.
<figure style="text-align: center;">
<a href="https://i.imgur.com/YyP8mwB.png" target="_blank">
<img
src="https://i.imgur.com/YyP8mwB.png"
style="width: 50%; display: block; margin-left: auto; margin-right: auto; border: 5px solid black;">
</a>
<figcaption style="margin-top: 8px; font-size: 1.1em;">
Embedding Atlas Flow Diagram
</figcaption>
</figure>
<br>
Promptfoo is designed to be easy to use for both beginners and practitioners. It's wizard will guide us through the process of configuration the tool for our target, selection of datasets and mutations, and track execution.
<div class="lab-callout lab-callout--info">
<strong>Tip:</strong> Although the Promptfoo WebUI is convenient, it unfortunately hides a critical configuration option within .yaml for our lab. As such, please use this provided configuration - [./content/labs/lab-6-evaluationn-and-red-teaming/promptfoo.yaml](Promptfoo.yaml). You can upload it with the "Load Config" button in the bottom left corner, and then proceed with the following screenshot steps.
</div>
<figure style="text-align: center;">
<a href="https://i.imgur.com/1xbMstb.png" target="_blank">
<img
src="https://i.imgur.com/1xbMstb.png"
style="width: 50%; display: block; margin-left: auto; margin-right: auto; border: 5px solid black;">
</a>
<figcaption style="margin-top: 8px; font-size: 1.1em;">
Target API Provider (OpenAI)
</figcaption>
</figure>
<br>
<figure style="text-align: center;">
<a href="https://i.imgur.com/p5mw1i4.png" target="_blank">
<img
src="https://i.imgur.com/p5mw1i4.png"
style="width: 50%; display: block; margin-left: auto; margin-right: auto; border: 5px solid black;">
</a>
<figcaption style="margin-top: 8px; font-size: 1.1em;">
Application Details (Direct LLM Testing)
</figcaption>
</figure>
<br>
<figure style="text-align: center;">
<a href="https://i.imgur.com/jhgkxx0.png" target="_blank">
<img
src="https://i.imgur.com/jhgkxx0.png"
style="width: 50%; display: block; margin-left: auto; margin-right: auto; border: 5px solid black;">
</a>
<figcaption style="margin-top: 8px; font-size: 1.1em;">
Dataset(s) Selection
</figcaption>
</figure>
<br>
<figure style="text-align: center;">
<a href="https://i.imgur.com/lStW3Zo.png" target="_blank">
<img
src="https://i.imgur.com/lStW3Zo.png"
style="width: 50%; display: block; margin-left: auto; margin-right: auto; border: 5px solid black;">
</a>
<figcaption style="margin-top: 8px; font-size: 1.1em;">
Mutation Strategies
</figcaption>
</figure>
<br>
Once we select start, Promptfoo handles the rest! Mutations, tests, and results are all tracked by the WebUI. Promptfoo tests can take a significant period of time! Once done, we'll be provided a new results screen.
<figure style="text-align: center;">
<a href="https://i.imgur.com/2UopUGj.png" target="_blank">
<img
src="https://i.imgur.com/2UopUGj.png"
style="width: 50%; display: block; margin-left: auto; margin-right: auto; border: 5px solid black;">
</a>
<figcaption style="margin-top: 8px; font-size: 1.1em;">
Promptfoo Results
</figcaption>
</figure>
<br>
Promptfoo is supremely flexible! Anything that involves mass evaluation of prompts against a model can be easily performed using the Promptfoo framework. Likewise, we can run an evaluation against a direct HuggingFace dataset. Once again, PromptFoo provides a WebUI, but providing the direct .yaml is often easier.
<div class="lab-callout lab-callout--info">
<strong>Tip:</strong> Please use this provided configuration - [./content/labs/lab-6-evaluation-and-red-teaming/mmlu-promptfoo-config.yaml](MMLU-Promptfoo-Config.yaml). You can upload it with the "Load Config" button in the bottom left corner, and then proceed with the following screenshot steps.
</div>
<figure style="text-align: center;">
<a href="https://i.imgur.com/23iFYNo.png" target="_blank">
<img
src="https://i.imgur.com/23iFYNo.png"
style="width: 50%; display: block; margin-left: auto; margin-right: auto; border: 5px solid black;">
</a>
<figcaption style="margin-top: 8px; font-size: 1.1em;">
Promptfoo Evaluation
</figcaption>
</figure>
<br>
Often times, running an Evaluation of a known publicly tested dataset against a copy of your local model can be a more quantitative way to determine the precision loss of your configuration. This can be useful when trying to squeeze the maximum possible performance possible out of your hardware!
## Conclusion
In this lab, we performed red team evaluations against a target model:
1. **Direct Injections** - We explored different ways to bypass common LLM controls.
2. **Promptfoo Red Teaming** - We used Promptfoo for red teaming a large number of prompts against our target model.
3. **Promptfoo Evaluation** - We used Promptfoo for benchmarking a model against a popular public benchmark, giving us a local point of comparison.
We should now have a better sense of what our next round of fine-tuning should be, or if we need to explore additional protections for our model!