How to test LLM guardrails with promptfoo

A practical test plan for measuring whether an LLM guardrail blocks attacks without blocking real users, using promptfoo's CLI, assertions and datasets.

On this page

How to test LLM guardrails with promptfoo before you trust them

A guardrail is sitting in front of a model or application, and nobody can yet say how often it stops attacks or how often it wrongly stops real users. Testing a guardrail means measuring both errors against a fixed set of prompts, then deciding whether the balance is acceptable before users depend on it. The method works the same way whether the guardrail is a managed cloud service, an open-source scanner or a filter your own team wrote. promptfoo can run that measurement locally. Its evals execute on your machine and call the model or guardrail endpoint directly, and the same suite can be run from the command line, imported as a library or wired into a CI/CD pipeline so the check repeats on every change.

A dedicated guardrail test plan becomes necessary once a guardrail is expected to make a block decision that a user or downstream system will feel. That usually means a vendor filter was enabled because a policy or security review asked for it, a team is about to change a threshold, or a guardrail is being swapped for another. Without a plan, teams tend to rely on a handful of demo prompts that either all pass or all fail, which says little about production traffic. A plan fixes three things in advance: which attack prompts and benign prompts are in the test set, which layer of the stack is under test, and what counts as a pass, a miss, a false block or an error. Each of those choices changes what the final numbers mean.

The rest of this page works through that plan in order. Confirm before you start which guardrail version, configuration and provider endpoint you are testing, because a result is only valid for the exact setup that produced it. Check the promptfoo version you run against the release notes, since the current npm release requires Node.js 22.22.0 or newer, and confirm that your environment can reach the guardrail endpoint from the machine running the evals. Treat the guardrail as the variable under test and keep the model, prompts and test data fixed, so a change in results can be traced to the guardrail rather than to something else in the pipeline.

Which parts a guardrail test plan needs

A guardrail test plan answers two questions at once: does it stop attacks, and does it leave legitimate users alone. The six parts below split that work so each one proves a specific claim and leaves its own gaps, which is why a plan that only has one of them tends to report a misleading result.

Attack dataset

A labeled set of prompts that should be blocked, covering the attack classes your application faces, such as direct prompt injection, jailbreaks, indirect injection through documents, and sensitive data extraction. It proves the guardrail catches the attacks you chose to include. It leaves untested every attack you did not write down, so record which categories the set covers and which it omits. Include paraphrases and encodings, because a set of verbatim attacks often overstates detection.

Benign dataset

A labeled set of ordinary requests that should pass, drawn from real user phrasing, domain vocabulary and edge cases such as security questions, medical or financial terms, and long documents. It measures wrongly blocked legitimate requests, which is the cost users feel first. It proves nothing about attacks, so a guardrail that blocks everything will look strong on attacks alone and fail here.

Application-level tests

Tests that send attack and benign prompts through your full application, including the system prompt, retrieval, tools and the response path. They prove the protection works in the configuration users actually reach. They leave the guardrail service itself unmeasured in isolation, so a failure here does not tell you whether the filter or the application logic caused it. Confirm how your application reports a block to the test harness.

Service-level tests

Tests that call the guardrail API or filter directly with the same datasets, bypassing the application. They isolate the detector's own decisions, scores and categories, which makes threshold tuning and vendor comparison possible. They leave untested whether the application passes content to the guardrail at all, so pair them with application-level runs.

Guardrail assertions

Assertions that expect the guardrail to block or flag an attack prompt and record the decision as a guardrail result. They prove the control fired on the inputs you tested. They do not prove the response is safe if the guardrail is bypassed, so they should sit alongside output checks. Confirm whether your guardrail returns a structured flag or only an error, because that changes how the assertion is written.

Not-guardrail assertions

Assertions that expect benign prompts to pass without a guardrail block and to return a usable answer. They prove legitimate traffic still reaches the model and the answer is not degraded. They leave untested whether the answer is free of harmful content, which is the job of output assertions. Use them to count false positives directly rather than inferring them from a pass rate.

Application-level versus service-level guardrail tests

Application-level tests send attack and benign prompts through the complete application, including the system prompt, retrieval, tools and the guardrail the application calls. They answer what a user actually experiences: whether an attack is stopped before it reaches the model, whether a legitimate request gets a useful answer, and whether a blocked request returns a message the product can handle. A guardrail that scores well alone can still fail here if the application ignores its verdict, passes raw input to a tool, or retries after a block.

  • Coverage: includes routing, prompt templates, retrieval and tool calls, so failures outside the filter show up.
  • Outcome grading: assert on the user-visible response, such as a refusal or a safe answer, not only on a flag.
  • Setup cost: needs a running test copy of the application, its credentials and realistic test data.
  • Stability: responses vary with the model, so grade with deterministic checks where possible and record the model version.
  • Ownership: application owners usually write and maintain these tests.

Before relying on results, confirm with the application owners which code path calls the guardrail and whether a block is logged in a form your tests can read.

Guardrail assertion options and when each fits

This table compares guardrail-style assertions, which expect a block or flag, with not-guardrail-style assertions, which expect the request to pass, and with checking the output instead of the guardrail decision. Read each row by asking what result the test expects, which dataset it belongs to, and how a passing score could still hide a problem. Confirm exact assertion names in the promptfoo documentation before writing any config.

Assertion styleExpected resultDataset it suitsMain risk of misreading it
Guardrail expects blockThe guardrail blocks or flags the attack inputAdversarial prompts, injections and jailbreaks with known harmful intentA pass only shows the guardrail acted, not that the attack would have failed without it
Guardrail expects flag on outputThe guardrail flags a harmful or leaked outputAdversarial cases where the model may produce unsafe textModel output varies between runs, so a single flagged result may not be stable
Not-guardrail expects passThe guardrail lets a benign request through unchangedBenign and business-as-usual requests drawn from real user trafficA pass may come from an unrelated error path, so confirm the request actually reached the model
Not-guardrail expects no flag on outputThe guardrail does not alter or block a normal answerBenign cases covering edge topics, domain terms and multilingual inputOver-blocking shows up here as a failure, but a low sample hides rare false positives
Output check instead of guardrail decisionThe model answer meets a content or quality rule, regardless of whether a guardrail actedAdversarial and benign sets when the guardrail is absent or under comparisonPassing an output check does not prove the guardrail worked, and a guardrail decision does not prove the output is safe
Error or unavailable resultRecorded separately from pass and failAny set, especially during guardrail service outages or timeoutsCounting errors as blocks inflates detection, and counting them as passes hides outages

Build the test plan in six steps

The sequence turns a guardrail decision into evidence: a named risk owner, datasets that reflect real traffic, a repeatable promptfoo run and a reviewed record of results before any threshold moves. Each step ends with a check that tells you whether to continue.

  1. Define the risk and name an owner

    Write down what the guardrail must stop, what it must not block, and which application and users it protects. Name one owner who approves the risk statement and who signs off on threshold changes later. This is done when the statement lists the attack categories in scope, the legitimate workflows that must keep working, and the owner's name is recorded next to both. If you cannot name a legitimate workflow, stop here, because a benign set cannot be built without one.

  2. Assemble attack and benign datasets

    Build two separate sets. The attack set holds prompts and documents that try to trigger the risks from the first step, drawn from known attack collections, red team output and incidents your team has seen. The benign set holds requests your users actually send, such as sanitized samples from your own logs, support tickets and edge cases like long messages, code, medical or financial terms and non-English input. Check that the benign set contains realistic traffic from your own logs, not only examples written by the test author, and that no record contains personal data you are not allowed to copy into a test environment.

  3. Wire the guardrail as a provider or target

    Connect promptfoo to the guardrail so every test case goes through the same path your production traffic takes. Depending on the service, this means a provider configuration for the vendor's API, a Python or HTTP provider for your own filter, or a target that calls the application with the guardrail in place. Record which component returns the block decision, because later results depend on it. The step is done when a single known-bad and a single known-good prompt produce a block and a pass decision you can read in the output.

  4. Write application and service tests

    Write two layers of assertions. Service-level tests call the guardrail directly and check its raw decision, category and score for each input. Application-level tests send the same inputs through your whole application and check what the user sees, including whether the model still answered a benign request and whether a blocked request returned a safe message. Use the guardrails and not-guardrails assertion types in promptfoo to express block expectations on attack cases and pass expectations on benign cases. Confirm that each attack case is expected to be blocked and each benign case is expected to pass, so a single misconfigured assertion cannot hide a failure.

  5. Run the suite and record every outcome

    Run the suite from the command line or your pipeline and save the output for each run, including the guardrail version or configuration, dataset version and promptfoo version. Record three counts separately: passes, failures where the guardrail decided incorrectly, and errors where the call failed, timed out or returned an unparseable response. Treat errors as unknown results, not passes, and rerun or investigate them before you report a rate. The step is complete when a second run on the same configuration produces the same counts or a documented reason for the difference.

  6. Review results before any threshold change

    Before changing a threshold, a category setting or a blocking rule, review the failed attack cases, the wrongly blocked benign cases and the error log with the owner from step one. Decide whether the fix belongs in the guardrail configuration, the application or the dataset itself, since a benign case that fails may be a broken test rather than a bad filter. Record the decision, the evidence and the rerun results in your change record. This step closes when the owner has approved the change in writing and the rerun shows the expected trade-off between missed attacks and blocked users.

Why errors must be tracked separately from passes

A provider timeout, an authentication failure or a malformed response is neither a guardrail pass nor a block. It is a test that never produced a verdict. If your harness counts it as a pass, the guardrail appears to stop more attacks than it did, and if it counts it as a block, the guardrail appears to wrongly refuse more legitimate requests than it did. Both headline numbers from the attack and benign datasets then move for reasons unrelated to the guardrail. A run where the Azure, AWS, Google or NVIDIA endpoint returned 401 errors on a fifth of the requests can look like a strong result, and a run with rate-limit errors on the benign set can look like a poor one. Neither number means anything until error cases are removed from the denominators and reported on their own.

In practice, give every test result three states: pass, fail and error, and make the error state carry a reason. In promptfoo, an assertion that cannot be evaluated because the provider call failed should be reviewed in the output and not folded into the pass count. Check how your chosen provider or wrapper surfaces failures, since a Python or HTTP provider that catches exceptions and returns an empty string will silently turn an outage into a clean result. Confirm that a guardrail block is recorded from the guardrail's own signal, such as a structured flag or metadata field, rather than inferred from a missing answer, because a missing answer is an error until proven otherwise.

In CI, gate on error rate as well as on the pass rate. Set a maximum error count for each dataset and fail the job when it is exceeded, so that a broken credential or an expired quota stops the pipeline instead of producing a green build. When error rates rise, stop reading the detection numbers, rerun the affected cases after fixing the cause, and record the error categories (authentication, timeout, quota, malformed output) in the report so the team can see whether the problem is in the guardrail service, the network path or the harness. Confirm with your guardrail vendor which error codes are retryable and how long their rate limits apply, since retry policy decides whether an error becomes a verdict or stays an error.

Security and operational considerations for guardrail tests

Guardrail test suites hold attack prompts, benign traffic that may resemble production, and vendor credentials. The cards below cover where that material lives, who can reach it, and when the suite has to run again.

Keep attack datasets out of shared locations

Adversarial prompts for a guardrail are a map of what it misses, so a leaked set tells an attacker where to probe. Store attack datasets in a private repository or an encrypted workspace with the same access rules as your other security test material. Check who can read the CI logs, since failing cases often print the full prompt. Decide before the first run whether results are kept at all, and for how long.

Store vendor guardrail API keys securely

Guardrail services from cloud providers authenticate with keys or cloud identities that can call the service and, in some setups, read its configuration. Inject them from your secrets manager at run time and keep them out of promptfoo config files committed to source control. Use a dedicated test account or role with the minimum permissions for the guardrail calls, and rotate the credentials on the schedule your security team applies to other service accounts.

Control where benign production-like data goes

Benign test sets are most useful when they look like real user traffic, but real traffic contains personal and customer data. Replace identifiers with synthetic values before the data enters a test set, and record which fields were masked. Confirm with the guardrail vendor and your data protection team where the prompts are processed and whether the service retains them, because each test run sends every prompt to that service.

Run the CLI against approved endpoints only

The promptfoo CLI runs on the machine that starts it and calls the models and guardrail endpoints directly. Restrict those calls to endpoints your organization has approved, and block others at the network or egress layer where possible. Pin the endpoint URLs in the config for each environment so a test aimed at staging cannot quietly reach production, and review which hosts a CI runner can reach.

Share results through a team server with limits

The Community edition runs locally, so results stay on the machine or CI runner that produced them unless you export them. If several people need the same results, a shared self-hosted promptfoo server is an option, but the self-hosting documentation says its SQLite storage cannot be shared across replicas, and it has no RBAC or built-in SSO and is not recommended for production. Ask whether your team needs those controls before you choose that path.

Self-hosting docs

Rerun the suite after every change

A guardrail verdict can shift when the vendor updates its model, when you change a threshold or policy, or when the underlying model behind your application changes. Rerun the attack and benign sets on each of those changes and compare results against the previous baseline. Keep the run configuration and dataset version with each result so a later regression can be traced to the change that caused it.

Questions teams ask before testing guardrails

How long does a first guardrail test plan take to write?

No supplied figure gives a duration, so confirm it for your own environment rather than assuming one. The main drivers are how many guardrails are in scope, whether you already have labeled attack and benign examples, how many applications sit in front of each guardrail, and whether results must go to a review board. A plan that covers one guardrail on one application with existing data moves much faster than one that compares several services across several products. Ask any partner for a written scope that lists these inputs, then ask how each one changes the schedule.

Can an in-house team run this with the promptfoo Community edition?

Yes, for many teams, because the Community edition is free and includes all LLM evaluation features, all model providers and integrations, and red teaming with 10k probes per month, with community support. The Community edition runs locally, so evals run on your machine and talk directly with the LLM. What it does not include is team sharing, SSO, RBAC or a centralized guardrail dashboard, which are Enterprise features. Teams should check whether their probe volume fits the monthly limit and whether they can cover support themselves. A self-hosted server is not recommended for production use, so confirm any shared setup with the vendor first.

What data and access does guardrail testing need?

You need the guardrail under test, a way to call it, and test data you are allowed to send to it. In practice that means API keys or service identities for each guardrail, a sandbox or non-production endpoint where possible, and a decision on whether attack prompts and sample user content can leave your network. Benign datasets should use anonymized or synthetic records so that no real customer data is stored in test logs. Confirm with each provider how it logs requests and whether test traffic counts against your quotas, and confirm with your security team where promptfoo output files will be stored.

Can promptfoo test a custom filter we built ourselves?

Yes, if your filter can be called from promptfoo. Promptfoo supports custom providers, including HTTP, WebSocket and Python endpoints, so a filter exposed through an API or a Python function can be wrapped and scored with the same attack and benign datasets used for managed services. Record each block as a guardrail flag, and keep the test suite separate from the filter code so the same suite can test a replacement later. Confirm the exact provider setup in the promptfoo documentation for your version, because the configuration keys can change between releases.

How should we choose a threshold from the results?

Choose the threshold from the trade-off between missed attacks and wrongly blocked legitimate requests, not from the default setting alone. Run the same adversarial and benign sets at several thresholds, then plot the two error rates for each. Pick the point your risk owner accepts for the application's use case, and record why. A customer-facing chatbot and an internal document tool may need different points. Re-run the chosen threshold on a held-out set before release, since a threshold tuned on one dataset often performs worse on new traffic.

What should we do when a guardrail update changes our results?

Treat the update as a change to the control and re-run the full test suite before accepting the new version. Keep the attack and benign datasets, configs and results versioned so you can compare the old and new guardrail on identical inputs. Track errors separately from passes, because a failed request or timeout is not the same as a block or an allow. If the update moves missed attacks or false positives beyond the threshold your risk owner set, hold the rollout or adjust the configuration, and document the decision. Ask each vendor for its change notes and whether it versions models or policies.

Does a passing guardrail test mean we are compliant?

No. Passing tests produce evidence about one guardrail's behavior on your datasets, which can support a compliance assessment, but they do not certify your system. Promptfoo's red teaming documentation references the OWASP LLM Top 10, the NIST AI Risk Management Framework and the EU AI Act as frameworks that support systematic testing before deployment. Auditors and certification bodies decide what evidence is sufficient. DeployOpen prepares systems, controls and evidence for compliance assessments, but it does not issue audit reports or certifications.

How the guardrail test flow fits together

The run starts with attack and benign datasets loaded into promptfoo on your machine. promptfoo sends each case either to your application with its guardrail enabled, or straight to the guardrail service, so you can separate application behavior from the filter itself. Results split into pass, fail and error, and the fail and error counts go to a threshold review. The trust boundary sits at the edge of your local run: anything crossing into the vendor API is data leaving your environment, so confirm what that vendor retains before you point real prompts at it.

Datasets flow through promptfoo to the guardrail, with results feeding a threshold review.

How DeployOpen scopes and delivers guardrail testing

DeployOpen approaches guardrail testing as a written, fixed-scope engagement: the guardrails in scope, the attack and benign datasets, the test layers and the handover are agreed before work starts. The promptfoo setup runs inside infrastructure you control, so the evidence stays with your team.

How we scope

  • Inventory every guardrail, filter and moderation layer that sits in front of or behind your LLM application
  • Agree which attack categories and benign user journeys the attack and benign datasets must cover
  • Record the application-level and service-level test layers, pass criteria and error handling in the written scope

How we build

  • Configure promptfoo with the providers, targets and guardrail assertions for each layer under test
  • Build separate attack and benign datasets, and keep errors from timeouts or provider faults out of pass and fail counts
  • Run the suites in your environment, including the self-hosted promptfoo server where your team needs a shared view

How we hand over

  • Deliver the promptfoo configuration, datasets and assertion logic in a repository your team owns
  • Document each test layer, how to read block and error results, and how to rerun the suite after a guardrail change
  • Walk your security and engineering teams through the results and the threshold trade-offs they will need to decide

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer after the fixed-scope work ends
  • Retesting after guardrail configuration changes or model updates can be scoped as part of the same engagement
  • Ask us to confirm the support levels, response expectations and retainer terms in writing before you commit

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.