Guardrail Support for the Generic Bedrock Agent Test UI

Guardrail Support for the Generic Bedrock Agent Test UI

Here is the latest update to the generic Bedrock Agent test UI that enables guardrail trace.

Introduction

In the blog post Developing a Generic Streamlit UI to Test Amazon Bedrock Agents, I shared the design and source code of a basic yet functional UI for testing Bedrock agents. I’ve since added support for Knowledge Bases for Amazon Bedrock by displaying citations and their details to match the functionality in the Bedrock console.

Recently I’ve started experimenting with Guardrails for Amazon Bedrock, a feature that enables the implementation of safeguards for your generative AI applications based on specific use cases and responsible AI policies. As part of the blog post A Guide to Effective Use of the Terraform AWS Cloud Control Provider, I created a simple history-themed Bedrock agent with a guardrail that filters violent content. As I test a guardrail-enabled agent in the Bedrock console, I see additional traces showing whether guardrails have intervened as they assess the input and output, and if so, what policies were triggered:

Post-guardrail trace

With a bit of work, I have added similar support to the generic test UI and I am happy to share the updates in the GitHub repository.

Design overview

With the latest update, guardrail traces are now added to the pre-processing and post-processing trace sections in a manner similar to how they are displayed in the Bedrock console:

Guardrail trace details

The Boto3 invoke_agent method provides a new guardrailTrace trace type that includes trace details used in the guardrail. Distinguishing between pre- and post-guardrail traces took a bit of work, as they need to be tracked as events are streamed in sequence. If a guardrailTrace shows up for the first time (naturally before preProcessingTraces, it would be a pre-guardrail trace. A subsequent guardrailTrace that shows up (naturally after any postProcessingTraces would be a post-guardrail trace. Then they must be displayed under the Pre-Processing and Post-Processing sections as a single JSON object unlike other traces where they are broken down into smaller JSON objects for readability.

Summary

With the improvements to the generic test UI outlined in this post, you should now be able to test any Bedrock agents with an associated guardrail. I will be sure to incorporate support for new Agents for Amazon Bedrock features. If you find this blog post helpful, there is plenty more similar content at the Avangards Blog. Be sure to check them out!