Track if responses from Vertex models are blocked by content filter
Problem to solve
We see that some response both for code completion and code generation are blocked due to the content filter:
We are getting this in the body of the response on the blocked value - https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/code-generation#response_body
Proposal
We need to add in the first step logging for telemetry to know how many requests are blocked at the moment by it. Both for code-gecko
and code-bison
.
- Inspect 200 response and check for
"safetyAttributes": { "blocked": true }
- Log: Write a new warning log entry
- Prometheus: Increment a Prometheus counter
- Snowplow: Add a new field to Snowplow event (+ update Iglu schema)
- Deploy changes and verify in ElasticSearch/Kibana
- Add Prometheus metrics in Grafana
- Verify in Sisense
Further details
To reproduce the blocked content request via the API.
Request
curl --request POST \
--url https://us-central1-aiplatform.googleapis.com/v1/projects/unreview-poc-390200e5/locations/us-central1/publishers/google/models/code-gecko@001:predict \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"instances": [
{
"prefix": "# froz"
}
],
"parameters": {
"temperature": 0.2,
"maxOutputTokens": 64,
"candidateCount": 1
}
}'
Response - HTTP 200
code-gecko
, code-bison
, text-bison
-> "blocked": true
{
"predictions": [
{
"score": 0,
"content": "",
"safetyAttributes": {
"blocked": true,
"errors": [
254
]
}
}
],
...
}
code-gecko
, code-bison
, text-bison
-> "blocked": false
{
"predictions": [
{
"score": 0,
"content": "",
"safetyAttributes": {
"scores": [
0.2,
0.1
],
"blocked": false,
"categories": [
"Death, Harm & Tragedy",
"Finance"
]
}
}
],
...
}
Links / references
- https://cloud.google.com/vertex-ai/docs/generative-ai/learn/responsible-ai#safety_attribute_descriptions
- https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/code-completion
- https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/code-generation
- https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/text
Edited by Tan Le