Firebase.AI.Schema

A Schema 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 an OpenAPI 3.0 schema object.

Public types

SchemaType enum
The value type of a Schema.

Properties

AnyOfSchemas
IEnumerable< Schema >
An array of Schema objects.
Description
string
A human-readable explanation of the purpose of the schema or property.
EnumValues
IEnumerable< 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
IEnumerable< string >
A specific hint provided to the Gemini model, suggesting the order in which the keys should appear in the generated JSON string.
RequiredProperties
IEnumerable< 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 a Schema representing a value that must conform to any (one or more) of the provided sub-schemas.
Array(Schema items, string description, bool nullable, int? minItems, int? maxItems)
Returns a Schema for an array.
Boolean(string description, bool nullable)
Returns a Schema representing a boolean value.
Double(string description, bool nullable, double? minimum, double? maximum)
Returns a Schema for a double-precision floating-point number.
Enum(IEnumerable< string > values, string description, bool nullable)
Returns a Schema for an enumeration.
Float(string description, bool nullable, float? minimum, float? maximum)
Returns a Schema for a single-precision floating-point number.
Int(string description, bool nullable, int? minimum, int? maximum)
Returns a Schema for a 32-bit signed integer number.
Long(string description, bool nullable, long? minimum, long? maximum)
Returns a Schema 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 a Schema representing an object.
String(string description, bool nullable, StringFormat? format)
Returns a Schema for a string.

Structs

Firebase.AI.Schema.StringFormat

Modifiers describing the expected format of a string Schema.

Public types

SchemaType

 SchemaType

The value type of a Schema.

Properties

AnyOfSchemas

IEnumerable< Schema > AnyOfSchemas

An array of Schema objects.

The generated data must be valid against any (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 a String or an Int: ``` Schema.AnyOf(new [] { Schema.String(), Schema.Int() }) ```

Description

string Description

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

IEnumerable< string > EnumValues

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

Format

string Format

The format of the data.

Items

Schema Items

Schema of the elements of type "Array".

MaxItems

int MaxItems

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

Maximum

double Maximum

The maximum value of a numeric type.

MinItems

int MinItems

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

Minimum

double Minimum

The minimum value of a numeric type.

Nullable

bool Nullable

Indicates if the value may be null.

Properties

IReadOnlyDictionary< string, Schema > Properties

Properties of type "Object".

PropertyOrdering

IEnumerable< 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

IEnumerable< string > RequiredProperties

Required properties of type "Object".

Title

string Title

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

SchemaType Type

The data type.

Public static functions

AnyOf

Schema AnyOf(
  IEnumerable< Schema > schemas
)

Returns a Schema representing a value that must conform to any (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 the schemas array. This is useful when a field can accept multiple distinct types or structures.

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

Array

Schema Array(
  Schema items,
  string description,
  bool nullable,
  int? minItems,
  int? maxItems
)

Returns a Schema for an array.

Details
Parameters
items
The Schema of the elements stored in the array.
description
An optional description of what the array represents.
nullable
Indicates whether the value can be null. Defaults to false.
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

Schema Boolean(
  string description,
  bool nullable
)

Returns a Schema representing a boolean value.

Details
Parameters
description
An optional description of what the boolean should contain or represent.
nullable
Indicates whether the value can be null. Defaults to false.

Double

Schema Double(
  string description,
  bool nullable,
  double? minimum,
  double? maximum
)

Returns a Schema 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 be null. Defaults to false.
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

Schema Enum(
  IEnumerable< string > values,
  string description,
  bool nullable
)

Returns a Schema 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 be null. Defaults to false.

Float

Schema Float(
  string description,
  bool nullable,
  float? minimum,
  float? maximum
)

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

Important: This Schema 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's possible that decoding it as a float could overflow.

Details
Parameters
description
An optional description of what the number should contain or represent.
nullable
Indicates whether the value can be null. Defaults to false.
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

Schema Int(
  string description,
  bool nullable,
  int? minimum,
  int? maximum
)

Returns a Schema for a 32-bit signed integer number.

Important: This Schema 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's possible that decoding it as an int could overflow.

Details
Parameters
description
An optional description of what the integer should contain or represent.
nullable
Indicates whether the value can be null. Defaults to false.
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

Schema Long(
  string description,
  bool nullable,
  long? minimum,
  long? maximum
)

Returns a Schema 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 be null. Defaults to false.
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

Schema Object(
  IDictionary< string, Schema > properties,
  IEnumerable< string > optionalProperties,
  IEnumerable< string > propertyOrdering,
  string description,
  string title,
  bool nullable
)

Returns a Schema 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: A City could be represented with the following object Schema. ``` Schema.Object(properties: new Dictionary() { { "name", Schema.String() }, { "population", Schema.Integer() } }) ```

Details
Parameters
properties
The map of the object's property names to their Schemas.
optionalProperties
The list of optional properties. They must correspond to the keys provided in the properties 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 be null. Defaults to false.

String

Schema String(
  string description,
  bool nullable,
  StringFormat? format
)

Returns a Schema for a string.

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