Certopolis

AWS Certified Developer – Associate

Amazon Bedrock Guardrails policies and filters for DVA-C03

The Amazon Bedrock User Guide describes a guardrail as a set of filters that check prompts and model responses: content filters, denied topics, word filters, sensitive information filters and contextual grounding checks. You attach a guardrail version to an inference call, or call ApplyGuardrail to check text without invoking a model.

What does each guardrail policy do?

Content filters detect harmful text in the categories Hate, Insults, Sexual, Violence, Misconduct and Prompt Attack, with a strength you set per category. Misconduct covers seeking or giving information about criminal activity or defrauding a person or organization.

Denied topics block a subject. Each topic has a name, a definition of up to 200 characters and up to five sample phrases, and a guardrail can hold up to 30 topics. The definition describes the subject. It must not be an instruction such as "Block all content about cryptocurrency", and topics should not be used to catch a single word or a person's name.

Word filters block custom words and phrases with case-insensitive whole-word matching, plus a ready-made profanity list. Sensitive information filters detect built-in PII types such as NAME and EMAIL and custom regex patterns. Block rejects the whole content. Mask replaces each match with its type, for example {NAME}.

Contextual grounding checks flag or block a response that is not grounded in the supplied source or is not relevant to the user's query, which suits retrieval-augmented generation.

Prompt attacks and input tags

The prompt attack filter covers jailbreaks, prompt injection and, in the Standard tier only, prompt leakage. A user's injection attempt can look like a developer's system prompt, so the guardrail needs to know which part of the prompt is user input.

With InvokeModel and InvokeModelWithResponseStream you wrap the user input in guardrail input tags. Without tags, prompt attacks are not filtered for those operations. With the Converse API the guardContent block does the same job.

Guardrail filters evaluate text. In tool use they do not evaluate tool results, tool definitions or the tool call arguments the model generates.

How is a guardrail applied?

For inference, pass the guardrail ID and version. In Converse and ConverseStream this is guardrailConfig with guardrailIdentifier, guardrailVersion and an optional trace. ApplyGuardrail evaluates any text with no model call. Set source to INPUT for user content and OUTPUT for model output. In a RAG application it can check the question before retrieval runs.

Streaming has two modes. The default synchronous mode buffers chunks and scans them before they are sent, which adds latency. Setting streamProcessingMode to ASYNCHRONOUS sends chunks at once and scans in the background, so a chunk can reach the user before the scan finishes, and masking of sensitive information is not supported.

A new guardrail has a working draft. A version is a snapshot that you create for production. Versions have no ARN of their own, so IAM policies restrict a version with the bedrock:GuardrailIdentifier condition key.

Filtering AI model inputs and outputs sits in Task 2.3 of the exam guide, a task that AWS lists as new in DVA-C03.

Where the exam catches people

  • Believing a denied topic definition should be an instruction to the guardrail: actually it must describe the subject and its subtopics.
  • Believing a denied topic is the way to block one person's or competitor's name: actually word filters or sensitive information filters handle words and entities.
  • Believing ApplyGuardrail runs the prompt through a model: actually it only evaluates the text against the guardrail.
  • Believing asynchronous streaming scans every chunk before the user sees it: actually only the default synchronous mode buffers and scans first.
  • Believing the prompt attack filter checks untagged InvokeModel prompts: actually user input must be wrapped in guardrail input tags for those operations.

Written from these sources

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. A developer is building a customer assistant for an accounting software company with Amazon Bedrock. The assistant must not discuss personal tax planning, whether a user asks about it or the model starts on it. The developer is adding this rule to the assistant's Amazon Bedrock guardrail. Which solution will meet these requirements?

    Right. In the game that’s Renown for your Security building.

    Not that one: C is right. In the game your Security building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    The definition should describe the subject itself, here the questions and advice it covers, so that the guardrail knows what to look for.

    Written from docs.aws.amazon.com/bedrock/latest/userguide/guardrails-components.html

  2. A retrieval-augmented generation (RAG) application takes each user question, retrieves passages from a vector store, and then calls a foundation model in Amazon Bedrock. Questions that violate the company's Amazon Bedrock guardrail must be stopped before the vector store is searched. The check itself must not invoke a foundation model. Which solution will meet these requirements?

    Right. In the game that’s Renown for your Security building.

    Not that one: C is right. In the game your Security building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    Calling it on the question with the source set to INPUT before the search, and continuing only when the action is NONE rather than GUARDRAIL_INTERVENED, stops violating questions before the vector store is touched. The guardrail documentation describes this placement for RAG applications.

    Written from docs.aws.amazon.com/bedrock/latest/userguide/guardrails-use-independent-api.html

  3. A health information app streams model responses to users with the InvokeModelWithResponseStream API and an Amazon Bedrock guardrail. The guardrail has a denied topic for personal medical diagnoses. Responses must keep streaming, and compliance requires that no chunk containing diagnosis content ever reaches a user's screen. Which solution will meet these requirements?

    Right. In the game that’s Renown for your Security building.

    Not that one: D is right. In the game your Security building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    Leaving streamProcessingMode out keeps that default.

    Written from docs.aws.amazon.com/bedrock/latest/userguide/guardrails-streaming.html

Ask for something