Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Vertex AI Responses Blocked Incorrectly

I'm using langchain to call Vertex AI Gemini 1.5 Pro. I'm setting the security settings to "block less" (BLOCK_ONLY_HIGH, 3) for all 4 categories

  • HARM_CATEGORY_DANGEROUS_CONTENT
  • HARM_CATEGORY_HATE_SPEECH
  • HARM_CATEGORY_HARASSMENT
  • HARM_CATEGORY_SEXUALLY_EXPLICIT

I'm using multimodal input (pictures) and the documents are sensitive (scans of identity documents). In some cases the responses are being blocked when the probability_label is MEDIUM, which doesn't make sense to me. Responses should only be blocked when probability_label is HIGH, surely!

For example, here is part of the response coming back via langchain,

  "generations": [
    [
      {
        "text": "",
        "generation_info": {
          "is_blocked": true,
          "safety_ratings": [
            {
              "category": "HARM_CATEGORY_HATE_SPEECH",
              "probability_label": "NEGLIGIBLE",
              "blocked": false
            },
            {
              "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
              "probability_label": "MEDIUM",
              "blocked": true
            },
            {
              "category": "HARM_CATEGORY_HARASSMENT",
              "probability_label": "NEGLIGIBLE",
              "blocked": false
            },
            {
              "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
              "probability_label": "NEGLIGIBLE",
              "blocked": false
            }
          ],
          "usage_metadata": {
            "prompt_token_count": 523,
            "total_token_count": 523,
            "candidates_token_count": 0
          }
        },
        "type": "ChatGeneration",

Note that HARM_CATEGORY_DANGEROUS_CONTENT has probablity_level MEDIUM and is blocked. I suddenly noticed this behaviour only recently (a couple of days ago).
I have read the following documentation:

I don't see the API calls to Vertex API in the Logs Explorer and I don't know of another way to interrogate the low level API calls to ensure that I'm sending the correct security settings.

Does anyone have any tips?

0 3 882
3 REPLIES 3

This is a problem in langchain_google_vertexai, fixed by the developer in commit https://github.com/langchain-ai/langchain-google/pull/260/commits/a0c90341832f1db42451399c990c7d3490....

On a side note, this forum is a horrible experience. I'm trying to contribute here, but I'm having to click little photographs of fire hydrants and motorbikes like a child. And the site keeps on timing out.

This problem has been resolved by using a fixed version of `langchain-google-vertexai`. The fix (see issue https://github.com/langchain-ai/langchain-google/issues/252) has not been rolled into a release as of the writing of this message. It's expected to be included in the upcoming release (probably 1.0.6).

it maybe that you have to pass safety config when generating a message not just on model creation...

(and yeah this forum software sucks eh @stefanadelbert )