Get Started with AWS Bedrock Guardrails
Using AWS Bedrock Guardrails with Portkey
Portkey provides native support for AWS Bedrock Guardrails to secure your LLM applications, including features like content filtering and PII detection.1. Create a guardrail on AWS Bedrock
- Navigate to
AWS Bedrock->Guardrails->Create guardrail - Configure the guardrail according to your requirements
- Once the guardrail is created, note the ID and version displayed on the console - you’ll need these to enable the guardrail in Portkey
2. Enable Bedrock integration on Portkey
- Navigate to the
Integrationspage in Portkey - Find and enable the Bedrock integration
- Add your AWS credentials on the integrations page
3. Create a guardrail on Portkey
- Navigate to the
Guardrailspage and click theCreatebutton - Search for
Apply bedrock guardrailand clickAdd - Enter the guardrail ID and version from step 1
- Configure any additional settings as needed
- Click
Createand note the Portkey Guardrail ID
4. Add the Portkey Guardrail ID to a config
Create a config with your guardrail:5. Attach the config to your requests
- NodeJS
- Python
- OpenAI NodeJS
- OpenAI Python
- cURL
Response handling
When using AWS Bedrock Guardrails through Portkey, the response will include details about any guardrail checks that were triggered. You can configure different behaviors based on your security requirements through the Portkey Guardrails UI.Using Raw Guardrails with AWS Bedrock
You can define AWS Bedrock guardrails directly in your code for more programmatic control without using the Portkey UI. This “raw guardrails” approach lets you dynamically configure guardrails based on your application’s needs.We recommend creating guardrails using the Portkey UI whenever possible. Raw guardrails are more complex and require you to manage credentials and configurations directly in your code.
Raw Guardrails Configuration Example
Raw Guardrails Configuration Example
Available AWS Bedrock Guardrails
| Guardrail Name | ID | Description | Parameters |
|---|---|---|---|
| Apply bedrock guardrail | bedrock.guard | Applies AWS Bedrock guardrail checks for LLM requests/responses | guardrailId (string), guardrailVersion (string), redact (boolean), timeout (number) |
Key Configuration Properties
type: Always set to"guardrail"for guardrail checksid: A unique identifier for your guardrailcredentials: Authentication details for AWS Bedrock (if using assumedRole)checks: Array of guardrail checks to runid: The specific guardrail ID - in this case,bedrock.guardparameters: Configuration options for the guardrail
deny: Whether to block the request if guardrail fails (true/false)async: Whether to run guardrail asynchronously (true/false)on_success/on_fail: Optional callbacks for success/failure scenariosfeedback: Data for logging and analyticsweight: Importance of this feedback (0-1)value: Feedback score (-10 to 10)
Implementation Example
When using raw guardrails, you must provide valid credentials for AWS Bedrock directly in your config. Make sure to handle these credentials securely and consider using environment variables or secrets management.

