

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 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) 請求的標頭中指定，或在 [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) 請求內文的 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 欄位中定義提示節點時，請在 [PromptFlowNodeConfiguration](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_PromptFlowNodeConfiguration.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 欄位中定義知識庫節點時，請在 [KnowledgeBaseFlowNodeConfiguration](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_KnowledgeBaseFlowNodeConfiguration.html) 中包含 guardrailConfiguration 欄位。 | 

本節涵蓋使用具有模型推論和 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)