Firebase.AI.Schema

ASchema object allows the definition of input and output data types.

Summary

These types can be objects, but also primitives and arrays. Represents a select subset of anOpenAPI 3.0 schema object.

Public types

SchemaTypeenum
The value type of aSchema.

Properties

AnyOfSchemas
IReadOnlyList<Schema >
An array ofSchema objects.
Description
string
A human-readable explanation of the purpose of the schema or property.
EnumValues
IReadOnlyList< string >
Possible values of the element of type "String" with "enum" format.
Format
string
The format of the data.
Items
Schema of the elements of type "Array".
MaxItems
int
An integer specifying the maximum number of items the generated "Array" must contain.
Maximum
double
The maximum value of a numeric type.
MinItems
int
An integer specifying the minimum number of items the generated "Array" must contain.
Minimum
double
The minimum value of a numeric type.
Nullable
bool
Indicates if the value may be null.
Properties
IReadOnlyDictionary< string,Schema >
Properties of type "Object".
PropertyOrdering
IReadOnlyList< string >
A specific hint provided to the Gemini model, suggesting the order in which the keys should appear in the generated JSON string.
RequiredProperties
IReadOnlyList< string >
Required properties of type "Object".
Title
string
A human-readable name/summary for the schema or a specific property.
Type
The data type.

Public static functions

AnyOf(IEnumerable<Schema > schemas)
Returns aSchema representing a value that must conform toany (one or more) of the provided sub-schemas.
Array(Schema items, string description, bool nullable, int? minItems, int? maxItems)
Returns aSchema for an array.
Boolean(string description, bool nullable)
Returns aSchema representing a boolean value.
Double(string description, bool nullable, double? minimum, double? maximum)
Returns aSchema for a double-precision floating-point number.
Enum(IEnumerable< string > values, string description, bool nullable)
Returns aSchema for an enumeration.
Float(string description, bool nullable, float? minimum, float? maximum)
Returns aSchema for a single-precision floating-point number.
Int(string description, bool nullable, int? minimum, int? maximum)
Returns aSchema for a 32-bit signed integer number.
Long(string description, bool nullable, long? minimum, long? maximum)
Returns aSchema for a 64-bit signed integer number.
Object(IDictionary< string,Schema > properties, IEnumerable< string > optionalProperties, IEnumerable< string > propertyOrdering, string description, string title, bool nullable)
Returns aSchema representing an object.
String(string description, bool nullable,StringFormat? format)
Returns aSchema for a string.

Structs

Firebase.AI.Schema.StringFormat

Modifiers describing the expected format of a stringSchema.

Public types

SchemaType

SchemaType

The value type of aSchema.

Properties

AnyOfSchemas

IReadOnlyList<Schema>AnyOfSchemas

An array ofSchema objects.

The generated data must be valid againstany (one or more) of the schemas listed in this array. This allows specifying multiple possible structures or types for a single field.

For example, a value could be either aString or anInt: ```Schema.AnyOf(new [] {Schema.String(),Schema.Int() }) ```

Description

stringDescription

A human-readable explanation of the purpose of the schema or property.

While not strictly enforced on the value itself, good descriptions significantly help the model understand the context and generate more relevant and accurate output.

EnumValues

IReadOnlyList<string>EnumValues

Possible values of the element of type "String" with "enum" format.

Format

stringFormat

The format of the data.

Items

SchemaItems

Schema of the elements of type "Array".

MaxItems

intMaxItems

An integer specifying the maximum number of items the generated "Array" must contain.

Maximum

doubleMaximum

The maximum value of a numeric type.

MinItems

intMinItems

An integer specifying the minimum number of items the generated "Array" must contain.

Minimum

doubleMinimum

The minimum value of a numeric type.

Nullable

boolNullable

Indicates if the value may be null.

Properties

IReadOnlyDictionary<string,Schema>Properties

Properties of type "Object".

PropertyOrdering

IReadOnlyList<string>PropertyOrdering

A specific hint provided to the Gemini model, suggesting the order in which the keys should appear in the generated JSON string.

Important: Standard JSON objects are inherently unordered collections of key-value pairs. While the model will try to respect PropertyOrdering in its textual JSON output, subsequent parsing into native C# objects (like Dictionaries) might not preserve this order. This parameter primarily affects the raw JSON string serialization.

RequiredProperties

IReadOnlyList<string>RequiredProperties

Required properties of type "Object".

Title

stringTitle

A human-readable name/summary for the schema or a specific property.

This helps document the schema's purpose but doesn't typically constrain the generated value. It can subtly guide the model by clarifying the intent of a field.

Type

SchemaTypeType

The data type.

Public static functions

AnyOf

SchemaAnyOf(IEnumerable<Schema>schemas)

Returns aSchema representing a value that must conform toany (one or more) of the provided sub-schemas.

This schema instructs the model to produce data that is valid against at least one of the schemas listed in theschemas array. This is useful when a field can accept multiple distinct types or structures.

Details
Parameters
schemas
An array ofSchema objects. The generated data must be valid against at least one of these schemas. The array must not be empty.

Array

SchemaArray(Schemaitems,stringdescription,boolnullable,int?minItems,int?maxItems)

Returns aSchema for an array.

Details
Parameters
items
TheSchema of the elements stored in the array.
description
An optional description of what the array represents.
nullable
Indicates whether the value can benull. Defaults tofalse.
minItems
Instructs the model to produce at least the specified minimum number of elements in the array.
maxItems
Instructs the model to produce at most the specified minimum number of elements in the array.

Boolean

SchemaBoolean(stringdescription,boolnullable)

Returns aSchema representing a boolean value.

Details
Parameters
description
An optional description of what the boolean should contain or represent.
nullable
Indicates whether the value can benull. Defaults tofalse.

Double

SchemaDouble(stringdescription,boolnullable,double?minimum,double?maximum)

Returns aSchema for a double-precision floating-point number.

Details
Parameters
description
An optional description of what the number should contain or represent.
nullable
Indicates whether the value can benull. Defaults tofalse.
minimum
If specified, instructs the model that the value should be greater than or equal to the specified minimum.
maximum
If specified, instructs the model that the value should be less than or equal to the specified maximum.

Enum

SchemaEnum(IEnumerable<string>values,stringdescription,boolnullable)

Returns aSchema for an enumeration.

For example, the cardinal directions can be represented as: ```Schema.Enum(new string[]{ "North", "East", "South", "West" }, "Cardinal directions") ```

Details
Parameters
values
The list of valid values for this enumeration.
description
An optional description of what the enum represents.
nullable
Indicates whether the value can benull. Defaults tofalse.

Float

SchemaFloat(stringdescription,boolnullable,float?minimum,float?maximum)

Returns aSchema for a single-precision floating-point number.

Important: ThisSchema provides a hint to the model that it should generate a single-precision floating-point number, but only guarantees that the value will be a number. Therefore it'spossible that decoding it as afloat could overflow.

Details
Parameters
description
An optional description of what the number should contain or represent.
nullable
Indicates whether the value can benull. Defaults tofalse.
minimum
If specified, instructs the model that the value should be greater than or equal to the specified minimum.
maximum
If specified, instructs the model that the value should be less than or equal to the specified maximum.

Int

SchemaInt(stringdescription,boolnullable,int?minimum,int?maximum)

Returns aSchema for a 32-bit signed integer number.

Important: ThisSchema provides a hint to the model that it should generate a 32-bit integer, but only guarantees that the value will be an integer. Therefore it'spossible that decoding it as anint could overflow.

Details
Parameters
description
An optional description of what the integer should contain or represent.
nullable
Indicates whether the value can benull. Defaults tofalse.
minimum
If specified, instructs the model that the value should be greater than or equal to the specified minimum.
maximum
If specified, instructs the model that the value should be less than or equal to the specified maximum.

Long

SchemaLong(stringdescription,boolnullable,long?minimum,long?maximum)

Returns aSchema for a 64-bit signed integer number.

Details
Parameters
description
An optional description of what the number should contain or represent.
nullable
Indicates whether the value can benull. Defaults tofalse.
minimum
If specified, instructs the model that the value should be greater than or equal to the specified minimum.
maximum
If specified, instructs the model that the value should be less than or equal to the specified maximum.

Object

SchemaObject(IDictionary<string,Schema>properties,IEnumerable<string>optionalProperties,IEnumerable<string>propertyOrdering,stringdescription,stringtitle,boolnullable)

Returns aSchema representing an object.

This schema instructs the model to produce data of type "Object", which has keys of type "String" and values of any other data type (including nested "Objects"s).

Example: ACity could be represented with the following objectSchema. ```Schema.Object(properties: new Dictionary() { { "name",Schema.String() }, { "population", Schema.Integer() } }) ```

Details
Parameters
properties
The map of the object's property names to theirSchemas.
optionalProperties
The list of optional properties. They must correspond to the keys provided in theproperties map. By default it's empty, signaling the model that all properties are to be included.
propertyOrdering
An optional hint to the model suggesting the order for keys in the generated JSON string.
description
An optional description of what the object represents.
title
An optional human-readable name/summary for the object schema.
nullable
Indicates whether the value can benull. Defaults tofalse.

String

SchemaString(stringdescription,boolnullable,StringFormat?format)

Returns aSchema for a string.

Details
Parameters
description
An optional description of what the string should contain or represent.
nullable
Indicates whether the value can benull. Defaults tofalse.
format
An optional pattern that values need to adhere to.

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-07-24 UTC.