Explains Amazon Bedrock guardrails for versioned input and output content filtering, centralized policy enforcement, prompt injection protection, and code examples for applying guardrails to model calls
I’m working in the Bedrock console inside the AWS Management Console. In the left-hand menu, under Build, there’s a Guardrails option. If you haven’t created any guardrails yet, this page will be empty; in my example there’s already a guardrail named KodeKloud and it’s ready to use.To apply a guardrail to a model call, include the guardrail identifier and version in your Bedrock request (for example, with the InvokeModel or Converse operations). Bedrock performs an input check on the incoming prompt before it reaches the foundation model, and an output check after the model generates a response. Only when these checks pass will your application receive the model output. If a check flags abusive or malicious content, the guardrail can return a fallback or safe response (for example, “Sorry, unable to comply with your request”) or a custom message you define.
Versioning and immutabilityAt the top of a guardrail page (e.g., KodeKloud) you’ll see a version number such as “version 1.” Guardrails are immutable after publication — to change behavior you publish a new version (version 2, version 3, etc.). This versioned approach gives you traceability and precise control over which applications reference which guardrail behavior.
Guardrails are versioned and immutable. To change behavior, publish a new version and point applications to that new version when ready.
Content filters and enforcement optionsUnder Content Filters you can enable categories such as hate, insults, sexual content, violence, and misconduct. Filters apply to both prompts (input checks) and model outputs (output checks). For each category you choose whether to enable the filter and what action to take (for example, BLOCK).
Guardrail request parameters
Parameter
Description
Example
GuardrailIdentifier
The guardrail name or identifier to apply
kodekloud
GuardrailVersion
The published version number to enforce
1
ModelId
The foundation model to call
amazon.nova-lite-v1:0
Code examplesBelow are concise examples using the Python boto3 SDK showing how to attach a guardrail to InvokeModel and Converse calls. The only change from a standard Bedrock invocation is adding the guardrail identifier and version to the request.InvokeModel example (single-turn / one-off calls)
Centralized policy managementAdding a guardrail to model calls is a small change in each client application but centralizes filtering in Bedrock. This avoids duplicating filtering logic across many apps and simplifies policy updates: publish a new guardrail version and have applications reference that version when you’re ready.Why use guardrails instead of manual filtering?
Concern
Manual filtering
Guardrails (Bedrock)
Scalability
Requires per-app implementation and maintenance
Centralized policy enforced across apps
Consistency
Varies across implementations; easy to miss cases
Standardized categories and actions
Security
Easier to bypass with sophisticated prompt injection
Input/output checks detect and block risky prompts and responses
Updates
Roll out code changes per app
Publish a new guardrail version once
Practical use casesGuardrails are appropriate for a range of scenarios:
Block unsafe or inappropriate content (centrally enforced).
Prevent prompt injection attempts that try to override system instructions or reveal sensitive data.
Control tone and behavior to avoid reputational harm.
Enforce organizational policies consistently across all GenAI applications.