Gemini 3 Pro & Flash, Gemini 3 Pro Image (nano banana pro), and the latest Gemini Live API native audio models are now available to use with Firebase AI Logic on all platforms!
Template format, syntax, and examplesStay organized with collectionsSave and categorize content based on your preferences.
ForFirebase AI Logic, theFirebaseconsole provides a guided UI for you
to specify the contents of a template.
Server prompt templates use a Dotprompt-based syntax and format. On this page,
you can find detailed descriptions of the template format and syntax, along with
examples for bothGeminiandImagen.
Here are the most important components for an example request to aGeminimodel:
---
model: 'gemini-2.5-flash'
---
{{role "system"}}
All output must be a clearly structured invoice document.
Use a tabular or clearly delineated list format for line items.
{{role "user"}}
Create an example customer invoice for a customer named {{customerName}}.
The top section within the triple-dashes contains the model name as well as
optionally any model configuration, input validation, or schema you want to
send in the request. It's written as key-value pairs and is commonly called
YAMLfrontmatter.
The body of the template contains the prompt. It can also optionally include
system instructions and input values (usingHandlebarssyntax).
This page provides detailed descriptions of the template format and syntax,
along with examples, for the following:
All the examples in this section show templates that usegemini-2.5-flash, but
you can use anyGeminimodel supported byFirebase AI Logic(except for Gemini Live models).
Hello world
Here's a minimal example of a server prompt template:
Configuration (frontmatter)
---
model: 'gemini-2.5-flash'
---
Prompt and (as applicable) system instructions
Write a story about a magic backpack.
Control generation of responses
You can control the generation of responses in a variety of ways depending on
your use case and the level of control that you need.
Model configuration
Set amodel configurationto control how the
model generates a response,
like max output tokens, temperature, top-K, and top-P.
Setsystem instructionsto steer the
behavior of the model. You include them as part of the prompt:
Specify the system instructions using the{{role "system"}}syntax.
Specify the text prompt using the{{role "user"}}syntax.
Configuration (frontmatter)
---
model: 'gemini-2.5-flash'
---
Prompt and (as applicable) system instructions
{{role "system"}}
All output must be a clearly structured invoice document.
Use a tabular or clearly delineated list format for line items.
{{role "user"}}
Create an example customer invoice for a customer.
Input variables
Some prompts are static, but you often need to include some data from the user
as part of the prompt.
You can include dynamic input variables in the prompt usingHandlebarsexpressions, which
are contained within{{ }}tags in the format
of{{variableName}}or{{object.propertyName}}(for example,Hello, {{name}} from {{address.city}}).
Configuration (frontmatter)
---
model: 'gemini-2.5-flash'
---
Prompt and (as applicable) system instructions
Create an example customer invoice for a customer named {{customerName}}.
You can provide adefault valuein the
template, but the value of an input variable is usually provided by the client
as part of the request.
View client-side request that provides input values
Click yourGemini APIprovider to view provider-specific content
and code on this page.
Swift
// ...// Initialize the Gemini Developer API backend service// Create a `TemplateGenerativeModel` instanceletmodel=FirebaseAI.firebaseAI(backend:.googleAI()).templateGenerativeModel()letcustomerName="Jane"do{letresponse=tryawaitmodel.generateContent(// Specify your template IDtemplateID:"my-first-template-v1-0-0",// Provide the values for any input variables required by your template.inputs:["customerName":customerName])iflettext=response.text{print("Response Text:\(text)")}}catch{print("An error occurred:\(error)")}print("\n")
Kotlin
// ...// Initialize the Gemini Developer API backend service// Create a `TemplateGenerativeModel` instancevalmodel=Firebase.ai(backend=GenerativeBackend.googleAI()).templateGenerativeModel()valcustomerName="Jane"valresponse=model.generateContent(// Specify your template ID"my-first-template-v1-0-0",// Provide the values for any input variables required by your template.mapOf("customerName"tocustomerName))valtext=response.textprintln(text)
Java
// ...// Initialize the Gemini Developer API backend service// Create a `TemplateGenerativeModel` instanceTemplateGenerativeModelgenerativeModel=FirebaseAI.getInstance().templateGenerativeModel();TemplateGenerativeModelFuturesmodel=TemplateGenerativeModelFutures.from(generativeModel);StringcustomerName="Jane";Futureresponse=model.generateContent(// Specify your template ID"my-first-template-v1-0-0",// Provide the values for any input variables required by your template.mapOf("customerName",customerName));addCallback(response,newFutureCallback(){publicvoidonSuccess(GenerateContentResponseresult){System.out.println(result.getText());}publicvoidonFailure(Throwablet){reportError(t);}}executor);
Web
// ...// Initialize the Gemini Developer API backend serviceconstai=getAI(app,{backend:newGoogleAIBackend()});// Create a `TemplateGenerativeModel` instanceconstmodel=getTemplateGenerativeModel(ai);constcustomerName='Jane';constresult=awaitmodel.generateContent(// Specify your template ID'my-first-template-v1-0-0',// Provide the values for any input variables required by your template{customerName:customerName,});constresponse=result.response;consttext=response.text();
Dart
// ...// Initialize the Gemini Developer API backend service// Create a `TemplateGenerativeModel` instancevar_model=FirebaseAI.googleAI().templateGenerativeModel()varcustomerName='Jane';varresponse=await_model.generateContent(// Specify your template ID'my-first-template-v1-0-0',// Provide the values for any input variables required by your templateinputs:{'customerName':customerName,},);vartext=response?.text;print(text);
Unity
// ...// Initialize the Gemini Developer API backend servicevarfirebaseAI=FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());// Create a `TemplateGenerativeModel` instancevarmodel=firebaseAI.GetTemplateGenerativeModel();varcustomerName="Jane";try{varresponse=awaitmodel.GenerateContentAsync(// Specify your template ID"my-first-template-v1-0-0",// Provide the values for any input variables required by your templatenewDictionary<string,object>{{"customerName",customerName},});Debug.Log($"Response Text: {response.Text}");}catch(Exceptione){Debug.LogError($"An error occurred: {e.Message}");}
Control flows (loops & conditionals)
To write more complex prompts, you can use conditional blocks (like#if,else, and#unless) and iteration (#each).
You can provide additional contextual information as variables with a special@prefix:
@first: true when iterating the first item of an#eachblock.
@last: true when iterating the last item of an#eachblock.
@index: gives the (zero-based) index position of the current element.
Create an example customer invoice for a customer named {{customerName}}.
Include entries for each of the following products
{{#each productNames}}
{{#if @first}}
Include line items for the following purchases
{{/if}}
- {{this}}
{{/each}}
{{#if isVipCustomer}}
Give the customer a 5% discount.
{{/if}}
Note that conditionals only accept a variable reference, not any type of
expression, for example:
The following works:{{#if isVipCustomer}} ... {{/if}}
The following doesnotwork:{{#if customer.type == 'vip'}} ... {{/if}}
If the variable is a boolean, then the conditional works as you would expect.
If the variable isnota boolean then the conditional is effectively an
"is-not-null" check. This can be useful for handling optional inputs, for
example:
If you have data coming from the client, we strongly recommend using input
schema to help protect against prompt injection as well as ensure that the data
passed in the request matches your expectations.
You can provide default values in case the client doesn't provide a value.
The schema supports scalar typesstring,integer,number,boolean, andobject. Objects, arrays, and enums are denoted by a parenthetical after the
field name.
All properties are considered required unless you denote it as optional with?. When a property is marked as optional, it's also made nullable to provide
more leniency for LLMs to return null instead of omitting a field.
Here's abasic examplefor providing input schema. You can find a more
advanced schema just below.
Configuration (frontmatter)
---
model: 'gemini-2.5-flash'
input:
default:
isVipCustomer: false
schema:
customerName: string, the customers name # string, number, and boolean types are defined like this
productNames?(array, list of products to include in the invoice): string # optional fields are marked with a ?
isVipCustomer?: boolean, whether or not the customer is a VIP
---
Prompt and (as applicable) system instructions
Create an example customer invoice for a customer named {{customerName}}.
Include entries for each of the following products
{{#each productNames}}
{{#if @first}}
Include line items for the following purchases
{{/if}}
- {{this}}
{{/each}}
{{#if isVipCustomer}}
Give the customer a 5% discount.
{{/if}}
View a morecomplex examplefor providing input schema
Configuration (frontmatter)
---
model: gemini-2.5-flash
input:
schema:
customer:
type: object
description: details about the customer
required: [lastName, address]
properties:
firstName:
type: string
minLength: 2
maxLength: 50
lastName:
type: string
minLength: 2
maxLength: 50
address:
type: object
description: customer's address
required: [street, city, country]
properties:
street:
type: string
city:
type: string
country:
type: string
isVip:
type: boolean
description: whether or not the customer is a VIP
purchases?:
type: array
description: list of things the customer purchased
items:
type: object
required: [itemName, sku, cost, quantity]
properties:
itemName:
type: string
sku:
type: string
minLength: 7
maxLength: 19
pattern: "^[0-9]{1,3}-[a-zA-Z]{3,10}-[0-9]{1,4}$"
category:
enum: ["ELECTRONICS", "APPAREL", "HOME", "MISC" ]
cost:
type: number
minimum: 0
quantity:
type: number
minimum: 1
maximum: 200
---
Prompt and (as applicable) system instructions
Create an example customer invoice for a customer.
The customer's address is
{{customer.firstName}} {{customer.lastName}}
{{customer.address.street}}
{{customer.address.city}}
{{customer.address.country}}
{{#each purchases}}
{{#if @first}}
Include line items for the following purchaes
{{/if}}
- {{quantity}} x {{itemName}} ({{sku}}) @ ${{cost}}, category {{category}}
{{/each}}
{{#if customer.isVip}}
Give the customer a 5% discount.
{{/if}}
Output schema
If you want the model to generatestructured JSON output,
then you can specify an output schema. By specifyingformat: json, you're
constraining the model to always return a JSON response that follows the
specified schema.
The schema supports scalar typesstring,integer,number,boolean, andobject. Objects, arrays, and enums are denoted by a parenthetical after the
field name.
All properties are considered required unless you denote it as optional with?. When a property is marked as optional, it's also made nullable to provide
more leniency for LLMs to return null instead of omitting a field.
Here's abasic examplefor generating structured JSON output. You can
find a more advanced schema just below.
View a morecomplex examplefor generating structured JSON output
Configuration (frontmatter)
---
model: gemini-2.5-flash
output:
format: json
schema:
title: string # string, number, and boolean types are defined like this
subtitle?: string # optional fields are marked with a ?
draft?: boolean, true when in draft state
status?(enum, approval status): [PENDING, APPROVED]
date: string, the date of publication for example '2024-04-09' # descriptions follow a comma
tags(array, relevant tags for article): string # arrays are denoted via parentheses
authors(array):
name: string
email?: string
metadata?(object): # objects are also denoted via parentheses
updatedAt?: string, ISO timestamp of last update
approvedBy?: integer, id of approver
extra?: any, arbitrary extra data
(*): string, wildcard field
---
Prompt and (as applicable) system instructions
Store all the specified information about the provided article.
Multimodal input
Multimodal prompts sent to a Gemini model can include multiple types of input,
includingfiles(like text along with images, PDFs, plain-text files, audio, and video).
Provide a file using its URL with the{{media url}}syntax.
Provide an inline file with the{{media type="mime_type" data="contents"}}syntax.
Here's abasic examplefor providing multimodal input. You can find a more
complex example just below.
Configuration (frontmatter)
---
model: 'gemini-2.5-flash'
---
Prompt and (as applicable) system instructions
Describe this image
{{media type="mimeType" data="imageData"}}
View how to provide base64-encoded data to test your template in the console
If your template has input that's base64-encoded data, here's how you can
include it in the testing experience of theFirebaseconsole:
View a morecomplex examplefor providing multimodal input
Configuration (frontmatter)
---
model: gemini-2.5-flash
input:
schema:
image_urls?(array, urls of external images): string
inline_images?(array, inline image data):
type: object
properties:
mime_type: string
contents: string # inline data must be base64-encoded
---
Prompt and (as applicable) system instructions
{{role "system"}}
Use the following image as the basis for comparisons
{{media url="http://example.com/reference_img.bmp"}}
{{role "user"}}
What do the following images have in common?
{{#each image_urls}}
{{media url="this"}}
{{/each}}
{{#each inline_images}}
{{media type="mime_type" data="contents"}}
{{/each}}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-12-15 UTC."],[],[]]