You can actually configure Gemini’s safety settings to be less restrictive than their defaults, even for production.
Let’s see how this looks in practice. Imagine you’re building a customer support chatbot and you want to allow it to discuss potentially sensitive topics like financial advice or health queries, but still avoid outright harmful content.
Here’s a Python snippet using the google.generativeai library to set up a model with custom safety settings:
import google.generativeai as genai
# Assume you have your API key set as an environment variable
# or passed directly: genai.configure(api_key="YOUR_API_KEY")
genai.configure()
# Configure the model with custom safety settings
# We're reducing the threshold for harassment and hate speech
# and allowing content that might be considered sexually explicit
# but is not harmful.
model = genai.GenerativeModel(
model_name="gemini-1.5-flash-latest",
safety_settings={
"HARASSMENT": "BLOCK_NONE",
"HATE_SPEECH": "BLOCK_NONE",
"SEXUALLY_EXPLICIT": "BLOCK_NONE",
"DANGEROUS_CONTENT": "BLOCK_ONLY_HIGH",
}
)
# Example of a prompt that might have been blocked by default
prompt = "Can you explain the basics of investing in mutual funds for beginners?"
response = model.generate_content(prompt)
print(response.text)
Running this would output an explanation of mutual funds. The key here is the safety_settings dictionary. Each key (HARASSMENT, HATE_SPEECH, SEXUALLY_EXPLICIT, DANGEROUS_CONTENT) corresponds to a safety category. The values are policy levels: BLOCK_NONE, BLOCK_LOW_AND_ABOVE, BLOCK_MEDIUM_AND_ABOVE, BLOCK_HIGH_AND_ABOVE, and BLOCK_ONLY_HIGH.
By setting BLOCK_NONE for harassment and hate speech, we’re telling Gemini to only block content that is demonstrably harmful or illegal. For SEXUALLY_EXPLICIT, BLOCK_NONE means it will allow content that is sexually suggestive but not explicit or exploitative. DANGEROUS_CONTENT is kept at BLOCK_ONLY_HIGH as a baseline for truly hazardous instructions.
The core problem this solves is the rigidity of default safety filters, which can sometimes over-censor legitimate, nuanced, or sensitive conversations that are crucial for certain applications like therapy-adjacent tools, educational platforms discussing mature topics, or creative writing assistants. These settings allow you to fine-tune the model’s sensitivity to better match your specific use case’s risk tolerance and functional requirements.
The mental model here is that each safety category is a dial. The default settings are often turned up high across the board to err on the side of caution for broad public use. For a controlled production environment, you can selectively turn these dials down. You are not disabling safety; you are recalibrating it to a specific risk profile. The BLOCK_ONLY_HIGH setting, for instance, is a common middle ground for categories where you want to allow more nuanced discussion but still stop truly egregious content.
It’s important to understand that setting BLOCK_NONE doesn’t mean Gemini will generate harmful content. It means the automatic filtering mechanisms for that category are turned off. The model’s inherent training still guides it away from generating truly harmful outputs. However, the confidence of the filter in blocking borderline cases is reduced.
A critical, often overlooked aspect is the interplay between BLOCK_NONE and the model’s inherent biases or limitations. Even with all safety filters off, a model might still refuse to generate certain content due to its core training data or alignment. For example, it might still refuse to generate illegal instructions even with DANGEROUS_CONTENT set to BLOCK_NONE, because the model itself has learned that such information is inappropriate. The safety settings are a layer on top of the model’s core behavior.
The next step is often dealing with the nuanced edge cases that still slip through, requiring careful prompt engineering or post-processing of the model’s output.