When a moderation assertion in promptfoo tests fits better than a guardrail test
A moderation assertion grades the output of a model or application against a moderation model, while a guardrail test checks whether a guardrail made the right block decision. Use the moderation assertion when your concern is the content that actually reaches the user: the response must stay free of categories such as hate, violence or sexual content, whatever the upstream filter did. Use a guardrail test when your concern is the filter itself: does it block the adversarial inputs you care about, and does it let benign requests through. The two answer different questions, so a team that asks one of them and reads the result as the other will draw the wrong conclusion. In promptfoo, the moderation assertion is the right tool when you are testing an application's responses, a prompt change or a model swap, and you want to catch unsafe generations before release.
The default moderation provider is OpenAI's moderation model, and the documentation also lists Azure AI Content Safety as an alternative. When Replicate is the provider, LlamaGuard 4 is the default moderation model. Choose the grader that matches the policy your organization must defend. A grader that scores categories differently from your own content policy can pass an output your reviewers would reject, or fail one they would accept. Before relying on a grader in a release gate, run a small set of outputs you have already labeled, confirm the grader agrees with those labels, and record which provider and model version you used. Confirm current model names and availability in the promptfoo moderation documentation and with each provider, since moderation models change over time.
A practical rule is to keep both tests. Run guardrail tests on attack and benign datasets to measure the filter's decisions, and run moderation assertions on the outputs your application produces with and without the guardrail in place. If the guardrail blocks an attack but the application still emits unsafe text in a related case, the moderation assertion will catch it, and the guardrail test will not. If a guardrail blocks a request, the output never reaches the moderation step, so the assertion will pass by design. Plan this split in the test configuration from the start, so that a passing moderation check is never mistaken for evidence that the guardrail works.
Choosing a moderation provider: OpenAI, Azure AI Content Safety or Llama Guard
OpenAI moderation is the default provider for the promptfoo moderation assertion, so it is the path most teams try first. It suits a team that already calls OpenAI models for its application and wants the output check to use the same account, billing and key management. It also fits a quick first pass over model responses before the team decides whether a second provider is worth the setup.
- Account and key: The assertion needs an OpenAI API key available to the promptfoo run, typically through an environment variable in your CI system or local shell. Confirm which key scope and project your organization uses for evaluation traffic.
- Hosting: The moderation call leaves your environment and goes to the provider's hosted service, so the output under test is sent to a third party. Check this against your data handling rules before running it on production transcripts.
- Billing: Moderation calls are a recurring cost on each run. Ask how the provider prices moderation requests for your account before you add it to a scheduled pipeline.
- Categories and thresholds: Read the provider's current category list and what each flag means in its documentation. Do not assume a score or cut-off that the documentation does not state.
- Version changes: Model and endpoint behavior can change over time. Pin the model you test against where the provider allows it, and rerun a baseline set after any change.
Before you rely on this provider, confirm the current moderation endpoint, its data retention terms and the categories it returns in the OpenAI documentation.
Azure AI Content Safety is an alternative moderation provider that promptfoo supports for moderation assertions. A team usually picks it when the application already runs on Azure, when its security or procurement review expects Azure-hosted services, or when it already uses Azure AI Content Safety elsewhere and wants one set of categories and reporting across tests and production.
- Azure resource: You need an Azure AI Content Safety resource in a subscription your organization controls, with its endpoint and key. Confirm the region and resource type your compliance team has approved.
- Configuration: Credentials and the endpoint are supplied to promptfoo through the provider settings and environment variables. Check the promptfoo moderation documentation for the exact keys before writing the config.
- Data location: Confirm where Azure processes moderation requests for your chosen resource and whether that meets your residency requirements.
- Categories and severity: Read the Azure documentation for the harm categories and severity levels it returns, and map them to your assertion thresholds yourself. Do not copy thresholds from examples.
- Cost ownership: Azure bills the resource under your subscription. Ask your platform team who owns the resource, its quotas and its cost reporting.
Before you rely on this provider, confirm the current API version, the supported content types and the category definitions in the Azure AI Content Safety documentation.
Llama Guard is a safety classifier model, and promptfoo can use it for moderation assertions. Per the promptfoo documentation, LlamaGuard 4 is the default moderation model when you use Replicate. A team usually picks this path when it wants an open model family it can reason about, when it prefers a hosted model endpoint over a large vendor safety API, or when it plans to evaluate a self-hosted classifier later with the same test suite.
- Replicate account: The Replicate route needs a Replicate API token available to the promptfoo run. Confirm which account and billing arrangement your organization uses.
- Model choice: LlamaGuard 4 is the documented default with Replicate. If you want a different Llama Guard version or model identifier, confirm it is available on the provider and that promptfoo supports it.
- Hosting and data flow: Replicate hosts the model, so output under test leaves your environment. A self-hosted classifier is a separate design that you would need to set up and verify yourself.
- Output interpretation: Read the Llama Guard model card and the promptfoo moderation documentation to understand how unsafe categories are reported. Do not infer scores or thresholds that the documentation does not state.
- Licensing: Check the license terms of the specific Llama Guard model version you plan to use with your legal team.
Before you rely on this path, confirm the Replicate model identifier, the license terms and the output format in the promptfoo moderation documentation.
Moderation assertion options and when each fits
This table compares the moderation options promptfoo supports for the moderation assertion and the question each one answers. Read it to pick a provider for your output checks, then confirm the requirement and the setting in the last column before you build the test.
| Option | When it fits | What it requires | What to confirm |
|---|---|---|---|
| OpenAI moderation (default) | Output checks where you want the default moderation model and already use OpenAI credentials | An OpenAI API key available to promptfoo during the run | Which moderation model your promptfoo version calls by default and which categories the assertion checks |
| Azure AI Content Safety | Output checks where your organization already runs Azure AI Content Safety and needs the assertion to match that service | An Azure AI Content Safety resource and the endpoint and key settings the moderation docs describe | Which categories and severity levels the assertion reports, and that the resource region and key are correct for the test environment |
| Llama Guard via Replicate | Output checks using an open model family, where the team wants a self-hosted-style moderation classifier accessed through Replicate | A Replicate account and API token; LlamaGuard 4 is the default moderation model when Replicate is used | Whether the default LlamaGuard 4 model is the one you want, and how Replicate usage is billed and logged for your data |
| Moderation on model output | Checking that a model's response does not contain harmful content, regardless of what any guardrail decided | Your test cases and the model under test returning the text to be moderated | That the assertion is applied to the output field, not the input prompt, and that failures are reviewed as model behavior |
| Guardrail decision tests | Checking whether a guardrail service blocks an attack or allows a benign request | A guardrail under test and a labeled attack and benign dataset | That you use the guardrail assertions for block or allow decisions, and keep moderation assertions for output content |
Setting up moderation assertions in a promptfoo config
This sequence takes a team from an installed promptfoo CLI to a config that sends model outputs to a moderation check and reports which outputs were flagged. Each step ends with a check so that a broken key or misconfigured assertion is caught before the results are trusted.
Install the promptfoo CLI on a supported Node.js version
The engineer who runs evals installs the promptfoo CLI on a workstation or CI runner that has Node.js 22.22.0 or newer, the minimum version stated for the current npm release. promptfoo runs locally, so the install happens on a machine the team controls. Confirm the install by running the version command for the CLI and checking that it prints a version number without errors. If the command fails, check the Node.js version first.
Define the provider and a set of test cases
Create a
promptfooconfig.yamlfile that names the model or application whose outputs will be checked, along with the prompts or inputs sent to it. Add test cases that cover both benign requests and content that a moderation model should flag, such as clearly labeled unsafe examples used only for testing. Keep the unsafe set small and documented so reviewers know what each case is meant to trigger. Confirm the file parses by running the validation or a dry run, which should list the expected number of test cases.Add the moderation assertion to expected outputs
Add a moderation assertion under the expected outputs of each test, or as a default assertion that applies to all tests. The assertion checks the model's output with a moderation model, so it tests what the application returned rather than whether a guardrail blocked the request. Start with OpenAI moderation, which is the default, and add the Azure AI Content Safety or Llama Guard option only when your environment is set up for it. Confirm the assertion is attached by viewing the parsed config, where it should appear on the tests you intended.
Set provider credentials for the moderation model
Store the API key for the moderation provider in an environment variable or secrets store that the CI runner or workstation can read, and reference it from the config rather than writing it into the file. If you use Azure AI Content Safety, the endpoint and key for that resource are needed instead. If you use Llama Guard through Replicate, the Replicate token is required, and LlamaGuard 4 is the default model for that path. Confirm credentials load by running a single test and checking that the run authenticates without a key error.
Run a known-unsafe test to confirm the assertion fails
Before running the full suite, run a small eval that includes at least one known-unsafe test case and one benign case. The unsafe case should produce a failed moderation assertion, and the benign case should pass. This check shows that the assertion is actually evaluating output and that the moderation model is reachable. If the unsafe case passes, review whether the assertion is attached to that test and whether the model output was generated at all.
Run the full eval and read the results
Run the complete eval and open the results view or the output file. For each failed assertion, check the test input, the model output and the moderation category that triggered the failure, so you can tell whether the model produced problematic content or the moderation model flagged something benign. Record errors separately from assertion failures, because a provider timeout or missing credential is not a moderation finding. The sequence is complete when every test has a clear result and the errors have been resolved or documented.
Trade-offs of grading output with a moderation model
A moderation assertion grades output with a second model, and that model brings its own errors, cost and data path. The cards below cover the decisions that follow from this, so the result you record reflects the content you actually tested rather than the behavior of the judge.
The judge has its own errors
A moderation model is a separate classifier, so it can flag harmless output and miss harmful output. When a moderation assertion fails, the failure may belong to the application under test or to the judge. Before you trust a suite, run a small set of outputs you have labeled by hand through the moderation assertion and count where it disagrees with your labels. Keep those disagreements in the test plan so reviewers can see the judge was checked.
Results depend on the provider
The category labels, thresholds and coverage of a moderation check change with the provider behind it. The default OpenAI moderation path, Azure AI Content Safety and Llama Guard can disagree on the same text. Record the provider name, model and settings in every run so a result can be reproduced. Confirm the current categories and default behavior with each vendor, since they change over time.
Moderation docsA pass does not prove a block
A moderation assertion checks what the application returned. It does not show that a guardrail stopped anything, because a guardrail decision is a separate event with its own status and logs. A clean output can come from a model that refused on its own, from a filter that never ran or from a request that never reached the filter. Use guardrail tests to measure blocks and use moderation assertions to measure output content, and keep the two results in separate columns of the report.
Cross-provider results do not transfer
A suite that passes with one moderation provider may fail with another, so a comparison between guardrail products can be distorted by the grader rather than the systems being compared. Run the same outputs through each provider you care about, and report the differences as findings. Do not treat one provider's pass rate as a score for the application itself.
External calls send output out
Hosted moderation services receive the text you ask them to grade, and that text may include personal data, internal prompts or model responses from regulated workflows. Check the data terms of each provider before the suite runs on production-like content, and confirm where requests are processed. Where data may not leave your environment, a locally hosted judge model is the option to evaluate, with its own hardware and maintenance cost.
How a moderation assertion grades an output
The flow starts with a test case sent to the model or application under test. promptfoo receives the output and passes it to the moderation assertion, which sends that text to the moderation provider you chose. The provider's verdict becomes a pass or fail in the results. The key boundary is the hand-off to the external provider: the output text leaves your machine at that point, so check what that provider receives and retains before you run tests on sensitive data.
Output text crosses to the moderation provider; the verdict returns and is recorded locally.
Security and data handling for moderation calls
A moderation assertion sends test content to a third-party service, so the test harness itself becomes a data flow to review. The cards below cover where the content goes, how provider keys are handled, what runs locally and what your provider keeps. Check each one before the first run against production-like prompts.
Keep provider keys out of configs
Moderation assertions call a provider such as OpenAI, Azure AI Content Safety or a Replicate-hosted Llama Guard, so each needs its own credential. Load keys from environment variables or your secrets manager rather than writing them into promptfooconfig.yaml or committing them to the repository. Use a separate key with a spending limit for test runs, so a leaked or looping CI job cannot draw on production quota.
Know where test outputs travel
promptfoo runs on your machine and calls the moderation endpoint directly, so each test string and each model output you check is sent to that provider. Map which services receive the text, including the model under test, the judge and the moderation API. Confirm that this matches what your data handling policy allows for synthetic attack prompts and any sample customer data you reuse.
Run promptfoo locally
promptfoo's documentation states that evals run on your machine and talk directly with the LLM, with no promptfoo relay in between. That makes the local workstation or CI runner the place to control. Confirm the runner's disk, logs and cache are covered by the same access rules as the test data, and that no one is copying results to shared drives by default.
promptfoo introductionConfirm provider retention rules
Retention of submitted content is set by each moderation provider's terms, not by promptfoo. Ask the provider whether inputs are logged, how long they are kept, whether they are used for training, and whether abuse-monitoring storage applies to your account. Record the answers next to the test plan, and recheck them when you change provider, region or account tier.
Keep unsafe test content out of logs
Attack prompts that trigger moderation are, by design, harmful content. Redact or hash them in CI console output, dashboards and shared reports, and store full results only in an access-controlled location. Share pass and fail counts with wider teams and keep the raw strings with the people who maintain the dataset.
Scope access to eval results
Results include the prompt, the model output and the moderation verdict for each case, which can reveal how the application responds to sensitive requests. Limit who can read result files and CI artifacts to the team that owns the guardrail, and set artifact expiry in your pipeline. The self-hosted server has no built-in RBAC or SSO, so shared result storage needs controls outside promptfoo.
Questions teams ask about moderation assertions in promptfoo
Should I use a moderation assertion or a guardrail test in promptfoo?
Use a moderation assertion when you want to check the content of what your application produced, such as whether a model response contains harmful categories. Use a guardrail test when you want to measure whether a guardrail in front of or behind your application blocks attacks and lets legitimate requests through. The two answer different questions, so most teams need both. A moderation assertion grades output text, while a guardrail test records the guardrail's decision and its effect on real requests. Decide first which question your release gate must answer, then pick the test type that answers it.
Which moderation provider does promptfoo use by default?
OpenAI moderation is the default provider for moderation assertions in promptfoo. Azure AI Content Safety is also supported as a moderation provider, so teams already running on Azure can grade output with the same service they use in production. When you use Replicate, LlamaGuard 4 is the default moderation model. Confirm the exact provider configuration in the promptfoo moderation documentation before you write your config, because provider options and defaults can change between releases.
What does setting up moderation assertions involve, and who pays for it?
Setup has three parts: configuring the moderation provider credentials, writing test cases with the output you want graded, and wiring the assertion into your eval run. If you run promptfoo yourself, your team carries this work and the cost of the moderation API calls that the provider bills to your account. If you hire a partner, the partner's fee covers the design and build, and the API usage still bills to your provider account. Ask any quote to separate one-time configuration from recurring API usage, and to state which accounts the charges land on.
What does the team need to provide before starting moderation tests?
You need access to the model or application under test, credentials for the moderation provider you choose, and a clear list of content categories that matter for your product. You also need example prompts and responses that reflect real traffic, so the grading results mean something for your users. Confirm with your security and compliance leads which categories and thresholds they expect to see in evidence, since promptfoo grades what you configure and does not decide your policy for you.
Can our own engineers run moderation assertions without outside help?
Yes, promptfoo is open source under the MIT license and runs locally, so an engineer who knows YAML and your model endpoints can add a moderation assertion to an existing eval. The harder work is choosing categories, building a representative test set and deciding what pass rate blocks a release. Teams without that experience often need a few iterations before results are trustworthy. Plan time for that review, and treat the first config as a draft rather than a finished control.
How does the promptfoo Community edition relate to moderation assertions?
The promptfoo Community edition is free and includes all LLM evaluation features and all model providers and integrations, so moderation assertions are part of what you get without a paid license. Enterprise adds team sharing, access control, SSO, continuous monitoring and a centralized guardrail dashboard, which matter once several teams need to review the same results. Check the promptfoo pricing page for current terms before you decide whether a shared deployment is needed.
What should we check if moderation results look wrong?
Start by confirming which provider and model graded the output, since the default and the alternatives score content differently. Then review a sample of flagged and unflagged outputs by hand to see whether the categories match your policy. Check that the moderation call itself succeeded, because provider errors should be tracked separately from passes and failures. If results still disagree with reviewers, adjust the categories or thresholds and rerun the same test set so changes are measurable.
How DeployOpen scopes moderation testing inside promptfoo
Moderation testing starts with a written scope agreed before any work begins. For work like this, that scope should name the moderation providers under test (OpenAI moderation by default, with Azure AI Content Safety or a Llama Guard deployment as alternatives), the moderation assertions and their categories in the promptfoo configuration, the datasets that define what counts as a pass, the application or endpoint whose output is checked, and the environment where promptfoo runs. It should also state who holds the API keys, where the results are stored, and who signs off on the thresholds that decide whether a release passes. Most engagements are fixed-scope, so deliverables and timelines are set out in this document before the first test is written, and changes to the scope are handled as written amendments rather than informal requests.
Ongoing work is handled through a retainer. A retainer suits teams whose model, system prompt or moderation provider changes often, because each change can alter what the moderation assertions see in the output. Under a retainer, the test suite is maintained, new categories and edge cases are added as the application grows, and the suite is rerun against changed configurations. Teams should confirm with DeployOpen how retainer scope, response expectations and reporting are defined in their written agreement, since those terms are set per engagement and are not published as standard.
DeployOpen prepares evidence from these tests, such as configuration records, test datasets, run outputs and findings with fixes and retests. It does not issue audit reports, attestations or certifications. If an auditor or certification body asks for evidence of output moderation, the reader should confirm with that body which artifacts it accepts and how they are presented, and treat the DeployOpen deliverables as inputs to that assessment rather than as its conclusion.

