Gemini HARM_CATEGORY Threshold Configuration
You're passing safety_settings but seeing invalid category names, unsupported thresholds, or configurations that don't behave as expected. Fix by using correct enum values, understanding threshold levels, and knowing which categories can be adjusted.
Categories: HARM_CATEGORY_HARASSMENT, HATE_SPEECH, SEXUALLY_EXPLICIT, DANGEROUS_CONTENT, CIVIC_INTEGRITY. Thresholds: BLOCK_NONE, BLOCK_ONLY_HIGH, BLOCK_MEDIUM_AND_ABOVE (default), BLOCK_LOW_AND_ABOVE. Use exact strings, per-category settings. CSAM and severe harm always blocked regardless.
The Error Messages You're Seeing
HTTP/1.1 400 Bad Request
{
"error": {
"code": 400,
"message": "Invalid HarmCategory: 'HARM_CATEGORY_VIOLENCE'
is not a valid enum value.",
"status": "INVALID_ARGUMENT"
}
}
Variants:
"Invalid HarmBlockThreshold: 'BLOCK_HIGH' not valid"
"Duplicate safety setting for HARM_CATEGORY_DANGEROUS_CONTENT"
"HARM_CATEGORY_CIVIC_INTEGRITY threshold not adjustable in
this region"
"safety_settings not permitted on unblockable models"Threshold Levels Reference
| Threshold | Blocks at probability | Use when |
|---|---|---|
BLOCK_LOW_AND_ABOVE | LOW, MEDIUM, HIGH | Kids' apps, strict compliance |
BLOCK_MEDIUM_AND_ABOVE | MEDIUM, HIGH (default) | General purpose apps |
BLOCK_ONLY_HIGH | HIGH only | Adult content platforms, research |
BLOCK_NONE | Nothing (via safety_settings) | Approved research, moderation tools |
OFF (alternative) | Filter disabled entirely | Same as BLOCK_NONE for most |
Category Adjustability
| Category | Adjustable | Notes |
|---|---|---|
| HARM_CATEGORY_HARASSMENT | Yes | All thresholds |
| HARM_CATEGORY_HATE_SPEECH | Yes | All thresholds |
| HARM_CATEGORY_SEXUALLY_EXPLICIT | Yes | All thresholds |
| HARM_CATEGORY_DANGEROUS_CONTENT | Yes | Extreme content always blocked regardless |
| HARM_CATEGORY_CIVIC_INTEGRITY | Limited | Region/model dependent |
| CSAM (implicit) | No | Always blocked |
What Actually Causes This Error
Fixes That Work (Tested Nov 2026)
1Correct Configuration Syntax
2Context-Specific Configurations
If your app permits BLOCK_ONLY_HIGH or BLOCK_NONE on any category, document the business justification in code comments and a policy doc. Legal, PR, and compliance teams will ask; auditors will look.
3Inspect Safety Ratings Post-Response
Preventing This Error Going Forward
- Use SDK constants when possible. Prevents typos.
- Never duplicate category entries. One SafetySetting per category.
- Log rating probabilities to tune thresholds. Data-driven, not guesswork.
- Document loose thresholds in code + policy. Justify each deviation.
- Test all thresholds against your real content. Especially non-English.
- Remember: severe harm always blocked. Even at BLOCK_NONE.
Researcher · AI Error Hub
Frequently Asked Questions
For the adjustable categories yes — model may produce content that would have been blocked at default. But core unblockable filters (CSAM, imminent violence toward identified persons) remain active regardless.
Same category names and threshold enums. Vertex AI historically allowed lower defaults for enterprise workloads; the API accepts identical configuration. Model behavior may differ slightly between deployment paths.
Doesn't exist as a separate category. Violence-related content evaluated under HARM_CATEGORY_DANGEROUS_CONTENT (instructions to harm) or HARM_CATEGORY_HARASSMENT (targeting people).
Curate a labeled test set of prompts across your content spectrum. Run through Gemini, log probabilities, check block rates against expectations. Iterate. Consider AI Studio playground for interactive testing.
Safety runs independently. A blocked response with structured outputs configured will still produce empty content + SAFETY finish_reason. Handle both response_schema parse failures AND safety blocks in your code.
Related Errors
Fine-Tune Gemini Safety Settings
Weekly deep dives on safety, moderation, and threshold tuning. 12,000+ developers subscribe.
Subscribe Free →