

# Add an Amazon Bedrock guardrail component to a flow app
<a name="add-guardrail-component-flow-app"></a>

In this procedure, you add a guardrail component to the [knowledge base](nodes.md#flow-node-kb) node that you create in step 2 of [Create a flow app with Amazon Bedrock](build-flow.md). You can also add a guardrail to a [prompt](nodes.md#flow-node-prompt) node. To add a guardrail to a prompt node, use the following steps. For step 7, select the prompt node (**Playlist\$1generator\$1node**).

1. Navigate to the Amazon SageMaker Unified Studio landing page by using the URL from your administrator.

1. Access Amazon SageMaker Unified Studio using your IAM or single sign-on (SSO) credentials. For more information, see [Access Amazon SageMaker Unified Studio](getting-started-access-the-portal.md).

1. If the project that you want to use isn't already open, do the following:

   1. Choose the current project at the top of the page. If a project isn't already open, choose **Select a project**.

   1. Select **Browse all projects**. 

   1. In **Projects** select the project that you want to use.

1. Choose the **Build** menu option at the top of the page.

1. In **MACHINE LEARNING & GENERATIVE AI** choose **My apps**.

1. open the flow app that you created in [Create a flow app with Amazon Bedrock](build-flow.md).

1. In the canvas, select the knowledge base node (**Local\$1bands\$1knowledge\$1base**).

1. In the **flow builder** pane, choose the configure tab.

1. In the **Guardrail details** section do one of the following: 
   + Select an existing guardrail to use
   + Choose **Create a new guardrail** to create a new guardrail. Then do the following: 

     1. For **Guardrail name**. enter a name for the guardrail.

     1. For **Guardrail description** enter a description for the guardrail.

     1. In **Content filters** do the following.

        1. Select **Enable content filters** to turn on content filtering. 

        1. For **Filter for prompts**, choose the filters that you want to apply to prompts. For more information, see [Content filters](guardrails.md#guardrails-studio-content-filters).

        1. If you want the filter to apply to responses that the model generates, select **Apply the same filters for responses**.

     1. In **Blocked messsaging** do the following:

        1. For **Blocked messaging for prompts** enter a message to display when the guardrail blocks content in the prompt. 

        1. If you want to show a different message when the guardrail blocks content, do the following:

           1. Clear **Apply the same message for blocked responses**.

           1. For **Blocked messaging for responses**, enter a message to display when the guardrail blocks content in the response from the model.

     1. Add a denied topic filter by doing the following: 

        1. Choose **Use advanced features**.

        1. Choose **Denied topics**.

        1. Choose **Add topic**.

        1. For **Name**, enter a name for the filter.

        1. For **Definition for topic**, enter a definition for the content that you want to deny.

        1. (Optional) To help guide the guardrail, do the folllowing: 

           1. Choose **Sample phrases - optional**.

           1. For **Sample phrases**, enter a phrase.

           1. Choose **Add phrase**.

           1. Add up to four more phrases by repeating the previous two steps.

           1. Choose **Save**.

        For information about denied topics, see [Denied topics](guardrails.md#guardrails-topic-policies).

     1. Choose **Create** to create the guardrail.

     1. Add the guardrail component to a chat agent app by doing [Add an Amazon Bedrock guardrail component to a chat agent app](add-guardrail-component-chat-app.md).

1. Choose **Save** to save your changes to your flow app.

1. Test your prompt by doing the following:

   1. On right side of the app flow page, choose **<** to open the test pane.

   1. In **Enter prompt**, enter a phrase that violates your guardrail.

   1. Press Enter on the keyboard or choose the run button to test the prompt. 

   1. In the response you should see the text **guardrail applied** under the affected prompt. Choose the prompt to see the reason why the guardrail rejected the prompt.