Template format, syntax, and examples


For Firebase AI Logic, the Firebase console 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 both Gemini and Imagen.

Here are the most important components for an example request to a Gemini model:

---
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 YAML frontmatter.

  • The body of the template contains the prompt. It can also optionally include system instructions and input values (using Handlebars syntax).


This page provides detailed descriptions of the template format and syntax, along with examples, for the following:



Gemini

All the examples in this section show templates that use gemini-2.5-flash, but you can use any Gemini model supported by Firebase 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.


Model configuration

Set a model configuration to control how the model generates a response, like max output tokens, temperature, top-K, and top-P.

Configuration (frontmatter)

---
model: 'gemini-2.5-flash'
config:
  candidateCount: 1
  temperature: 0.9
  topP: 0.1
  topK: 16
  maxOutputTokens: 200
  stopSequences: ["red"]
---

Prompt and (as applicable) system instructions

Write a story about a magic backpack.


System instructions

Set system instructions to 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 using Handlebars expressions, 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 a default value in the template, but the value of an input variable is usually provided by the client as part of the request.


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 #each block.
  • @last: true when iterating the last item of an #each block.
  • @index: gives the (zero-based) index position of the current element.

See the Handlebars documentation for information on all of the built-in logical helpers.

Configuration (frontmatter)

---
model: 'gemini-2.5-flash'
---

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

Note that conditionals only accept a variable reference, not any type of expression, for example:

  • The following works: {{#if isVipCustomer}} ... {{/if}}
  • The following does not work: {{#if customer.type == 'vip'}} ... {{/if}}

If the variable is a boolean, then the conditional works as you would expect. If the variable is not a boolean then the conditional is effectively an "is-not-null" check. This can be useful for handling optional inputs, for example:

{{#if customerName}}
Hello {{customerName}}
{{else}}
Hello Guest
{{/if}}


Input validation and schema

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 types string, integer, number, boolean, and object. 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 a basic example for 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}}


Output schema

If you want the model to generate structured JSON output, then you can specify an output schema. By specifying format: json, you're constraining the model to always return a JSON response that follows the specified schema.

  • The schema supports scalar types string, integer, number, boolean, and object. 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 a basic example for generating structured JSON output. You can find a more advanced schema just below.

Configuration (frontmatter)

---
model: gemini-2.5-flash
output:
  format: json
  schema:
    invoiceId: string
    invoiceFile(object, an invoice file):
      url?: string
      contents: string
      mimeType: string
---

Prompt and (as applicable) system instructions

Create an example customer invoice.


Multimodal input

Multimodal prompts sent to a Gemini model can include multiple types of input, including files (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 a basic example for 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"}}



Imagen (image generation)

With the initial release, server prompt templates support generating images using Imagen models and a text-only prompt. Check back soon for more support, including editing images with Imagen (when using the Vertex AI Gemini API).

Basic

This example shows a basic template for generating images with Imagen, with input variables and input validation similar to Gemini.

Configuration (frontmatter)

---
model: 'imagen-4.0-generate-001'
input:
  schema:
    prompt: 'string'
---

Prompt and (as applicable) system instructions

Create an image containing {{prompt}}

Advanced

This example shows how to add model configuration and use more advanced features in the prompt, like input variables, input validation, and control flows similar to Gemini.

Configuration (frontmatter)

---
model: 'imagen-4.0-fast-generate-001'
config:
  sampleCount: 1
  aspectRatio: "16:9"
  personGeneration: dont_allow
  includeRaiReason: true
input:
  schema:
    style(enum, The style of image): [photo, sketch, painting]
    subject: string, The object or animal or scenery to generate.
    context?: string, Optional background or context description.
  default:
    style: photo
---

Prompt and (as applicable) system instructions

A {{style}} of {{subject}}{{#if context}}{{context}}{{/if}}.