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.