View a markdown version of this page

Write policies with third-party checks - Amazon Bedrock AgentCore

Write policies with third-party checks

A third-party check goes in a when guardrails condition, like a BedrockGuardrails check. It names the provider namespace, the guardrail type, the categories to assess (for types that have categories), and the content to assess. Your condition then tests the result.

Before you write these policies, register the provider on your engine. For more information, see Register a third-party guardrail provider. A policy that calls a provider that isn’t registered on the engine fails validation.

Forms of a check

A third-party check has one of the following forms.

Form When to use it How to read the result

<Namespace>::<GuardrailType>([<content>])

A guardrail type without categories.

Read the result directly, with .level or .confidenceScore.

<Namespace>::<GuardrailType>([<categories>], [<content>])

A guardrail type with categories.

Read the result for one category by name, such as .<CATEGORY>.level or .<CATEGORY>.confidenceScore, or use an aggregation across the categories that you named.

<Namespace>::Custom("<profile>", [<content>])

A profile check. The provider evaluates the content against a profile or policy that you configured with the provider.

.allowed() returns true when the provider allows the content.

Where:

<Namespace>

The provider ID, such as CheckPoint or Zscaler. Some providers group their guardrail types, and the group is part of the name, as in PromptSecurity::Safety::HarmfulContentModerator.

<GuardrailType>

A guardrail type that the provider offers.

<categories>

One or more categories of the guardrail type, as strings.

<content>

The data paths to assess, such as context.input.prompt for a tool input field or "$.choices[*].message.content" for inference output. The rules are the same as for Amazon Bedrock Guardrails. For more information, see Passing context to your guardrail. For the data paths of each inference response format, see Recommended data paths.

For each provider’s guardrail types, categories, and results, see Third-party guardrail reference.

Testing the result

Providers return one of two kinds of result. The reference lists which one each provider uses.

Level (Check Point, Netskope)

A string such as l1_confident or high. Test it with contains against the levels you want to act on:

["l1_confident", "l2_very_likely"].contains(CheckPoint::PromptAttack([context.input.prompt]).level)
Confidence score (Prompt Security, Rubrik, Zscaler)

A decimal. Compare it with a decimal value. A bare number such as 0.8 isn’t valid:

Zscaler::PromptInjection([context.input.prompt]).confidenceScore.greaterThanOrEqual(decimal("0.9"))

The meaning of a level or score, and the thresholds to use, are defined by the provider. For guidance, see the provider’s documentation.

Aggregations

For guardrail types with categories, you can reduce the results across the categories you named instead of testing them one at a time. Which aggregations a type supports is listed in the reference.

maxConfidenceScore(), minConfidenceScore()

The highest or lowest score across the categories (score-based types only).

count()

How many of the categories were detected.

categories()

The set of categories detected.

Zscaler::PII(["US_SSN", "CREDIT_CARD"], [context.input.prompt]).maxConfidenceScore().greaterThan(decimal("0.8"))

Examples

The examples use a tool target named RefundTool with a process_refund tool that takes a reason argument. Replace the action and gateway ARN with your own.

Permit the tool only while a Check Point prompt-attack check isn’t triggered

permit( principal, action == AgentCore::Action::"RefundTool___process_refund", resource == AgentCore::Gateway::"arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/my-gateway-a1b2c3d4e5" ) when guardrails { !["l1_confident", "l2_very_likely", "l3_likely"].contains( CheckPoint::PromptAttack([context.input.reason]).level) };

Deny when Netskope rates weapons content high or medium

forbid( principal, action == AgentCore::Action::"RefundTool___process_refund", resource == AgentCore::Gateway::"arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/my-gateway-a1b2c3d4e5" ) when guardrails { ["high", "medium"].contains( Netskope::InappropriateContent(["WEAPONS"], [context.input.reason]).WEAPONS.level) };

Deny when Prompt Security scores hateful content at 0.8 or higher

forbid( principal, action == AgentCore::Action::"RefundTool___process_refund", resource == AgentCore::Gateway::"arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/my-gateway-a1b2c3d4e5" ) when guardrails { PromptSecurity::Safety::HarmfulContentModerator(["HATEFUL"], [context.input.reason]) .HATEFUL.confidenceScore.greaterThanOrEqual(decimal("0.8")) };

Deny when Rubrik reports a high or critical PII finding

forbid( principal, action == AgentCore::Action::"RefundTool___process_refund", resource == AgentCore::Gateway::"arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/my-gateway-a1b2c3d4e5" ) when guardrails { Rubrik::PIIDetection([context.input.reason]).confidenceScore.greaterThanOrEqual(decimal("0.75")) };

Deny when a Zscaler AI Guard profile doesn’t allow the content

forbid( principal, action == AgentCore::Action::"RefundTool___process_refund", resource == AgentCore::Gateway::"arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/my-gateway-a1b2c3d4e5" ) when guardrails { !Zscaler::Custom("<AI Guard user>", [context.input.reason]).allowed() };

A forbid grants nothing on its own. Pair it with a permit for the same action, and create it with --validation-mode IGNORE_ALL_FINDINGS, as described in Creating a policy with guardrails.

Third-party checks also work with interruptOutput, redactOutput, and redactInput. For an example, see Use a third-party provider.

Creating the policy

Create the policy like any other guardrail policy, with the statement in the policy field of definition:

aws bedrock-agentcore-control create-policy \ --policy-engine-id my_policy_engine-a1b2c3d4e5 \ --name BlockHighPii \ --validation-mode IGNORE_ALL_FINDINGS \ --definition '{ "policy": { "statement": "forbid (principal, action == AgentCore::Action::\"RefundTool___process_refund\", resource == AgentCore::Gateway::\"arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/my-gateway-a1b2c3d4e5\") when guardrails { Rubrik::PIIDetection([context.input.reason]).confidenceScore.greaterThanOrEqual(decimal(\"0.75\")) };" } }'

CreatePolicy returns 202. Poll GetPolicy until the status is ACTIVE or CREATE_FAILED. A category, guardrail type, or result field that the provider doesn’t support fails validation, and the reason is in statusReasons.

Note

AgentCore verifies the provider’s API key when you register the provider, so a policy that you create afterward uses a key that the provider accepted. For more information, see Verifying the API key.