Testing AWS Bedrock Guardrails with promptfoo

This page explains how to connect promptfoo to Bedrock Guardrails, measure blocks and false positives, and avoid CI results that depend on which Bedrock API returned the guardrail decision.

On this page

How promptfoo tests AWS Bedrock Guardrails for attacks and false blocks

A team that has Bedrock Guardrails in front of a model needs more than a configuration screenshot to show it blocks attacks without blocking legitimate users. The evidence has to come from running the same guardrail against a set of hostile prompts and a set of ordinary requests, then counting what was stopped and what should not have been. promptfoo tests Bedrock Guardrails through two methods: the guardrail settings on its bedrock provider, which apply the guardrail while promptfoo calls the model, and the ApplyGuardrail API, which evaluates content against a guardrail directly without invoking a model. This section explains how the two methods differ and which one to use for each test goal, and the rest of the page covers the setup, the assertions, image checks and the metadata differences between APIs.

The provider guardrail settings suit tests of the full application path. Use them when the question is whether the model and its guardrail together produce an acceptable response, because the guardrail runs as part of the model call that promptfoo already makes. The ApplyGuardrail method suits tests of the guardrail on its own, such as tuning a filter before any model is chosen, or checking content in an application that calls the API itself. Confirm in the current promptfoo Amazon Bedrock documentation which parameters each method accepts for your guardrail identifier and version before you write the config, since those fields change over time. Also confirm which guardrail policy types your account can use in your AWS Region.

This page covers the supported configuration for both methods, how to write attack and benign test sets against them, how image content is handled, and how to read guardrail metadata without misreading it. Keep the guardrail identifier, version and Region in your test config so every run can be traced to the exact guardrail that was tested. Before you rely on the guardrails assertion in CI, check the guardrail metadata that your chosen API returns, because that metadata is where a blocked request is recorded.

What you need before running Bedrock guardrail tests

Most failed first runs trace back to a missing prerequisite rather than a bad test. Each card below is one item to confirm before you point promptfoo at a Bedrock guardrail, so the first run measures the guardrail and not your setup.

Node.js runtime version

The current promptfoo release on npm requires Node.js 22.22.0 or newer. Check the runtime on the machine or CI runner that will execute evals, not only your workstation. Pin the version in your pipeline image so a later runner update does not silently change the test environment. Confirm the requirement against the release notes before each upgrade.

promptfoo on npm

AWS account and IAM permissions

The identity running the tests needs permission to invoke the guardrail, and to call the model if you use the bedrock provider with guardrail settings. Scope permissions to the specific guardrail and model ARNs your team uses. Confirm the exact IAM actions required for your chosen path (direct ApplyGuardrail calls or model invocation with guardrail configuration) in the promptfoo Amazon Bedrock docs and AWS documentation.

promptfoo Bedrock docs

Guardrail ID and version

Record the guardrail identifier and the exact version you are testing, not only the name. A draft version and a numbered version can apply different filters, so a test run without a pinned version cannot be reproduced later. Store both values in your promptfoo config so a result can be tied to a specific guardrail configuration during review.

Target region

Guardrails are regional resources, so the region in your promptfoo config must match where the guardrail was created. Calls to the wrong region fail with errors that can look like permission problems. Confirm which features and models are available in your region with the AWS documentation before you choose a region for a shared test environment.

Model access for the target

If your tests call a model through the bedrock provider, the account must have access to that model in the same region. Request model access in the Bedrock console before the first run. For ApplyGuardrail-only tests that never invoke a model, this item does not apply, so decide the test path first.

Known intervention for the metadata check

Guardrail metadata differs across InvokeModel, Converse streaming, cached responses and Bedrock Agents. Before you rely on the guardrails assertion in CI, export a known intervention from the API you plan to use and confirm the fields your assertion reads are present. This check catches a silent pass caused by missing metadata.

Bedrock metadata notes

How to configure the bedrock provider with a guardrail

This sequence connects promptfoo to a Bedrock model with a guardrail attached, then proves with one benign and one attack prompt that the guardrail intervention shows up in the output. Only after that check should you build a larger suite on top of it.

  1. Install promptfoo and confirm the runtime

    Install the promptfoo CLI on the machine or CI runner that will run the tests, using Node.js 22.22.0 or newer, since the current npm release requires that runtime. Run the version command to confirm the CLI starts. The step is done when the CLI reports a version and the Node.js check passes on the same host you plan to use for testing.

  2. Set AWS credentials through the standard chain

    Provide AWS credentials the way the AWS SDK normally finds them, such as a named profile, environment variables or an assumed role, rather than pasting keys into the promptfoo config. The principal needs permission to invoke the chosen model and to call the guardrail. Ask your AWS administrator to confirm those permissions for the account and Region. The step is done when a simple model call succeeds from the same shell without any key values written into config files.

  3. Create the guardrail and record its identifier and version

    In the Bedrock console or your infrastructure-as-code tooling, confirm the guardrail you want to test exists in the Region you call, and note its identifier and the version you intend to test. Use a numbered version, not the working draft, so results stay reproducible across runs. The step is done when you have written down the identifier and version and can see them in the console or your IaC output.

  4. Add the Bedrock provider with guardrail settings

    Create a minimal promptfooconfig.yaml that points a provider at your Bedrock model and adds the guardrail identifier and version under the provider's guardrail settings. Keep the prompt a plain pass-through so the model's behavior is not the thing being measured. Check the provider's documentation for the exact key names before you copy them. The step is done when promptfoo validate or a dry run parses the config without errors.

  5. Run one known benign and one known attack

    Add two test cases to the config: a short, clearly harmless request and a well-known prompt that your guardrail is expected to block. Run promptfoo eval against them. Open the results and look at the benign case first, then the attack case. The step is done when both cases produced output and you can see the status for each one.

  6. Confirm the guardrail intervention in the output

    Inspect the stored output for the attack case and find the guardrail intervention signal in the response metadata. Bedrock returns that signal differently depending on the API you call, so note the exact field your call path produces. The benign case should pass through without intervention. The step is done when you can point to the intervention field on the attack case and show that the benign case has none. If the field is missing, check the API path before going further.

  7. Record the verified baseline before adding a suite

    Save the working config and the two result files together with the guardrail identifier, version, model and Region, so later runs can be compared against a known starting point. Add a note that metadata field names were confirmed for this call path. Only after this baseline is saved should you expand the attack and benign datasets. The step is done when the config, results and notes are committed to the test repository and a second run reproduces the same two outcomes.

When to use provider guardrail settings versus ApplyGuardrail directly

Choose between the two paths by deciding what you need the test to prove. Attaching guardrail settings to the Bedrock provider in promptfoo tests the model call as a whole: the user prompt goes to the model, Bedrock applies the guardrail as part of that request, and the result is judged against the response your application would actually return. This path answers the question "does my deployed configuration block what it should while the model still answers benign requests?" It also picks up any interaction between the guardrail and the model, such as a blocked intervention that changes the response text. The cost is that a failure can come from the model, the prompt template or the guardrail, so you need the guardrail decision recorded separately before you can attribute a miss.

Calling ApplyGuardrail directly evaluates input or output text against the guardrail without invoking a model. This path isolates the guardrail, which suits large attack and benign datasets, threshold tuning and comparisons between guardrail versions, where you want the same text run through the same filter every time. The decision is read from the ApplyGuardrail response itself rather than from a model reply, so your provider or assertion must read the action and assessment fields that API returns. Use this path when a team wants to test the guardrail independently of the model, for example before a model change or when the guardrail is shared by several applications. Check which fields your guardrail version returns, since the promptfoo AWS Bedrock documentation notes that metadata differs across call types and the test should be validated against a known intervention first.

Why guardrail metadata differs across Bedrock APIs

This table compares how a Bedrock guardrail intervention appears across the API paths promptfoo can exercise, and where the guardrails assertion may read the wrong signal. Read each row before trusting a pass in CI, because a missing intervention field can look like a clean response. The main takeaway is to export a known intervention from each path you use and confirm the assertion sees it.

API pathWhere the intervention signal is readRisk for the guardrails assertion
InvokeModelGuardrail output fields in the model response body, as documented for the pathConfirm the field is populated for your model and guardrail version before treating its absence as a pass
Converse streamingGuardrail events delivered within the stream rather than a single final responseA check that reads only the final payload can miss an intervention that arrived mid-stream
Cached responsesMetadata stored from an earlier call, which may not reflect the current guardrail versionA cached response can carry stale or missing intervention data, so cached runs may pass for the wrong reason
Bedrock AgentsTrace and orchestration output rather than a standard model responseIntervention data may sit in a different structure, so the assertion may need a path-specific check
ApplyGuardrail (direct)Guardrail result returned by the standalone call, independent of a model invocationConfirm your provider settings send the content you intend to test, or the result will not reflect the application
Image checksImage content in the request, evaluated by the guardrail when image filters are configuredConfirm image handling and its returned fields for your setup before assuming a text-only assertion covers images
Known intervention exportA deliberately blocked prompt run through each path you use, with its raw output savedExport this once per path and keep it as a fixture so CI tests whether the assertion still reads the signal

Testing image inputs against Bedrock Guardrails

Image checks belong in the same test set as text, but they need their own rows, because a guardrail can screen the text of a request and pass an image without ever evaluating it. Treat the image path as a separate attack surface: build dedicated cases for images that carry instructions (text rendered inside a picture, screenshots of a prompt, or documents with embedded directives) and for images that are plainly harmless. Tag each row with its modality so that results for text-only, image-only and mixed text-and-image requests can be read separately in promptfoo. Before you build the dataset, confirm in the AWS documentation which Bedrock Guardrails content filters and configuration options accept image input, and which foundation models pass images through the API you plan to test. If image support differs by guardrail version, model or API operation, record that in the test plan so a passing result is never attributed to a path that was not exercised.

Benign images matter as much as attack images. Include product photos, charts, scanned forms, medical or diagram images and screenshots from your own domain, because these are the inputs most likely to be wrongly blocked. Keep each benign image paired with a plain-language reason it should pass, so that a false positive is visible in the report. Where a benign image contains text, add a text-only variant with the same words so you can tell whether a block came from the visual content or from the words.

Confirm that the image path is really evaluated, not just accepted. Export a known intervention, using an image you know the guardrail should block, and check the response for the guardrail action and assessment that show the image was screened. Then run the same image through a deliberately different configuration, such as a stricter filter setting, and confirm the outcome changes. If the outcome does not change, the image is probably being skipped, and no pass result from that row should be trusted. Only after this check should you add the image rows to a CI gate, since the metadata used by a guardrails assertion can differ between APIs and operations.

How a promptfoo test request reaches the Bedrock guardrail

The request starts in the promptfoo CLI, which loads the test case and sends it through either the Bedrock provider with guardrail settings or a direct ApplyGuardrail call. Bedrock returns a guardrail decision, and the model response follows only when the request was passed on to the model. The assertion then reads the guardrail metadata from that response, so check which API path produced the metadata before trusting a CI result. Confirm the exact fields against the promptfoo Bedrock docs for each path.

Request path from promptfoo to the Bedrock guardrail, showing where guardrail metadata is read.

Securing AWS credentials and test data for Bedrock tests

Bedrock guardrail tests send real attack prompts and AWS credentials through your machine or CI runner. promptfoo runs locally and talks directly with the LLM, so the security of that path is your responsibility, from the IAM principal to the attack dataset.

Least privilege for the test principal

Create a dedicated IAM principal for guardrail tests that can only invoke the models and guardrail versions under test. Grant bedrock:ApplyGuardrail or the model invocation actions needed for your chosen path, and nothing for administration or unrelated resources. Ask your AWS team to confirm the exact action names for your API path, since the set differs between InvokeModel, Converse and ApplyGuardrail.

Bedrock provider docs

Keep credentials out of configs and logs

Do not put access keys in promptfooconfig.yaml or commit them to the repository. Use the standard AWS credential chain, such as environment variables injected by your CI secret store, a named profile, or a short-lived role assumed by the runner. Check CI logs after a run, because verbose output and failed-request dumps can echo headers or configuration values.

Pin the guardrail version under test

Reference a specific numbered guardrail version rather than the working draft, so a result can be traced to one configuration. Record the guardrail ID, version and region in the eval output. When someone edits the guardrail, a new version gives you a clean before and after comparison instead of a silent change to your baseline.

Scope the test environment

Run guardrail tests in a separate AWS account or a non-production guardrail that mirrors production settings. This keeps test traffic, quotas and logging apart from live users. Confirm with your AWS owner which CloudWatch or invocation logging is enabled for the account, because attack prompts sent during tests may be stored there.

Handle sensitive attack datasets

Attack datasets can contain harmful instructions, leaked-looking personal data or content from regulated domains. Store them in a restricted repository location, limit who can read results, and decide whether generated outputs are redacted before sharing. Ask your compliance team whether the dataset itself needs a data classification and retention rule before it is used in CI.

Map the data path end to end

Prompts travel from the machine or runner where promptfoo executes directly to the AWS region hosting the guardrail. Nothing routes through a promptfoo-hosted service in the community workflow. Document this path, the region and any proxy or egress controls for your security review, and confirm with your network team which outbound endpoints the runner needs.

promptfoo introduction

Common Bedrock guardrail test failures and fixes

This table pairs the failures teams most often hit when running promptfoo against Bedrock Guardrails with the likely cause and the fix. Fixes marked as needing confirmation depend on AWS or promptfoo behavior that should be checked in current documentation or your own account before you rely on them. Use it as a triage list when a guardrail test result looks wrong.

SymptomLikely causeFix
Guardrail assertion passes on attack prompts with no interventionThe guardrail never ran, or the response was read from a path that does not carry guardrail metadataExport a known intervention first, then confirm the guardrail ID and version are sent with the request. Confirm the metadata field for your API path in the AWS and promptfoo docs.
Guardrail metadata missing on one API path but present on anotherGuardrail metadata differs across InvokeModel, Converse streaming, cached responses and Bedrock AgentsTest each API path you use separately. Do not reuse an assertion written for one path on another without a known-intervention check.
Cached response shows a guardrail result that does not match the current configurationA cached response was returned, so the guardrail did not run on this requestDisable or clear the cache for guardrail runs, then re-run the known-intervention case. Confirm cache behavior in the promptfoo caching docs.
AccessDenied or model not found errorsModel access is not granted in the account, or the model ID is not available in the chosen regionConfirm model access in the Bedrock console for the target region, and match the region in the provider config to where the guardrail was created.
Guardrail not found or ResourceNotFound errorsGuardrail ID or region is wrong, or the guardrail was created in another regionCopy the guardrail ID from the console for the same region as the runtime call. Confirm the expected identifier format in the AWS docs.
Every request fails before the guardrail runsCredential chain problem: wrong profile, expired session token, or environment variables overriding the intended roleCheck which credential source the AWS SDK resolves first, then test with a single known profile. Confirm the credential resolution order in the AWS SDK documentation.
Results change between a guardrail version and the draftThe test points to DRAFT or an older numbered version, not the version under reviewPin the exact guardrail version in config and record it in each run. Confirm version semantics for DRAFT in the AWS docs.
Throttling or ThrottlingException during large runsRequest rate exceeds account quotas for the runtime APILower concurrency, add retries with backoff, and check current quotas for your account and region in the AWS Service Quotas console.
Image checks return no guardrail resultThe image content is not in a format or modality the guardrail configuration covers, or the request does not send the image blockConfirm which image formats and guardrail filters apply to your configuration, and verify with one known image before running the full set.

Questions teams ask before testing Bedrock Guardrails with promptfoo

Is promptfoo free to use for testing Bedrock Guardrails?

Yes, the core tool is free. promptfoo is licensed under the MIT license, and its 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 Bedrock provider and guardrail settings are part of that feature set. Paid tiers, promptfoo Enterprise and promptfoo On-Premise, add team sharing, SSO, role-based access, continuous monitoring and a centralized guardrail dashboard, and they are priced on request. Confirm current terms on the pricing page before you plan a budget, because the Community limits are the first thing to check against your planned scan volume.

How much effort does a Bedrock Guardrails test setup take?

The effort depends on how much of the test suite you have to build, not on the tool itself. The main drivers are the number of guardrail configurations you compare, whether you test through the bedrock provider guardrail settings or call ApplyGuardrail directly, how many image checks you include, and how much of your benign traffic you can reproduce. Each additional guardrail version, policy or content type adds test cases and review time. Teams that already keep prompts and sample traffic in version control usually reach a working suite faster than teams starting from raw logs.

What does our team need to provide before the work starts?

You need an AWS account where the guardrail is created, with permission to invoke the guardrail and read its configuration, and a clear list of the guardrail versions and policies under test. You also need representative attack prompts and benign prompts drawn from your real application, sample documents or images if image checks matter, and a decision on which API path your application uses. Access to CI/CD runners or a place to run the Node.js-based CLI is also required. Ask your AWS team to confirm which regions and models your workloads use, because these affect which requests can be tested.

Can our internal engineers set this up without outside help?

Yes, a team with experience in AWS IAM, Bedrock and Node.js can usually build a first suite alone, because promptfoo runs locally and is driven by configuration files and assertions. The harder parts are usually the test design: separating attack and benign datasets, deciding what a guardrail intervention means for your application, and reading the metadata correctly across APIs. Teams without dedicated AI security capacity often bring in a partner for the test plan and review, then keep the suite in their own pipeline. Your engineers will still need to own the suite after handover.

How long does a first Bedrock Guardrails suite take to build?

No fixed duration applies, because the timeline is set by scope. A first suite covering one guardrail, a text-only test set and one API path is much smaller than a suite that compares several guardrail versions, adds image checks and wires results into CI with pass-rate gates. Scope, data availability and review cycles with your security and product teams are the main variables. In a fixed-scope engagement, the written plan sets the timeline, and the deliverables and dates are agreed before work begins.

Which Bedrock charges does promptfoo not control?

Calls to Bedrock are billed by AWS, and promptfoo does not set or change those charges. Each guardrail evaluation, model invocation and image check you run during tests can generate charges on your AWS account, and these recur every time a suite runs. Costs rise with the size of the attack and benign datasets, the number of guardrail versions compared, how often CI runs the suite and whether you test image inputs. Ask your AWS account owner for current Bedrock Guardrails pricing for your region before estimating a test budget, and set spend alerts in your account.

Do guardrail metadata differences affect what I can trust in CI?

Yes. Bedrock guardrail metadata is not identical across InvokeModel, Converse streaming, cached responses and Bedrock Agents, so a passing assertion in one path does not prove the same result in another. The promptfoo documentation advises exporting a known intervention from each path before relying on the guardrails assertion in CI. Plan for one known-blocked and one known-allowed case per API path you use, and treat any missing metadata as a test error rather than a pass.

How DeployOpen scopes and delivers Bedrock guardrail testing

DeployOpen works on Testing AWS Bedrock Guardrails with promptfoo as a written, fixed-scope engagement. We agree which Bedrock guardrail configurations, invocation paths and attack and benign datasets are in scope, then build the promptfoo test suite in your environment and hand over the results with the runbook your team needs to repeat it.

How we scope

  • Confirm which Bedrock guardrails, versions and regions are under test before work starts
  • Agree whether tests call the bedrock provider guardrail settings, ApplyGuardrail directly, or both
  • Define image checks, attack sets and benign sets, with owners for approving the data used

How we build

  • Configure promptfoo to run in a runner or workstation you control, with AWS credentials scoped to the test account
  • Export a known guardrail intervention from each invocation path before writing guardrail assertions
  • Separate provider errors from guardrail blocks and benign-set false positives in the test reports

How we hand over

  • Deliver the promptfoo configuration, datasets, assertion definitions and a short note on metadata differences
  • Document how to rerun the suite after a guardrail version or policy change
  • Walk your security and platform teams through the results, open findings and remaining gaps

How we support

  • Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing
  • Ongoing support, upgrades and continuous testing are available as a retainer
  • Confirm the scope, data handling and access model with DeployOpen before any quote is issued

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.