Table of Contents

Class Candidate

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

A response candidate generated from the model.

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

Properties

AvgLogprobs

Output only. The average log probability of the tokens in this candidate. This is a length-normalized score that can be used to compare the quality of candidates of different lengths. A higher average log probability suggests a more confident and coherent response.

[JsonPropertyName("avgLogprobs")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public double? AvgLogprobs { get; set; }

Property Value

double?

CitationMetadata

Source attribution of the generated content.

[JsonPropertyName("citationMetadata")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public CitationMetadata? CitationMetadata { get; set; }

Property Value

CitationMetadata

Content

Contains the multi-part content of the response.

[JsonPropertyName("content")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public Content? Content { get; set; }

Property Value

Content

FinishMessage

Describes the reason the model stopped generating tokens.

[JsonPropertyName("finishMessage")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? FinishMessage { get; set; }

Property Value

string

FinishReason

The reason why the model stopped generating tokens. If empty, the model has not stopped generating the tokens.

[JsonPropertyName("finishReason")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public FinishReason? FinishReason { get; set; }

Property Value

FinishReason?

GroundingMetadata

Output only. Metadata returned when grounding is enabled. It contains the sources used to ground the generated content.

[JsonPropertyName("groundingMetadata")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public GroundingMetadata? GroundingMetadata { get; set; }

Property Value

GroundingMetadata

Index

Output only. The 0-based index of this candidate in the list of generated responses. This is useful for distinguishing between multiple candidates when candidate_count > 1.

[JsonPropertyName("index")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public int? Index { get; set; }

Property Value

int?

LogprobsResult

Output only. The detailed log probability information for the tokens in this candidate. This is useful for debugging, understanding model uncertainty, and identifying potential "hallucinations".

[JsonPropertyName("logprobsResult")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public LogprobsResult? LogprobsResult { get; set; }

Property Value

LogprobsResult

SafetyRatings

Output only. A list of ratings for the safety of a response candidate. There is at most one rating per category.

[JsonPropertyName("safetyRatings")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<SafetyRating>? SafetyRatings { get; set; }

Property Value

List<SafetyRating>

TokenCount

Number of tokens for this candidate.

[JsonPropertyName("tokenCount")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public int? TokenCount { get; set; }

Property Value

int?

UrlContextMetadata

Output only. Metadata returned when the model uses the url_context tool to get information from a user-provided URL.

[JsonPropertyName("urlContextMetadata")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public UrlContextMetadata? UrlContextMetadata { get; set; }

Property Value

UrlContextMetadata

Methods

FromJson(string, JsonSerializerOptions?)

Deserializes a JSON string to a Candidate object.

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

Parameters

jsonString string

The JSON string to deserialize.

options JsonSerializerOptions

Optional JsonSerializerOptions.

Returns

Candidate

The deserialized Candidate object, or null if deserialization fails.