View a markdown version of this page

Register a third-party guardrail provider - Amazon Bedrock AgentCore

Register a third-party guardrail provider

To use a third-party provider, store your provider API key in AgentCore Identity, give the gateway’s execution role permission to read it, and register the provider on your policy engine.

Prerequisites

  • An account with the provider, and an API key for the provider’s guardrail API. To get a key, follow the provider’s documentation. For links, see Supported providers.

  • A policy engine attached to a gateway. For more information, see Create a policy engine.

Step 1: Store the provider API key

Store the key as an API key credential provider in AgentCore Identity. For console steps, see Add API key.

Example
AWS CLI
aws bedrock-agentcore-control create-api-key-credential-provider \ --name my-guardrail-provider-key \ --api-key "<your provider API key>"
AWS Python SDK (Boto3)
import boto3 client = boto3.client("bedrock-agentcore-control") response = client.create_api_key_credential_provider( name="my-guardrail-provider-key", apiKey="<your provider API key>", ) print(response["credentialProviderArn"])

Keep the credentialProviderArn from the response. You use it when you register the provider.

Store the credential that your provider uses to authenticate its guardrail API. For which credential to use, see the provider’s documentation.

If you store the key in your own AWS Secrets Manager secret instead (Provide API key via Secrets Manager in the console), tag the secret with BedrockAgentCoreThirdPartyGuardrailsSecret = true, so that the permissions in Step 2 let the gateway read it.

Step 2: Let the gateway read the key

Policy in AgentCore reads the API key with credentials derived from the gateway’s execution role, the same way it calls Amazon Bedrock Guardrails. Use the following permission policy for the gateway’s execution role. It includes the permissions to evaluate policies and Amazon Bedrock Guardrails checks, and the permissions for third-party providers.

Important

Replace these placeholders:

  • us-east-1 with the AWS Region

  • 123456789012 with the AWS account ID

  • <gateway-name> with the gateway name

  • <policy-engine-id> with the policy engine ID

{ "Version": "2012-10-17", "Statement": [ { "Sid": "EvaluatePoliciesForGateway", "Effect": "Allow", "Action": [ "bedrock-agentcore:AuthorizeAction", "bedrock-agentcore:PartiallyAuthorizeActions" ], "Resource": [ "arn:aws:bedrock-agentcore:us-east-1:123456789012:gateway/<gateway-name>-*", "arn:aws:bedrock-agentcore:us-east-1:123456789012:policy-engine/<policy-engine-id>" ] }, { "Sid": "GetPolicyEngineForValidation", "Effect": "Allow", "Action": [ "bedrock-agentcore:GetPolicyEngine" ], "Resource": [ "arn:aws:bedrock-agentcore:us-east-1:123456789012:policy-engine/<policy-engine-id>" ] }, { "Sid": "EvaluatePoliciesGuardrailsForGateway", "Effect": "Allow", "Action": [ "bedrock:InvokeGuardrailChecks" ], "Resource": "*" }, { "Sid": "GetWorkloadAccessTokenForThirdPartyGuardrails", "Effect": "Allow", "Action": [ "bedrock-agentcore:GetWorkloadAccessToken" ], "Resource": [ "arn:aws:bedrock-agentcore:us-east-1:123456789012:workload-identity-directory/default", "arn:aws:bedrock-agentcore:us-east-1:123456789012:workload-identity-directory/default/workload-identity/*" ] }, { "Sid": "GetResourceApiKeyForThirdPartyGuardrails", "Effect": "Allow", "Action": [ "bedrock-agentcore:GetResourceApiKey" ], "Resource": [ "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/default", "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/default/apikeycredentialprovider/*", "arn:aws:bedrock-agentcore:us-east-1:123456789012:workload-identity-directory/default", "arn:aws:bedrock-agentcore:us-east-1:123456789012:workload-identity-directory/default/workload-identity/*" ] }, { "Sid": "GetManagedThirdPartyGuardrailApiKeySecrets", "Effect": "Allow", "Action": [ "secretsmanager:GetSecretValue" ], "Resource": "arn:aws:secretsmanager:us-east-1:123456789012:secret:bedrock-agentcore-identity!default/apikey/*" }, { "Sid": "GetTaggedExternalThirdPartyGuardrailApiKeySecrets", "Effect": "Allow", "Action": [ "secretsmanager:GetSecretValue" ], "Resource": "arn:aws:secretsmanager:us-east-1:123456789012:secret:*", "Condition": { "StringEquals": { "secretsmanager:ResourceTag/BedrockAgentCoreThirdPartyGuardrailsSecret": "true" } } } ] }

The statements do the following:

  • EvaluatePoliciesForGateway and GetPolicyEngineForValidation let the gateway evaluate the policies of its policy engine.

  • EvaluatePoliciesGuardrailsForGateway lets Policy in AgentCore call Amazon Bedrock Guardrails checks.

  • GetWorkloadAccessTokenForThirdPartyGuardrails and GetResourceApiKeyForThirdPartyGuardrails let Policy in AgentCore get the provider API key from AgentCore Identity.

  • GetManagedThirdPartyGuardrailApiKeySecrets lets it read API keys that AgentCore Identity stores for you.

  • GetTaggedExternalThirdPartyGuardrailApiKeySecrets lets it read API keys that you store in your own Secrets Manager secrets. It applies only to secrets tagged BedrockAgentCoreThirdPartyGuardrailsSecret = true. If you don’t use your own secrets, you can omit this statement.

For the trust policy and the other permissions of the execution role, see AgentCore Gateway and Policy in AgentCore IAM Permissions. If the role can’t read the key, every request that reaches a third-party check is denied.

If the secret uses a customer managed key

If the Secrets Manager secret that holds the API key is encrypted with a customer managed AWS KMS key, the gateway’s execution role also needs permission to decrypt with that key, through Secrets Manager.

Add the following statement to the gateway’s execution role:

{ "Sid": "DecryptThirdPartyGuardrailApiKeySecrets", "Effect": "Allow", "Action": "kms:Decrypt", "Resource": "arn:aws:kms:us-east-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab", "Condition": { "StringEquals": { "kms:ViaService": "secretsmanager.us-east-1.amazonaws.com" } } }

The key policy must also allow the gateway’s execution role to use the key. Add a statement like the following to the key policy:

{ "Sid": "AllowGatewayExecutionRoleDecryptViaSecretsManager", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:role/my-gateway-execution-role" }, "Action": "kms:Decrypt", "Resource": "*", "Condition": { "StringEquals": { "kms:ViaService": "secretsmanager.us-east-1.amazonaws.com" } } }

This applies to your own secrets that use a customer managed key. To use a customer managed key on the AgentCore Identity token vault, see Set customer managed key policy.

Step 3: Register the provider on the policy engine

To register a provider, add it to the engine’s policyInformationProviderConfiguration map. The key is the provider ID. For each provider’s ID, see Supported providers. The value names the credential provider and, optionally, your provider URL.

credentialProvider

The ARN of the API key credential provider from Step 1, as {"apiKey": {"arn": "…​"}}.

url

Your provider URL. If you omit it, the provider’s default URL is used. Set it if your provider account uses a different Region or deployment. For the URL to use, see the provider’s documentation. The URL must use https, its host must be one of the provider’s allowed hosts, and it must not include a port. For each provider’s rule, see Third-party guardrail reference.

You can register providers on an existing engine, or when you create the engine. The two operations use different shapes for each entry:

  • CreatePolicyEngine takes credentialProvider and url directly in the entry. url is a string.

  • UpdatePolicyEngine wraps the fields in providerConfiguration, and url is an object, {"optionalValue": "<URL>"}. The wrapper lets an update change only the fields that you name.

Example
Console
  1. Open the AgentCore console, choose Policy, and then choose your policy engine.

  2. In the Guardrail providers section, choose Register guardrail provider. The list already includes Bedrock Guardrails (provided by default).

    Policy engine details page showing the Guardrail providers section with Bedrock Guardrails provided by default and the Register guardrail provider button.
  3. For Provider, choose the provider.

  4. (Optional) For Detection endpoint, enter your provider URL. Leave it blank to use the provider’s default URL. The URL must start with https://.

  5. For API key, choose the API key credential provider that you created in Step 1. To create one now, choose create new.

    Register guardrail provider page with the Provider, Detection endpoint, and API key fields.
  6. Choose Register guardrail provider.

    The provider appears in the Guardrail providers list with its endpoint and the authentication type API key.

    Guardrail providers list showing Bedrock Guardrails provided by default and Check Point registered with endpoint https://api.lakera.ai and authentication type API key.
AWS CLI

To register a provider on an existing engine:

aws bedrock-agentcore-control update-policy-engine \ --policy-engine-id my_policy_engine-a1b2c3d4e5 \ --policy-information-provider-configuration '{ "<ProviderId>": { "providerConfiguration": { "credentialProvider": { "apiKey": { "arn": "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/default/apikeycredentialprovider/my-guardrail-provider-key" } }, "url": {"optionalValue": "https://<provider endpoint>"} } } }'

To register a provider when you create the engine:

aws bedrock-agentcore-control create-policy-engine \ --name my_policy_engine \ --policy-information-provider-configuration '{ "<ProviderId>": { "credentialProvider": { "apiKey": { "arn": "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/default/apikeycredentialprovider/my-guardrail-provider-key" } }, "url": "https://<provider endpoint>" } }'
AWS Python SDK (Boto3)
import boto3 client = boto3.client("bedrock-agentcore-control") ENGINE_ID = "my_policy_engine-a1b2c3d4e5" KEY_ARN = ("arn:aws:bedrock-agentcore:us-east-1:123456789012:" "token-vault/default/apikeycredentialprovider/my-guardrail-provider-key") client.update_policy_engine( policyEngineId=ENGINE_ID, policyInformationProviderConfiguration={ "<ProviderId>": { "providerConfiguration": { "credentialProvider": {"apiKey": {"arn": KEY_ARN}}, "url": {"optionalValue": "https://<provider endpoint>"}, } } }, ) # UpdatePolicyEngine returns 202 - wait until the engine is ACTIVE again client.get_waiter("policy_engine_active").wait(policyEngineId=ENGINE_ID)

An update changes only the providers and fields that you name. To register another provider, call UpdatePolicyEngine with that provider’s ID and a credentialProvider. To change the URL back to the provider’s default URL, send "url": {}.

Remove a provider

To remove a provider from an engine, call UpdatePolicyEngine with an empty object for the provider ID:

aws bedrock-agentcore-control update-policy-engine \ --policy-engine-id my_policy_engine-a1b2c3d4e5 \ --policy-information-provider-configuration '{"<ProviderId>": {}}'

You can’t remove a provider while a policy of the engine calls its checks. Delete or update those policies first. Otherwise the request fails with a ConflictException. You can’t remove BedrockGuardrails.

Verifying the API key

When you register a provider, AgentCore verifies your API key by sending a short test request to the provider. If the provider rejects the key, can’t be reached, or the URL isn’t found, the registration fails. The engine status becomes CREATE_FAILED or UPDATE_FAILED, and statusReasons names the provider and the reason, for example:

<ProviderId>: Invalid credentials for provider <ProviderId> (HTTP 401)

Fix the API key or URL and register the provider again.

Step 4: Check the configuration

In the console, the Guardrail providers section of the policy engine lists each registered provider with its endpoint and authentication type. With the API, GetPolicyEngine returns each registered provider with its credential provider, URL, settings, and the checks it offers. BedrockGuardrails always appears in the list. It’s built in and managed by the service.

aws bedrock-agentcore-control get-policy-engine \ --policy-engine-id my_policy_engine-a1b2c3d4e5 \ --query 'policyInformationProviderConfiguration'

Configuration rules

  • The URL must be an absolute https URL without a port, credentials, or whitespace, and its host must be one of the provider’s allowed hosts. Other URLs are rejected with a ValidationException, for example URL host is not an endpoint of this provider or URL must not set a port.

  • settings.windowSize is set by the service for each provider. It appears in GetPolicyEngine output, but you can’t set it. A request that includes it is rejected. The gateway uses the window size when it screens a streamed response. For more information, see When you receive the text.

  • You can’t configure BedrockGuardrails in policyInformationProviderConfiguration. A request that includes it is rejected with The BedrockGuardrails configuration is managed by the service and cannot be modified.

Next, write policies that call the provider. See Write policies with third-party checks.