Schema

public final 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

Nested types

public static classSchema.Companion

Public methods

static final @NonNullSchema
array(@NonNullSchema items, String description, boolean nullable)

Returns aSchema for an array.

static final @NonNullSchema
boolean(String description, boolean nullable)

Returns aSchema representing a boolean value.

static final @NonNullSchema
double(String description, boolean nullable)

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

static final @NonNullSchema
enumeration(
    @NonNullList<@NonNullString> values,
    String description,
    boolean nullable
)

Returns aSchema for an enumeration.

static final @NonNullSchema
float(String description, boolean nullable)

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

static final @NonNullSchema
integer(String description, boolean nullable)

Returns aSchema for a 32-bit signed integer number.

static final @NonNullSchema
long(String description, boolean nullable)

Returns aSchema for a 64-bit signed integer number.

static final @NonNullSchema
obj(
    @NonNullMap<@NonNullString, @NonNullSchema> properties,
    @NonNullList<@NonNullString> optionalProperties,
    String description,
    boolean nullable
)

Returns aSchema for a complex data type.

static final @NonNullSchema
string(String description, boolean nullable, StringFormat format)

Returns aSchema for a string.

Public fields

description

public final String description

enum

public final List<@NonNullStringenum

format

public final String format

items

public final Schema items

nullable

public final Boolean nullable

properties

public final Map<@NonNullString, @NonNullSchemaproperties

required

public final List<@NonNullStringrequired

type

public final @NonNullString type

Public methods

array

public static final @NonNullSchema array(@NonNullSchema items, String description, boolean nullable)

Returns aSchema for an array.

Parameters
@NonNullSchema items

TheSchema of the elements stored in the array.

String description

An optional description of what the array represents.

boolean nullable

Indicates whether the value can benull. Defaults tofalse.

boolean

public static final @NonNullSchema boolean(String description, boolean nullable)

Returns aSchema representing a boolean value.

Parameters
String description

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

boolean nullable

Indicates whether the value can benull. Defaults tofalse.

double

public static final @NonNullSchema double(String description, boolean nullable)

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

Parameters
String description

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

boolean nullable

Indicates whether the value can benull. Defaults tofalse.

enumeration

public static final @NonNullSchema enumeration(
    @NonNullList<@NonNullString> values,
    String description,
    boolean nullable
)

Returns aSchema for an enumeration.

For example, the cardinal directions can be represented as:

Schema.enumeration(listOf("north","east","south","west"),"Cardinal directions")
Parameters
@NonNullList<@NonNullString> values

The list of valid values for this enumeration

String description

The description of what the parameter should contain or represent

boolean nullable

Indicates whether the value can benull. Defaults tofalse.

float

public static final @NonNullSchema float(String description, boolean nullable)

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
String description

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

boolean nullable

Indicates whether the value can benull. Defaults tofalse.

integer

public static final @NonNullSchema integer(String description, boolean nullable)

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
String description

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

boolean nullable

Indicates whether the value can benull. Defaults tofalse.

long

public static final @NonNullSchema long(String description, boolean nullable)

Returns aSchema for a 64-bit signed integer number.

Parameters
String description

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

boolean nullable

Indicates whether the value can benull. Defaults tofalse.

obj

public static final @NonNullSchema obj(
    @NonNullMap<@NonNullString, @NonNullSchema> properties,
    @NonNullList<@NonNullString> optionalProperties,
    String description,
    boolean nullable
)

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" to Schema.string(),
"population" to Schema.integer()
))
Parameters
@NonNullMap<@NonNullString, @NonNullSchema> properties

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

@NonNullList<@NonNullString> 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.

String description

An optional description of what the object represents.

boolean nullable

Indicates whether the value can benull. Defaults tofalse.

string

public static final @NonNullSchema string(String description, boolean nullable, StringFormat format)

Returns aSchema for a string.

Parameters
String description

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

boolean nullable

Indicates whether the value can benull. Defaults tofalse.

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