ERROR: restricted HarmBlockThreshold setting BLOCK_NONE on Vertex AI - Gemini #5773

Closed
opened 2026-02-21 18:12:32 -05:00 by yindo · 2 comments
Owner

Originally created by @totsukash on GitHub (Sep 24, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

v0.8.3

Cloud or Self Hosted

Cloud

Steps to reproduce

After completing the Vertex AI setup, an error occurs when calling the LLM.

Run failed: [vertex_ai] Bad Request Error, 400 User has requested a restricted HarmBlockThreshold setting BLOCK_NONE. You can get access either (a) through an allowlist via your Google account team, or (b) by switching your account type to monthly invoiced billing via this instruction: https://cloud.google.com/billing/docs/how-to/invoiced-billing.

I know the source of the problem.

https://github.com/langgenius/dify/blob/64baedb48429bf7332feab61d7a83cf1b7c91cda/api/core/model_runtime/model_providers/vertex_ai/llm/llm.py#L506-L511

スクリーンショット 2024-09-24 17 35 17

✔️ Expected Behavior

To be able to perform inference without errors, just like other LLMs.

Actual Behavior

Errors are occurring.

Originally created by @totsukash on GitHub (Sep 24, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version v0.8.3 ### Cloud or Self Hosted Cloud ### Steps to reproduce After completing the Vertex AI setup, an error occurs when calling the LLM. ``` Run failed: [vertex_ai] Bad Request Error, 400 User has requested a restricted HarmBlockThreshold setting BLOCK_NONE. You can get access either (a) through an allowlist via your Google account team, or (b) by switching your account type to monthly invoiced billing via this instruction: https://cloud.google.com/billing/docs/how-to/invoiced-billing. ``` I know the source of the problem. https://github.com/langgenius/dify/blob/64baedb48429bf7332feab61d7a83cf1b7c91cda/api/core/model_runtime/model_providers/vertex_ai/llm/llm.py#L506-L511 <img width="1258" alt="スクリーンショット 2024-09-24 17 35 17" src="https://github.com/user-attachments/assets/4756bf32-42bd-4084-bcf4-4b866d4cfdd5"> ### ✔️ Expected Behavior To be able to perform inference without errors, just like other LLMs. ### ❌ Actual Behavior Errors are occurring.
yindo added the 🐞 bug label 2026-02-21 18:12:32 -05:00
yindo closed this issue 2026-02-21 18:12:32 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 24, 2024):

Hey there, @totsukash! I'm here to help you with bugs, questions, and becoming a contributor. Let me know how I can assist you while you wait for a human maintainer.

To resolve the "Bad Request Error, 400" related to the restricted HarmBlockThreshold setting BLOCK_NONE when using Vertex AI with Dify, you need to adjust the HarmBlockThreshold settings in the safety_settings dictionary. The current settings are:

safety_settings = {
    HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE,
    HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE,
    HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE,
    HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,
}

To resolve the error, you should change the HarmBlockThreshold values to a less restrictive setting. For example, you can use HarmBlockThreshold.BLOCK_LOW:

safety_settings = {
    HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_LOW,
    HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_LOW,
    HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_LOW,
    HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_LOW,
}

This adjustment should help in resolving the "Bad Request Error, 400" [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 24, 2024): <!-- Greeting --> Hey there, @totsukash! I'm here to help you with bugs, questions, and becoming a contributor. Let me know how I can assist you while you wait for a human maintainer. <!-- Answer --> To resolve the "Bad Request Error, 400" related to the `restricted HarmBlockThreshold setting BLOCK_NONE` when using Vertex AI with Dify, you need to adjust the `HarmBlockThreshold` settings in the `safety_settings` dictionary. The current settings are: ```python safety_settings = { HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE, HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE, HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE, HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE, } ``` To resolve the error, you should change the `HarmBlockThreshold` values to a less restrictive setting. For example, you can use `HarmBlockThreshold.BLOCK_LOW`: ```python safety_settings = { HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_LOW, HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_LOW, HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_LOW, HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_LOW, } ``` This adjustment should help in resolving the "Bad Request Error, 400" <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/vertex_ai/llm/llm.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@totsukash commented on GitHub (Sep 24, 2024):

Since we can't change that in the Cloud version, I'm thinking of modifying the default settings.
https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/configure-safety-filters

I will set HARM_BLOCK_THRESHOLD_UNSPECIFIED or remove these configs.

@totsukash commented on GitHub (Sep 24, 2024): Since we can't change that in the Cloud version, I'm thinking of modifying the default settings. https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/configure-safety-filters I will set `HARM_BLOCK_THRESHOLD_UNSPECIFIED` or remove these configs.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5773