Amazon Bedrock's ApplyGuardrail API can independently evaluate INPUT text (prompts) before a model is invoked and OUTPUT text (model responses) after generation, without requiring a model call — making it suitable for both a pre-inference block of harmful prompts and a post-inference check of generated content. Attaching a guardrail directly to the InvokeModelWithResponseStream API enables real-time filtering of streamed tokens as they are generated. Routing guardrail-flagged content to a queue such as Amazon SQS enables asynchronous human review of borderline or blocked cases. To guarantee that every inference request actually uses the approved guardrail (rather than relying on developers to remember to specify it), Bedrock supports the bedrock:GuardrailIdentifier IAM condition key, which can be enforced in an IAM policy attached to the InvokeModel/InvokeModelWithResponseStream/Converse/ConverseStream actions; any request lacking or mismatching the required guardrail identifier is denied. This combination — Step Functions orchestrating Lambda pre-check (ApplyGuardrail), streaming inference with an attached guardrail, Lambda post-check (ApplyGuardrail), SQS routing for review, and IAM-based enforcement — comprehensively satisfies all stated requirements.
Community Discussion