tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Google Gemini API > Gemini Safety Filters

Gemini Safety Filters

Author: Venkata Sudhakar

Gemini Safety Filters evaluate content across four harm categories: harassment, hate speech, sexually explicit material, and dangerous content. Each category has a configurable threshold - BLOCK_NONE, BLOCK_LOW_AND_ABOVE, BLOCK_MEDIUM_AND_ABOVE, or BLOCK_ONLY_HIGH. ShopMax India configures safety settings on its customer-facing agents to prevent misuse while keeping legitimate queries unrestricted.

Safety ratings are returned with every Gemini response. You can inspect them to understand why content was blocked or to log safety events for audit purposes. For business applications, the default settings are usually appropriate - only adjust thresholds when you have a specific, validated use case.

The below example shows how to configure safety settings and inspect safety ratings on responses.


It gives the following output,

HARM_CATEGORY_HARASSMENT: NEGLIGIBLE
HARM_CATEGORY_HATE_SPEECH: NEGLIGIBLE
HARM_CATEGORY_SEXUALLY_EXPLICIT: NEGLIGIBLE
HARM_CATEGORY_DANGEROUS_CONTENT: NEGLIGIBLE

Response: ShopMax India accepts returns within 10 days of delivery for unused electronics in original packaging with all accessories included.

The below example shows how to handle blocked responses gracefully and log safety events for audit.


It gives the following output,

ShopMax India TV warranties vary by brand. Samsung and LG TVs come with a 1-year comprehensive warranty, while Sony Bravia models include 2 years. Extended warranty plans are available at checkout for an additional Rs 999 to Rs 2,999 depending on the TV value.

ShopMax India logs all safety events to Cloud Logging for weekly review. In six months of operation, the system has blocked fewer than 0.05% of customer queries - mostly attempted misuse rather than genuine customer needs. The safety logs help the team identify patterns and refine agent instructions to handle edge cases gracefully without over-blocking legitimate queries.


 
  


  
bl  br