

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# Amazon Bedrock 护栏的使用案例
<a name="guardrails-use"></a>

创建护栏后，您可以通过以下功能进行应用：
+ [模型推理](inference.md) – 在模型上运行推理时，对提交的提示和生成的响应应用护栏。
+ [代理](agents.md) – 将护栏与代理关联，以将护栏应用于发送给代理的提示和从代理返回的响应。
+ [知识库](knowledge-base.md) – 在查询知识库并从中生成响应时应用护栏。
+ [工作流](flows.md) – 向流中的提示节点或知识库节点添加护栏，将其应用于这些节点的输入和输出。

下表描述了如何使用 AWS 管理控制台 或 Amazon Bedrock API 为每项功能添加护栏。


****  

| 使用案例 | 控制台 | API | 
| --- | --- | --- | 
| 模型推理 | 在[使用演练场](playgrounds.md)时选择护栏。 | 在[InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html)或[InvokeModelWithResponseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModelWithResponseStream.html)请求的标题中指定，或者在 C [onverse](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html) 或[ConverseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html)请求正文的guardrailConfig字段中包含该字段。 | 
| 与代理关联 | [创建或更新](agents-build-modify.md)代理时，在代理生成器的护栏详细信息部分中指定。 | 在 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_CreateAgent.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_CreateAgent.html) 或 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_UpdateAgent.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_UpdateAgent.html) 请求的正文中添加 guardrailConfiguration 字段。 | 
| 在查询知识库时使用 | 按照查询配置[护栏](kb-test-config.md#kb-test-config-guardrails)部分中的步骤进行操作。在设置配置时添加护栏。 | 在 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_RetrieveAndGenerate.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_RetrieveAndGenerate.html) 请求的正文中添加一个 guardrailConfiguration 字段。 | 
| 包含在流的提示节点中 | [创建](flows-create.md)或[更新](flows-modify.md)流时，请选择提示节点并在配置部分指定护栏。 | 在[CreateFlow](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_CreateFlow.html)或[UpdateFlow](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_UpdateFlow.html)请求的nodes字段中定义提示节点时，请在中加入一个guardrailConfiguration字段[PromptFlowNodeConfiguration](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_PromptFlowNodeConfiguration.html)。 | 
| 包含在流的知识库节点中 | [创建](flows-create.md)或[更新](flows-modify.md)工作流时，请选择知识库节点并在配置部分指定护栏。 | 在[CreateFlow](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_CreateFlow.html)或[UpdateFlow](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_UpdateFlow.html)请求的nodes字段中定义知识库节点时，请在中包含一个guardrailConfiguration字段[KnowledgeBaseFlowNodeConfiguration](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_KnowledgeBaseFlowNodeConfiguration.html)。 | 

这一部分介绍了如何在模型推理和 Amazon Bedrock API 中使用护栏。您可以使用基本推理运算（[InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html)和 [InvokeModelWithResponseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModelWithResponseStream.html)）和 Converse API（[Converse](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html) 和 [ConverseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html)）。通过这两组操作，您可以在同步和流式模型推理中使用护栏。您还可以有选择地评估用户输入，并配置流式响应行为。

**Topics**
+ [结合使用护栏和推理操作来评估用户输入](guardrails-input-tagging-base-inference.md)
+ [在您的应用程序中使用 ApplyGuardrail API](guardrails-use-independent-api.md)