Certopolis

AWS Certified Generative AI Developer – Professional

ApplyGuardrail API and guardrail input tags for AIP-C01

ApplyGuardrail checks any text against a guardrail without calling a model, with source set to INPUT or OUTPUT. Use it for text a guardrail on the model call never sees, such as retrieved passages or tool results. Input tags limit which part of a prompt a guardrail checks, and a prompt attack filter only checks tagged content.

ApplyGuardrail

ApplyGuardrail assesses text with a guardrail you already built, without invoking a foundation model, and you can call it anywhere in your application flow. Set source to INPUT for user content and OUTPUT for model output. If the guardrail masks content, the output holds the masked text. If it blocks, the output is the blocked message. If it does not intervene, the output is empty.

Example 1: a research assistant returns fetched web page text to the model in toolResult blocks. Calling ApplyGuardrail with source INPUT on each page, before returning it, lets the existing prompt attack filter catch instructions hidden in the page.

Example 2: RetrieveAndGenerate with a guardrail masks national ID numbers in answers, but the guardrail is applied only to the input and the generated response. It is not applied to the retrieved references. Running each displayed passage through ApplyGuardrail masks them too.

Input tags with InvokeModel

For InvokeModel and InvokeModelWithResponseStream, wrap the text to check in <amazon-bedrock-guardrails-guardContent_xyz> tags and pass xyz as tagSuffix in amazon-bedrock-guardrailConfig. Content outside the tags is not evaluated. With no tags the whole prompt is evaluated, except by prompt attack filters, which require input tags.

Use a new random tagSuffix for every request. A fixed suffix lets a user close the tag and append content after it. The suffix is 1 to 20 alphanumeric characters.

guardContent with Converse

With the Converse API, use guardContent blocks instead of XML tags. Once any guardContent block is present in the messages, only guardContent blocks are evaluated. The system prompt is assessed only if it has its own guardContent block. When a guardrail intervenes, stopReason is guardrail_intervened, and with trace enabled the details are in the trace field.

Where the exam catches people

  • Believing a guardrail on RetrieveAndGenerate also screens the retrieved references: it covers only the input and the generated response.
  • Believing a guardrail on the Converse call screens tool results well enough: ApplyGuardrail on the fetched text, before it reaches the model, checks exactly the risky content.
  • Believing a prompt attack filter checks an untagged InvokeModel prompt: prompt attack filters require input tags.
  • Believing one fixed tag suffix is safe: a user can close a static tag. Use a new random suffix per request.
  • Believing a system prompt instruction to ignore embedded commands replaces a guardrail: it is not a control, and ApplyGuardrail is.

Written from Amazon Web Services's documentation

Try 3 questions on this

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

  1. A company's research assistant calls the Amazon Bedrock Converse API with tool use. When the model requests a web search, the application fetches the text of public web pages and returns that text to the model in toolResult content blocks. The application already calls the ApplyGuardrail API on each user question with a guardrail that has a prompt attack filter. A red team shows that instructions hidden in a fetched web page can redirect the assistant. The company must screen all fetched page text with its existing guardrail before the model processes that text. Which solution will meet these requirements?

    Right. In the game that’s Renown for your AI Safety, Security, and Governance building.

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

    Show the full explanation and doc quotes

    And "You can integrate the ApplyGuardrail API anywhere in your application flow to validate data before processing or serving results to the user." Screening each fetched page with source INPUT, before it is returned as a tool result, applies the existing prompt attack filter to exactly the text that carries the attack.

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

  2. A company's HR assistant calls the RetrieveAndGenerate API on an Amazon Bedrock knowledge base of HR case files. Each request includes a guardrail whose sensitive information filter anonymizes national ID numbers in model responses. The web application shows each answer and, below it, the source passages from the citations in the response so that employees can check the answer. An audit finds national ID numbers in the displayed source passages, although the answers are masked. No national ID number may appear anywhere in the web application. The case files in the knowledge base must not be changed. Which solution will meet these requirements?

    Right. In the game that’s Renown for your AI Safety, Security, and Governance building.

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

  3. A bank's customer assistant calls the Amazon Bedrock InvokeModel API with a guardrail. Each request body contains one text prompt that combines the system instructions, the customer's account summary, and the customer's question. The guardrail has content filters and a prompt attack filter with HIGH input strength. Red team tests show that jailbreak attempts in customer questions reach the model without any guardrail intervention. The guardrail must check customer questions for prompt attacks but must not check the system instructions or the account summary. A customer must not be able to make the guardrail skip part of the question. Which combination of steps will meet these requirements? (Select TWO)

    Right. In the game that’s Renown for your AI Safety, Security, and Governance building.

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

    Show the full explanation and doc quotes

    The input tagging page says prompt attack filters "require input tags to be present", which is why the untagged prompt was never checked. It then warns: "A static tag can result in a malicious user closing the XML tag and appending malicious content after the tag closure, resulting in an injection attack", and "It is recommended to use a new, random string as the tagSuffix for every request."

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