AI / Google Antigravity Gemini Fundamentals Interview Questions
What is the Gemini API's approach to safety and content moderation?
Gemini models include built-in safety filters that evaluate both input prompts and output content across four harm categories. Developers can configure the threshold at which content is blocked, balancing safety with utility for their specific application context.
| Category | What it covers |
|---|---|
| HARM_CATEGORY_HARASSMENT | Threatening, bullying, or targeted abuse |
| HARM_CATEGORY_HATE_SPEECH | Content promoting hatred based on protected characteristics |
| HARM_CATEGORY_SEXUALLY_EXPLICIT | Adult sexual content |
| HARM_CATEGORY_DANGEROUS_CONTENT | Content facilitating serious harm, weapons, illegal activities |
from google import genai from google.genai import types client = genai.Client() # Configure safety thresholds: response = client.models.generate_content( model="gemini-3.5-flash", contents="Your prompt here", config=types.GenerateContentConfig( safety_settings=[ types.SafetySetting( category="HARM_CATEGORY_DANGEROUS_CONTENT", threshold="BLOCK_ONLY_HIGH", # options below ), types.SafetySetting( category="HARM_CATEGORY_HARASSMENT", threshold="BLOCK_MEDIUM_AND_ABOVE", ), ] ) ) # Check safety ratings on the response: for rating in response.candidates[0].safety_ratings: print(f"{rating.category}: {rating.probability}") # Check if response was blocked: if response.prompt_feedback.block_reason: print(f"Blocked: {response.prompt_feedback.block_reason}")
| Threshold | Blocks |
|---|---|
| BLOCK_NONE | Nothing (use with caution) |
| BLOCK_ONLY_HIGH | Only HIGH probability harm |
| BLOCK_MEDIUM_AND_ABOVE | MEDIUM and HIGH probability harm |
| BLOCK_LOW_AND_ABOVE | LOW, MEDIUM, and HIGH (most restrictive) |
More Related questions...