Security · Topic 6 of 6

Guardrails and AI Agent Security

Filter model inputs and outputs with Amazon Bedrock Guardrails, and secure AI agents with tool authorization, session isolation and human approval.

  • 5 min
In a nutshell
  • Guardrails combine content filters, prompt attack detection, denied topics, word filters, sensitive information filters and grounding checks.
  • Attach a guardrail with guardrailConfig. Use ApplyGuardrail when no model call is involved.
  • guardrail_intervened covers both blocking and masking. The trace shows which one happened.

What it is

A model will answer what it is asked, including things you did not intend. Amazon Bedrock Guardrails adds a configurable check on what goes into the model and what comes out.

An agent goes further: it decides to call tools, such as APIs and databases, on a user's behalf. Securing an agent means authorizing each tool call, separating one user's session from another's, and asking a human before sensitive actions.

The exam guide treats designing AI safety frameworks as out of scope. Your job is to configure and call these controls correctly.

User promptchecked by guardrailModelBedrockchecked by guardrailResponsesafe text or blocked message

How it works

What a guardrail can filter

You create a guardrail with one or more policies and a message to return when something is blocked.

PolicyWhat it does
Content filtersDetect harmful categories (hate, insults, sexual, violence, misconduct), with adjustable strength
Prompt attack filterDetects jailbreaks and prompt injection in user input
Denied topicsBlock topics you define in plain language, such as investment advice
Word filtersBlock exact words or phrases, including a profanity list
Sensitive information filtersDetect PII types and custom regular expressions, then block or mask
Contextual grounding checksFlag responses not supported by the source text, for retrieval based apps
Automated Reasoning checksValidate responses against logical rules you define

Masking replaces a detected value with a placeholder such as {EMAIL}. Blocking replaces the whole message with your configured text.

Using a guardrail in code

Create a guardrail, then create a version. Applications should reference a numbered version rather than the working DRAFT.

  • Converse and ConverseStream: add guardrailConfig with guardrailIdentifier, guardrailVersion and optionally trace set to enabled.
  • InvokeModel: pass the guardrail identifier and version with the request.
  • ApplyGuardrail: a separate API that checks any text against a guardrail without calling a model. Use it to screen content that does not go through a model call, or text from another source.

When a guardrail steps in, the response stopReason is guardrail_intervened. Masking also returns this same stop reason, so you cannot tell a block from a mask by stopReason. Read the trace: the action is BLOCKED or ANONYMIZED.

Use a guardContent block to tell the guardrail which part of a message to evaluate. Once any guardContent block exists, only the content inside those blocks is evaluated. A system prompt is checked only if you wrap it in guardContent.

Two limits matter. With Converse tool use, a guardrail does not evaluate tool results your application returns, tool definitions, or the arguments the model generates for a tool call. Check those yourself. Also, the trace includes the unmasked values, so protect it like sensitive data.

AppConverse callguardrailConfigGuardrailinput checkmodel callModelGuardrailoutput checkstopReasonApphandles block or mask

Securing agent interactions

Tool authorization. Give the agent's role only the actions its tools need. For tools behind Amazon Bedrock AgentCore Gateway, inbound callers are authorized with a JWT from an identity provider such as Amazon Cognito, or with IAM credentials. Do not use a gateway set to no authorization in production.

Amazon Bedrock AgentCore Identity manages agent identities and credentials, so an agent can act for a user without secrets in code.

Session isolation. Amazon Bedrock AgentCore Runtime gives each session its own microVM, and clears its memory when the session ends. Your application must create a unique session ID for each user (at least 33 characters) and keep the user to session mapping, because AgentCore does not enforce it. Session context keys such as aws:AgentCoreRuntimeSourceSid let one execution role policy limit each session to its own S3 prefix.

Human approval. A tool result can contain text that tells the agent to take another action, which is an indirect prompt injection. In Amazon Bedrock Agents you can turn on user confirmation for an action group function. The agent then returns the proposed call, the user chooses CONFIRM or DENY, and your code sends that answer back in the next InvokeAgent request as confirmationState. With DENY the call does not run. Return of control lets your application run the action itself instead of the agent calling it.

How the exam asks about this

  • "Customer emails must be redacted from model answers" -> a sensitive information filter set to mask.
  • "The agent can delete records; ensure the user approves first" -> enable user confirmation for that action.
  • "Users must not see each other's agent state" -> a unique runtime session ID per user, with isolated sessions.

What to remember for the exam

  • Guardrails combine content filters, prompt attack detection, denied topics, word filters, sensitive information filters and grounding checks.
  • Attach a guardrail with guardrailConfig. Use ApplyGuardrail when no model call is involved.
  • guardrail_intervened covers both blocking and masking. The trace shows which one happened.
  • Converse guardrails do not evaluate tool results, tool definitions or tool call arguments.
  • Use user confirmation or return of control for sensitive agent actions.
  • Isolate agent sessions per user, and scope each session's credentials to its own data.
Watch out

Guardrail traces and blocked content in invocation logs can contain the very data you tried to hide. Do not write them to general purpose logs.

Common mistakes

Relying on the prompt alone. A system prompt that says "ignore harmful requests" can be bypassed. Use the guardrail's prompt attack filter as well.

Assuming tool output is checked. In Converse tool use, results returned by your tools are not evaluated by the guardrail.

Sharing one session ID across users. A shared ID mixes context between people. Create one per user or conversation.

Check yourself

  • How do you tell whether a guardrail blocked or masked content?

    Both return guardrail_intervened, so enable the trace and read the action value, BLOCKED or ANONYMIZED.

  • Which API checks text against a guardrail without invoking a model?

    ApplyGuardrail.

  • How do you make an agent get approval before a sensitive action?

    Turn on user confirmation for the action, and send the user's CONFIRM or DENY back as confirmationState.

Topic 6 of 6 in Security

Test yourself on Security

The full AWS DVA-C03 question bank has 850 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.