Closed kardiff18 closed 2 weeks ago
I think this might be doable if the validation for SafetySettings
is fixed in https://github.com/langchain-ai/langchain-google/blob/eedb0d2e105c3573388ab2470702871efcddaab2/libs/vertexai/langchain_google_vertexai/_base.py#L142C32-L142C50
Currently setting it in the non-dict format will fail with the following error message:
ValidationError: 1 validation error for ChatVertexAI
safety_settings
value is not a valid dict (type=type_error.dict)
Investigating further, it looks like this has been fixed in https://github.com/langchain-ai/langchain-google/commit/4435b06ddd53cb06eddbd11f987b4b37bcf91d0b and we just need a new release
it looks like this one can be closed
I need to debug this further, but FYI it doesn't appear that this is being set when it's sent to Vertex (the method is not in the request object).
NVM - we are setting it, we just don't see it returned when using debug. I think when langchain gets the safetysetting back we need to return the severity parameters as well as the probability parameters.
With Vertex, there is the case that false positives occasionally arise in the safety settings due to using the "probability" method as default. To help fix the false positives, it would be desirable to switch to "severity" instead. This is not supposed in the way that LangChain accepts the safety_settings.
To fix the safety settings, it would likely break the current implementation since it is a dictionary rather than a proper object with the parameter names from Vertex. However, I think this is important to change to. If there are alternatives, please let me know. More details below and documentation from Vertex here.
Since langchain safety filters are in the format
{HarmCategory.HARM_CATEGORY_UNSPECIFIED: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
, it doesn't seem very conducive to doing the same in the Vertex SDK, but in Vertex I can do this and use severity rather than probability (the default) which is extremely helpful in reducing false positives