SafetySpec

Safety specification. There are two use cases: 1. when only safetySpec.enable is set, the BLOCK_LOW_AND_ABOVE threshold will be applied for all categories. 2. when safetySpec.enable is set and some safetySettings are set, only specified safetySettings are applied.

JSON representation
{"enable":boolean,"safetySettings":[{object (SafetySetting)}]}
Fields
enable

boolean

Enable the safety filtering on the answer response. It is false by default.

safetySettings[]

object (SafetySetting)

Optional. Safety settings. This settings are effective only when the safetySpec.enable is true.

SafetySetting

Safety settings.

JSON representation
{"category":enum (HarmCategory),"threshold":enum (HarmBlockThreshold)}
Fields
category

enum (HarmCategory)

Required. Harm category.

threshold

enum (HarmBlockThreshold)

Required. The harm block threshold.

HarmBlockThreshold

Probability-based thresholds levels for blocking.

Enums
HARM_BLOCK_THRESHOLD_UNSPECIFIEDUnspecified harm block threshold.
BLOCK_LOW_AND_ABOVEBlock low threshold and above (i.e. block more).
BLOCK_MEDIUM_AND_ABOVEBlock medium threshold and above.
BLOCK_ONLY_HIGHBlock only high threshold (i.e. block less).
BLOCK_NONEBlock none.
OFFTurn off the safety filter.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-06-27 UTC.