{"record":{"id":"dffff49c3d24c564","repo":"spring-projects/spring-ai","slug":"unknown-harmblockthreshold","errorCode":null,"errorMessage":"Unknown HarmBlockThreshold: ","messagePattern":"Unknown HarmBlockThreshold: ","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-google-genai/src/main/java/org/springframework/ai/google/genai/GoogleGenAiChatModel.java","lineNumber":849,"sourceCode":"\t\t};\n\t}\n\n\tprivate static com.google.genai.types.HarmBlockThreshold mapToGenAiHarmBlockThreshold(\n\t\t\tGoogleGenAiSafetySetting.HarmBlockThreshold threshold) {\n\t\treturn switch (threshold) {\n\t\t\tcase HARM_BLOCK_THRESHOLD_UNSPECIFIED -> new com.google.genai.types.HarmBlockThreshold(\n\t\t\t\t\tcom.google.genai.types.HarmBlockThreshold.Known.HARM_BLOCK_THRESHOLD_UNSPECIFIED);\n\t\t\tcase BLOCK_LOW_AND_ABOVE -> new com.google.genai.types.HarmBlockThreshold(\n\t\t\t\t\tcom.google.genai.types.HarmBlockThreshold.Known.BLOCK_LOW_AND_ABOVE);\n\t\t\tcase BLOCK_MEDIUM_AND_ABOVE -> new com.google.genai.types.HarmBlockThreshold(\n\t\t\t\t\tcom.google.genai.types.HarmBlockThreshold.Known.BLOCK_MEDIUM_AND_ABOVE);\n\t\t\tcase BLOCK_ONLY_HIGH -> new com.google.genai.types.HarmBlockThreshold(\n\t\t\t\t\tcom.google.genai.types.HarmBlockThreshold.Known.BLOCK_ONLY_HIGH);\n\t\t\tcase BLOCK_NONE -> new com.google.genai.types.HarmBlockThreshold(\n\t\t\t\t\tcom.google.genai.types.HarmBlockThreshold.Known.BLOCK_NONE);\n\t\t\tcase OFF ->\n\t\t\t\tnew com.google.genai.types.HarmBlockThreshold(com.google.genai.types.HarmBlockThreshold.Known.OFF);\n\t\t\tdefault -> throw new IllegalArgumentException(\"Unknown HarmBlockThreshold: \" + threshold);\n\t\t};\n\t}\n\n\tprivate static ThinkingLevel mapToGenAiThinkingLevel(GoogleGenAiThinkingLevel level) {\n\t\treturn switch (level) {\n\t\t\tcase THINKING_LEVEL_UNSPECIFIED -> new ThinkingLevel(ThinkingLevel.Known.THINKING_LEVEL_UNSPECIFIED);\n\t\t\tcase MINIMAL -> new ThinkingLevel(ThinkingLevel.Known.MINIMAL);\n\t\t\tcase LOW -> new ThinkingLevel(ThinkingLevel.Known.LOW);\n\t\t\tcase MEDIUM -> new ThinkingLevel(ThinkingLevel.Known.MEDIUM);\n\t\t\tcase HIGH -> new ThinkingLevel(ThinkingLevel.Known.HIGH);\n\t\t};\n\t}\n\n\tprivate static FunctionCallingConfigMode mapToFunctionCallingConfigMode(\n\t\t\tGoogleGenAiChatOptions.ToolChoice.Mode mode) {\n\t\treturn switch (mode) {\n\t\t\tcase AUTO -> new FunctionCallingConfigMode(FunctionCallingConfigMode.Known.AUTO);\n\t\t\tcase ANY -> new FunctionCallingConfigMode(FunctionCallingConfigMode.Known.ANY);","sourceCodeStart":831,"sourceCodeEnd":867,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-google-genai/src/main/java/org/springframework/ai/google/genai/GoogleGenAiChatModel.java#L831-L867","documentation":"mapToGenAiHarmBlockThreshold converts GoogleGenAiSafetySetting.HarmBlockThreshold enums to genai SDK thresholds; the default branch throws IllegalArgumentException for any value the switch does not map. It means a threshold value outside the supported set reached the mapper.","triggerScenarios":"Configuring a safety setting with a HarmBlockThreshold constant not handled by the switch (e.g. HARM_THRESHOLD_UNSPECIFIED or a new constant) when constructing Gemini safety settings.","commonSituations":"Version drift where the enum gained new constants not yet mapped; building thresholds dynamically from config strings; copying thresholds from Vertex/other SDKs with different names.","solutions":["Use only mapped values such as BLOCK_ONLY_HIGH, BLOCK_NONE, OFF and the other cases the switch handles.","Check the exception message for the offending threshold value and fix your safety configuration.","Update the library or the mapper if a newly introduced enum constant is missing.","Parse config-driven thresholds defensively against the supported enum set."],"exampleFix":"// before\nnew GoogleGenAiSafetySetting(category, HarmBlockThreshold.HARM_THRESHOLD_UNSPECIFIED);\n// after\nnew GoogleGenAiSafetySetting(category, HarmBlockThreshold.BLOCK_ONLY_HIGH);","handlingStrategy":"type-guard","validationCode":"Set<HarmBlockThreshold> allowed = Set.of(BLOCK_NONE, BLOCK_ONLY_HIGH, OFF /* plus other mapped cases */);\nif (!allowed.contains(threshold)) throw new IllegalArgumentException(\"unsupported: \" + threshold);","typeGuard":"boolean isMapped(HarmBlockThreshold t) { return EnumSet.of(BLOCK_NONE, BLOCK_ONLY_HIGH, OFF).contains(t); }","tryCatchPattern":"try { applySafety(settings); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Unknown HarmBlockThreshold\")) fixConfig(); else throw e; }","preventionTips":["Use only thresholds handled by the mapper","Avoid config-driven valueOf without validation","Verify mappings after version upgrades"],"tags":["enum","safety-settings","gemini"],"backgroundTag":"invalid-enum-value","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}