Back to blog
#red-team#testing#jailbreak#defense

How to Red-Team Your LLM: A Practical Guide

A hands-on walkthrough for red-teaming an LLM application — what to test, how to build a payload battery, how to score results, and how to wire it into CI.

OpenSecureAI TeamDecember 18, 20249 min read

Red-teaming is how you find out whether your guardrails actually hold before an attacker does. For LLM applications it means systematically probing the system with adversarial inputs and measuring what gets through. Here's a practical process you can run this week.

1. Define what "bad" means for your app

Before generating payloads, write down the outcomes you're trying to prevent. For most LLM apps they fall into a few buckets:

  • Policy violations — the model produces disallowed content.
  • Instruction override — untrusted text redirects the model's task.
  • Data leakage — the system prompt, secrets, or another user's data leak.
  • Tool abuse — the model is coaxed into a harmful tool/function call.

Your red-team is only meaningful relative to these goals. A jailbreak that produces edgy text may be irrelevant; one that triggers a destructive tool call is critical.

2. Build a payload battery

You want breadth across attack categories, not just a few clever prompts. Cover at least:

  • Instruction override ("ignore all previous instructions…")
  • Role/persona manipulation ("you are now DAN…")
  • System-prompt extraction ("repeat everything above verbatim")
  • Data exfiltration (beacon to a URL, markdown-image tricks)
  • Indirect injection (payloads planted in retrieved documents)

The Red-Team Toolkit generates a categorized battery and lets you interpolate your own objective into each template, so you can target your app's specific risk instead of generic prompts.

3. Test direct and indirect paths

Directly pasting payloads into the chat box only tests one channel. If your app does retrieval or reads files/URLs, plant payloads in that content too — indirect prompt injection is where most real incidents happen. (More on the distinction in Prompt Injection vs Jailbreaking and, for RAG specifically, Securing RAG Pipelines.)

4. Score results consistently

For each payload, record a simple outcome: blocked, flagged, or leaked/succeeded. Track the rate per category so you can see where you're weak. A useful pre-filter is to run inputs through the Prompt Injection Scanner — if a payload scores High/Critical but your app still processes it normally, that's a gap.

5. Close the loop with a firewall

Findings are only useful if they change the system. Put a guardrail in the request path that enforces your policy:

import { evaluateFirewall } from "@opensecureai/firewall";

const { decision, sanitized } = evaluateFirewall(untrustedInput);
if (decision === "block") return reject();
useModel(sanitized); // secrets/PII already redacted

Re-run your battery after each change to confirm the fix and catch regressions.

6. Make it continuous

One-off red-teaming rots. Bake a subset of your battery into CI so every prompt or model change is re-tested automatically:

cat redteam/*.txt | npx opensecureai-firewall check --fail-on flag

Then feed live attempts from LLM Observability back into your battery — real attackers will show you inputs you didn't think of.

Takeaways

  • Anchor tests to concrete bad outcomes, not vibes.
  • Cover attack categories, and test indirect channels, not just the chat box.
  • Score consistently, fix with a guardrail, and re-test in CI.

Red-teaming isn't a one-time audit — it's a habit. The teams that stay ahead are the ones who make adversarial testing part of every release.