Table of Contents

Class SafetySetting

Namespace
Google.GenAI.Types
Assembly
Google.GenAI.dll

A safety setting that affects the safety-blocking behavior. A SafetySetting consists of a harm category and a threshold for that category.

public record SafetySetting : IEquatable<SafetySetting>
Inheritance
SafetySetting
Implements
Inherited Members

Properties

Category

The harm category to be blocked.

[JsonPropertyName("category")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public HarmCategory? Category { get; set; }

Property Value

HarmCategory?

Method

Optional. The method for blocking content. If not specified, the default behavior is to use the probability score. This field is not supported in Gemini API.

[JsonPropertyName("method")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public HarmBlockMethod? Method { get; set; }

Property Value

HarmBlockMethod?

Threshold

The threshold for blocking content. If the harm probability exceeds this threshold, the content will be blocked.

[JsonPropertyName("threshold")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public HarmBlockThreshold? Threshold { get; set; }

Property Value

HarmBlockThreshold?

Methods

FromJson(string, JsonSerializerOptions?)

Deserializes a JSON string to a SafetySetting object.

public static SafetySetting? FromJson(string jsonString, JsonSerializerOptions? options = null)

Parameters

jsonString string

The JSON string to deserialize.

options JsonSerializerOptions

Optional JsonSerializerOptions.

Returns

SafetySetting

The deserialized SafetySetting object, or null if deserialization fails.