Schema

classSchema


This class is deprecated.
The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk

Definition of a data type.

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

Note: While optional, including adescription field in yourSchema is strongly encouraged. The more information the model has about what it's expected to generate, the better the results.

Summary

Public companion functions

Schema
array(items: Schema, description: String?, nullable: Boolean)

Returns aSchema for an array.

Schema
boolean(description: String?, nullable: Boolean)

Returns aSchema representing a boolean value.

Schema
double(description: String?, nullable: Boolean)

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

Schema
enumeration(values: List<String>, description: String?, nullable: Boolean)

Returns aSchema for an enumeration.

Schema
float(description: String?, nullable: Boolean)

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

Schema
integer(description: String?, nullable: Boolean)

Returns aSchema for a 32-bit signed integer number.

Schema
long(description: String?, nullable: Boolean)

Returns aSchema for a 64-bit signed integer number.

Schema
obj(
    properties: Map<StringSchema>,
    optionalProperties: List<String>,
    description: String?,
    nullable: Boolean
)

Returns aSchema for a complex data type.

Schema
string(description: String?, nullable: Boolean, format: StringFormat?)

Returns aSchema for a string.

Public companion functions

array

fun array(items: Schema, description: String? = null, nullable: Boolean = false): Schema

Returns aSchema for an array.

Parameters
items: Schema

TheSchema of the elements stored in the array.

description: String? = null

An optional description of what the array represents.

nullable: Boolean = false

Indicates whether the value can benull. Defaults tofalse.

boolean

fun boolean(description: String? = null, nullable: Boolean = false): Schema

Returns aSchema representing a boolean value.

Parameters
description: String? = null

An optional description of what the boolean should contain or represent.

nullable: Boolean = false

Indicates whether the value can benull. Defaults tofalse.

double

fun double(description: String? = null, nullable: Boolean = false): Schema

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

Parameters
description: String? = null

An optional description of what the number should contain or represent.

nullable: Boolean = false

Indicates whether the value can benull. Defaults tofalse.

enumeration

fun enumeration(
    values: List<String>,
    description: String? = null,
    nullable: Boolean = false
): Schema

Returns aSchema for an enumeration.

For example, the cardinal directions can be represented as:

Schema.enumeration(listOf("north","east","south","west"),"Cardinal directions")
Parameters
values: List<String>

The list of valid values for this enumeration

description: String? = null

The description of what the parameter should contain or represent

nullable: Boolean = false

Indicates whether the value can benull. Defaults tofalse.

float

fun float(description: String? = null, nullable: Boolean = false): Schema

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 variable (orfloat in Java) could overflow.

Parameters
description: String? = null

An optional description of what the number should contain or represent.

nullable: Boolean = false

Indicates whether the value can benull. Defaults tofalse.

integer

fun integer(description: String? = null, nullable: Boolean = false): Schema

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 variable (orint in Java) could overflow.

Parameters
description: String? = null

An optional description of what the integer should contain or represent.

nullable: Boolean = false

Indicates whether the value can benull. Defaults tofalse.

long

fun long(description: String? = null, nullable: Boolean = false): Schema

Returns aSchema for a 64-bit signed integer number.

Parameters
description: String? = null

An optional description of what the number should contain or represent.

nullable: Boolean = false

Indicates whether the value can benull. Defaults tofalse.

obj

fun obj(
    properties: Map<StringSchema>,
    optionalProperties: List<String> = emptyList(),
    description: String? = null,
    nullable: Boolean = false
): Schema

Returns aSchema for a complex data type.

This schema instructs the model to produce data of type object, which has keys of typeString and values of typeSchema.

Example: Acity could be represented with the following objectSchema.

Schema.obj(mapOf(
"name"toSchema.string(),
"population"toSchema.integer()
))
Parameters
properties: Map<StringSchema>

The map of the object's property names to theirSchemas.

optionalProperties: List<String> = emptyList()

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.

description: String? = null

An optional description of what the object represents.

nullable: Boolean = false

Indicates whether the value can benull. Defaults tofalse.

string

fun string(
    description: String? = null,
    nullable: Boolean = false,
    format: StringFormat? = null
): Schema

Returns aSchema for a string.

Parameters
description: String? = null

An optional description of what the string should contain or represent.

nullable: Boolean = false

Indicates whether the value can benull. Defaults tofalse.

format: StringFormat? = null

An optional pattern that values need to adhere to.

Public properties

description

val descriptionString?

enum

val enumList<String>?

format

val formatString?

items

val itemsSchema?

nullable

val nullableBoolean?

properties

val propertiesMap<StringSchema>?

required

val requiredList<String>?

type

val typeString

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-21 UTC.