跳至內容

如何解決 Amazon Bedrock 中的驗證例外狀況?

2 分的閱讀內容
0

我想解決在 Amazon Bedrock 基礎模型中調用時出現的驗證例外狀況。

解決方法

當您在使用不正確的推論參數或對應值的基礎模型上執行 InvokeModelInvokeModelWithResponseStream API 的模型調用 API 時,就會發生驗證錯誤。當您將模型的推論參數與不具有相同 API 參數的模型一起使用時,就會發生這些錯誤。當您使用 AWS Identity and Access Management (IAM) 角色原則在沒有權限的情況下存取基礎模型時,也會發生驗證錯誤。

權限不足

如果您調用使用 IAM 角色或 IAM 使用者但沒有相應權限的 Amazon Bedrock 模型,那麼您會收到下列錯誤訊息:

"An error occurred (ValidationException) when calling the InvokeModelWithResponseStream operation: Your AWS account is not authorized to invoke this API operation." (呼叫 InvokeModelWithResponseStream 作業時發生錯誤 (ValidationException):您的 AWS 帳戶無權調用此 API 作業。)

若要解決此錯誤,請確定您的 IAM 使用者或角色的政策具有調用 Amazon Bedrock 模型的權限

模型識別碼不正確

如果您使用不正確的基礎模型識別碼調用 Amazon Bedrock 模型,那麼您會收到下列錯誤訊息:

"Error raised by bedrock service: An error occurred (ValidationException) when calling the InvokeModel operation: The provided model identifier is invalid." (「由 Bedrock 服務引發的錯誤:呼叫 InvokeModel 作業時發生錯誤 (ValidationException):所提供的模型識別碼無效。」)

若要解決此錯誤,請確定您使用並傳遞您所調用 Amazon Bedrock 模型的模型 ID。另外,請檢查您 AWS 區域的特定模型可用性。如需詳細資訊,請參閱取得基礎模型的相關資訊

防護機制輸入格式不正確

如果您使用錯誤的防護機制輸入調用 Amazon Bedrock 模型,那麼您會收到下列錯誤訊息:

「An error occurred (ValidationException) when calling the InvokeModel operation: Guardrail was enabled but input is in incorrect format." (「呼叫 InvokeModel 作業時發生錯誤 (ValidationException):防護機制已啟用,但輸入的格式不正確。」)

要解決此錯誤,請確保為 guardrail-identifier 提供有效的 Guardrail ID,並為 guardrailVersion 提供版本號碼。

輸入請求格式錯誤

如果您使用錯誤的輸入請求調用 Amazon Bedrock 模型,那麼您會收到下列錯誤訊息:

"ValueError: Error raised by bedrock service: An error occurred (ValidationException) when calling the InvokeModel operation: Malformed input request: extraneous key [textGenerationConfig] is not permitted, please reformat your input and try again." (「ValueError:bedrock 服務引發的錯誤:呼叫 InvokeModel 作業時發生錯誤 (ValidationException):輸入請求格式錯誤:不允許使用多餘的索引鍵 [textGenerationConfig],請重新格式化您的輸入後再試一次。」)

若要解決此錯誤,請確定在調用時傳送特定模型支援的輸入組態。

輸入超過模型配額

如果您輸入和輸出權杖的總數高於指定的配額,那麼您將收到以下錯誤訊息:

"ValidationException('An error occurred (ValidationException) when calling the InvokeModel operation: Input is too long for requested model.')"}}." (「ValidationException (『呼叫 InvokeModel 作業時發生錯誤 (ValidationException):對於請求的模型來說輸入過長。』)"}}.」)

若要解決此錯誤,請確定您提供給模型的輸入內容在該模型的配額範圍內。此配額是您的輸入權杖大小和輸出權杖請求的組合。

不支援的 API

如果您使用模型不支援的 API 來調用 Amazon Bedrock 模型,那麼您會到下列錯誤訊息:

"ValidationException: "claude-3-sonnet-20240229" is not supported on this API.Please use the Messages API instead.(short issue description)" (「ValidationException:此 API 不支援 "claude-3-sonnet-20240229"。請改用 Messages API。 (問題簡述)」)

若要解決此錯誤,請調整程式碼以遵循 Claude 3.0 中支援的 Anthropic Claude Messages API。如果您使用 Claude 模型,那麼最佳做法是遷移到新的 Messages API。訊息元素表示 JSON 物件清單,其中包括輸入中每個回合的角色和內容。

不支援的國家、地區或領土

如果您嘗試從不支援的區域存取或調用 Amazon Bedrock 模型,那麼您會收到以下錯誤訊息:

"Can't invoke 'us.anthropic.claude-3-haiku-20240307-v1:0'.Reason: An error occurred (ValidationException) when calling the Converse operation: Access to Anthropic models is not allowed from unsupported countries, regions, or territories.Please refer to https://www.anthropic.com/supported-countries for more information on the countries and regions Anthropic currently supports." (「無法調用『us.anthropic.claude-3-haiku-20240307-v1:0』。原因:呼叫 Converse 作業時發生錯誤 (ValidationException):無法從不支援的國家、地區或領土存取 Anthropic 模型。如需進一步了解 Anthropic 目前支援的國家和地區,請參閱 https://www.anthropic.com/supported-countries。」)

若要解決此錯誤,請從支援的區域存取 Amazon Bedrock 模型,並確定您的 AWS 帳戶稅務地址位於支援的區域內。區域包括但不限於您帳戶的稅務地址與帳單地址,以及嘗試存取 Amazon Bedrock 模型的機器所在地。

若要更新帳單資訊,請參閱如何新增或更新帳單聯絡資訊?

相關資訊

測試防護機制

基礎模型的推論請求參數和回應欄位