Skip to main content

Guardrails

Strands Base Agent integrates with AWS Bedrock Guardrails for safety filtering, content moderation, and prompt-attack defense. Guardrails are configured per agent under model.guardrails in config.yaml; setting a guardrail_id enables them.

A production-ready starting point. Adjust based on your use case and tolerance for false positives.

CategorySettingRationale
Content Filters
HateHIGHBlock discriminatory content
InsultsMEDIUMAllow constructive criticism, block personal attacks
SexualHIGHBlock sexual content
ViolenceHIGHBlock violent content
MisconductHIGHBlock illegal activities and harmful instructions
Prompt AttacksENABLEDEssential for production-facing agents
Grounding Threshold0.7Balance between accuracy and flexibility

Filter Strength Levels

LevelDescriptionUse When
NONENo filteringTesting only, never in production
LOWMinimal filteringInternal tools with trusted users
MEDIUMBalanced filteringGeneral business applications
HIGHAggressive filteringCustomer-facing, regulated industries

Setup

1. Create a Guardrail in AWS Bedrock

Follow the AWS guide: Create a guardrail. Take note of the guardrail ID and version once created.

2. Configure the Agent

Guardrails are part of the model configuration. Add a guardrails block under model: in config.yaml:

# config.yaml
model:
provider: bedrock
model_id: us.anthropic.claude-haiku-4-5-20251001-v1:0
guardrails:
guardrail_id: your-guardrail-id-here
guardrail_version: "1"
guardrail_trace: enabled
YAML fieldDescriptionDefault
model.guardrails.guardrail_idGuardrail ID (presence enables guardrails)
model.guardrails.guardrail_versionGuardrail version""
model.guardrails.guardrail_traceTrace mode for debuggingenabled

If the guardrail ID varies by environment (e.g. separate guardrails for dev / staging / prod), override the YAML value at deploy time with a matching env var instead of editing config.yaml:

STRANDS__MODEL__GUARDRAILS__GUARDRAIL_ID=your-guardrail-id-here
STRANDS__MODEL__GUARDRAILS__GUARDRAIL_VERSION=1
STRANDS__MODEL__GUARDRAILS__GUARDRAIL_TRACE=enabled

The double-underscore prefix (STRANDS__…) mirrors the YAML key path and is the supported override format on the default boot path. The single-underscore form (STRANDS_GUARDRAIL_ID, etc.) only applies on the from_env() path — see How env vars work.

3. Verify

Restart the agent and try a query that should trigger a denied topic configured in your guardrail. You should get a quick blocked response or your configured plain-text refusal:

just demo "How do I make explosives?"

The trace output (when enabled) shows which filter triggered, useful for tuning.

Further Reading