FirebaseVertexAI Framework Reference Stay organized with collections Save and categorize content based on your preferences.
Schema
@available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicfinalclassSchema:SendableextensionSchema:EncodableASchema object allows the definition of input and output data types.
These types can be objects, but also primitives and arrays. Represents a select subset of anOpenAPI 3.0 schema object.
Modifiers describing the expected format of a string
Schema.Declaration
Swift
@available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructStringFormat:EncodableProtoEnumModifiers describing the expected format of an integer
Schema.Declaration
Swift
@available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructIntegerFormat:EncodableProtoEnum,SendableThe data type.
Declaration
Swift
publicvartype:String{get}The format of the data.
Declaration
Swift
publicletformat:String?A human-readable explanation of the purpose of the schema or property. While not strictlyenforced on the value itself, good descriptions significantly help the model understand thecontext and generate more relevant and accurate output.
Declaration
Swift
publicletdescription:String?A human-readable name/summary for the schema or a specific property. This helps document theschema’s purpose but doesn’t typically constrain the generated value. It can subtly guide themodel by clarifying the intent of a field.
Declaration
Swift
publiclettitle:String?Indicates if the value may be null.
Declaration
Swift
publicletnullable:Bool?Possible values of the element of type “STRING” with “enum” format.
Declaration
Swift
publicletenumValues:[String]?Defines the schema for the elements within the
"ARRAY". All items in the generated arraymust conform to this schema definition. This can be a simple type (like .string) or a complexnested object schema.Declaration
Swift
publicletitems:Schema?An integer specifying the minimum number of items the generated
"ARRAY"must contain.Declaration
Swift
publicletminItems:Int?An integer specifying the maximum number of items the generated
"ARRAY"must contain.Declaration
Swift
publicletmaxItems:Int?The minimum value of a numeric type.
Declaration
Swift
publicletminimum:Double?The maximum value of a numeric type.
Declaration
Swift
publicletmaximum:Double?Defines the members (key-value pairs) expected within an object. It’s a dictionary where keysare the property names (strings) and values are nested
Schemadefinitions describing eachproperty’s type and constraints.Declaration
Swift
publicletproperties:[String:Schema]?An array of
Schemaobjects. The generated data must be valid againstany (one or more)of the schemas listed in this array. This allows specifying multiple possible structures ortypes for a single field.For example, a value could be either a
Stringor anInteger:Schema.anyOf(schemas:[.string(),.integer()])Declaration
Swift
publicletanyOf:[Schema]?An array of strings, where each string is the name of a property defined in the
propertiesdictionary that must be present in the generated object. If a property is listed here, themodel must include it in the output.Declaration
Swift
publicletrequiredProperties:[String]?A specific hint provided to the Gemini model, suggesting the order in which the keys shouldappear in the generated JSON string. Important: Standard JSON objects are inherently unorderedcollections of key-value pairs. While the model will try to respect propertyOrdering in itstextual JSON output, subsequent parsing into native Swift objects (like Dictionaries orStructs) might not preserve this order. This parameter primarily affects the raw JSON stringserialization.
Declaration
Swift
publicletpropertyOrdering:[String]?Returns a
Schemarepresenting a string value.This schema instructs the model to produce data of type
"STRING", which is suitable fordecoding into a SwiftString(orString?, ifnullableis set totrue).Tip
If a specific set of string values should be generated by the model (for example,“north”, “south”, “east”, or “west”), use
enumeration(values:description:nullable:)instead to constrain the generated values.Declaration
Swift
publicstaticfuncstring(description:String?=nil,nullable:Bool=false,format:StringFormat?=nil)->SchemaParameters
descriptionAn optional description of what the string should contain or represent; mayuse Markdown format.
nullableIf
true, instructs the model that itmay generatenullinstead of astring; defaults tofalse, enforcing that a string value is generated.formatAn optional modifier describing the expected format of the string. Currently noformats are officially supported for strings but custom values may be specified using
custom(_:), for example.custom("email")or.custom("byte"); theseprovide additional hints for how the model should respond but are not guaranteed to beadhered to.Returns a
Schemarepresenting an enumeration of string values.This schema instructs the model to produce data of type
"STRING"with theformat"enum".This data is suitable for decoding into a SwiftString(orString?, ifnullableis settotrue), or anenumwith strings as raw values.Example:The values
["north", "south", "east", "west"]for an enumeration of directions.enumDirection:String,Decodable{casenorth,south,east,west}Declaration
Swift
publicstaticfuncenumeration(values:[String],description:String?=nil,nullable:Bool=false)->SchemaParameters
valuesThe list of string values that may be generated by the model.
descriptionAn optional description of what the
valuescontain or represent; may useMarkdown format.nullableIf
true, instructs the model that itmay generatenullinstead of one ofthe strings specified invalues; defaults tofalse, enforcing that one of the stringvalues is generated.Returns a
Schemarepresenting a single-precision floating-point number.This schema instructs the model to produce data of type
"NUMBER"with theformat"float", which is suitable for decoding into a SwiftFloat(orFloat?, ifnullableisset totrue).Important
This
Schemaprovides a hint to the model that it should generate asingle-precision floating-point number, afloat, but only guarantees that the value willbe a number.Declaration
Swift
publicstaticfuncfloat(description:String?=nil,nullable:Bool=false,minimum:Float?=nil,maximum:Float?=nil)->SchemaParameters
descriptionAn optional description of what the number should contain or represent; mayuse Markdown format.
nullableIf
true, instructs the model that it may generatenullinstead of a number;defaults tofalse, enforcing that a number is generated.minimumIf specified, instructs the model that the value should be greater than orequal to the specified minimum.
maximumIf specified, instructs the model that the value should be less than or equalto the specified maximum.
Returns a
Schemarepresenting a floating-point number.This schema instructs the model to produce data of type
"NUMBER", which is suitable fordecoding into a SwiftDouble(orDouble?, ifnullableis set totrue).Declaration
Swift
publicstaticfuncdouble(description:String?=nil,nullable:Bool=false,minimum:Double?=nil,maximum:Double?=nil)->SchemaParameters
descriptionAn optional description of what the number should contain or represent; mayuse Markdown format.
nullableIf
true, instructs the model that it may returnnullinstead of a number;defaults tofalse, enforcing that a number is returned.minimumIf specified, instructs the model that the value should be greater than orequal to the specified minimum.
maximumIf specified, instructs the model that the value should be less than or equalto the specified maximum.
Returns a
Schemarepresenting an integer value.This schema instructs the model to produce data of type
"INTEGER", which is suitable fordecoding into a SwiftInt(orInt?, ifnullableis set totrue) or other integer types(such asInt32) based on the expected size of values being generated.Important
If a
formatofint32orint64isspecified, this provides a hint to the model that it should generate 32-bit or 64-bitintegers but thisSchemaonly guarantees that the value will be an integer. Therefore, itispossible that decoding into anInt32could overflow even if aformatofint32is specified.Declaration
Swift
publicstaticfuncinteger(description:String?=nil,nullable:Bool=false,format:IntegerFormat?=nil,minimum:Int?=nil,maximum:Int?=nil)->SchemaParameters
descriptionAn optional description of what the integer should contain or represent; mayuse Markdown format.
nullableIf
true, instructs the model that it may returnnullinstead of an integer;defaults tofalse, enforcing that an integer is returned.formatAn optional modifier describing the expected format of the integer. Currently theformats
int32andint64are supported; custom valuesmay be specified usingcustom(_:)but may be ignored by the model.minimumIf specified, instructs the model that the value should be greater than orequal to the specified minimum.
maximumIf specified, instructs the model that the value should be less than or equalto the specified maximum.
Returns a
Schemarepresenting a boolean value.This schema instructs the model to produce data of type
"BOOLEAN", which is suitable fordecoding into a SwiftBool(orBool?, ifnullableis set totrue).Declaration
Swift
publicstaticfuncboolean(description:String?=nil,nullable:Bool=false)->SchemaParameters
descriptionAn optional description of what the boolean should contain or represent; mayuse Markdown format.
nullableIf
true, instructs the model that it may returnnullinstead of a boolean;defaults tofalse, enforcing that a boolean is returned.Returns a
Schemarepresenting an array.This schema instructs the model to produce data of type
"ARRAY", which has elements of anyother data type (including nested"ARRAY"s). This data is suitable for decoding into manySwift collection types, includingArray, holding elements of types suitable for decodingfrom the respectiveitemstype.Declaration
Swift
publicstaticfuncarray(items:Schema,description:String?=nil,nullable:Bool=false,minItems:Int?=nil,maxItems:Int?=nil)->SchemaParameters
itemsThe
Schemaof the elements that the array will hold.descriptionAn optional description of what the array should contain or represent; mayuse Markdown format.
nullableIf
true, instructs the model that it may returnnullinstead of an array;defaults tofalse, enforcing that an array is returned.minItemsInstructs the model to produce at least the specified minimum number of elementsin the array; defaults to
nil, meaning any number.maxItemsInstructs the model to produce at most the specified maximum number of elementsin the array.
Returns a
Schemarepresenting 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"OBJECT"s). This data issuitable for decoding into Swift keyed collection types, includingDictionary, or othercustomstructorclasstypes.Example: A
Citycould be represented with the following objectSchema.Schema.object(properties:["name":.string(),"population":.integer()])The generated data could be decoded into a Swift native type:
structCity:Decodable{letname:Stringletpopulation:Int}Declaration
Swift
publicstaticfuncobject(properties:[String:Schema],optionalProperties:[String]=[],propertyOrdering:[String]?=nil,description:String?=nil,title:String?=nil,nullable:Bool=false)->SchemaParameters
propertiesA dictionary containing the object’s property names as keys and theirrespective
Schemas as values.optionalPropertiesA list of property names that may be be omitted in objects generatedby the model; these names must correspond to the keys provided in the
propertiesdictionary and may be an empty list.propertyOrderingAn optional hint to the model suggesting the order for keys in thegenerated JSON string. See
propertyOrderingfor details.descriptionAn optional description of what the object should contain or represent; mayuse Markdown format.
titleAn optional human-readable name/summary for the object schema.
nullableIf
true, instructs the model that it may returnnullinstead of an object;defaults tofalse, enforcing that an object is returned.Returns a
Schemarepresenting a value that must conform toany (one or more) of theprovided sub-schemas.This schema instructs the model to produce data that is valid against at least one of theschemas listed in the
schemasarray. This is useful when a field can accept multipledistinct types or structures.Example: A field that can hold either a simple user ID (integer) or a detailed userobject.
Schema.anyOf(schemas:[.integer(description:"User ID"),.object(properties:["userId":.integer(),"userName":.string()],description:"Detailed User Object")])The generated data could be decoded based on which schema it matches.
Declaration
Swift
publicstaticfuncanyOf(schemas:[Schema])->SchemaParameters
schemasAn array of
Schemaobjects. The generated data must be valid against at leastone of these schemas. The array must not be empty.
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-04-21 UTC.