---
title: "Prompts"
source: "https://docs.vertesiahq.com/studio/prompts"
markdown: "https://docs.vertesiahq.com/llms/studio/prompts.md"
---

# Prompts

LLMs rely on a prompt they receive, and return a reply accordingly. Let's go deeper into how to configure a prompt and what can be achieved with it.

An `Interaction`'s prompt is made of one or many parametrized `Prompt Segments`.

A `Prompt Segment` has a role, such as `System` or `User`. \
System - This role is used to define the context of the interaction. For example, the system prompt can be used to define the persona of the LLM (*"You are a seasoned expert in legal affairs"*). \
User - This role is used to define the user input (*"Does this contract comply with corporate rules?"*).

Several `Prompt Segments` can thus be combined to make a consistent global prompt.


Each `Prompt Segment` can define a `Prompt Schema` made of zero or many `Input Parameters`.

An `Input Parameter` can have one of the following types:
- `string`
- `number`
- `integer`
- `boolean`
- `object`
- `any`
- `text`
- `media`
- `document`
- and the equivalent arrays, such as `string[]`

**Example : definition of a structured table of movies**

```bash
movie_input_table : object[]
  ├─ movie_title    : string
  ├─ movie_director : string
  └─ movie_synopsis : string
````

A `Prompt Segment` may refer to `Input Parameters` by injecting their value into the prompt's message.

## Defining and using simple prompt segment input parameters

In the following example we add two `Input Parameters` to a `Prompt Segment` intended to request the summary of a document text into a target language.


## Reusing prompt segments

Vertesia's `Prompt Segment Library` allows easily reusing them to serve new needs and use cases. In the following example, we fork an existing `Prompt` related to generic contracts in order to slightly adapt it to supplier contracts, and then add it to a relevant `Interaction`.


## Adding dynamicity and conditionality to a prompt

Vertesia supports two template engines for dynamic prompts: **Handlebars** (recommended for all new prompts) and **JS Templates** (legacy). Both allow you to inject input parameters, add conditionals, and iterate over data.

### Handlebars Templates (recommended)

Set the prompt segment's `content_type` to `"handlebars"`. Handlebars uses double curly braces for variable substitution with a clean, readable syntax.

For system prompts and agent instructions, include the current render time so the model has a reliable notion of today:

```handlebars
Today's date is {{_now}}.
```

**Variable substitution:**

```handlebars
Summarize the following {{document_type}} in {{target_language}}:

{{document_text}}
```

**Conditionals:**

```handlebars
Analyze the following contract.
{{#if focus_area}}
Focus specifically on: {{focus_area}}
{{/if}}
{{#if strict_mode}}
Flag any non-compliant clauses.
{{else}}
Provide a general overview.
{{/if}}
```

**Iterating over arrays:**

```handlebars
Review the following items:
{{#each items}}
- {{this.title}}: {{this.description}}
{{/each}}
```

**Helpers and System Variables:**

Registered helpers:

| Name | Description | Example |
|---|---|---|
| `_now` | Returns the current ISO timestamp at render time | `Report generated at {{_now}}` |
| `stringify` | Converts a value to JSON. Null/undefined become an empty string; strings are returned unchanged. | `Input data: {{stringify data}}` |

Standard Handlebars block helpers:

| Name | Description | Example |
|---|---|---|
| `if` / `unless` | Conditional rendering | `{{#if flag}}...{{/if}}` |
| `each` | Iterate over arrays or objects | `{{#each list}}...{{/each}}` |
| `with` | Change the evaluation context | `{{#with user}}{{name}}{{/with}}` |

Execution variables:

| Name | Description | Example |
|---|---|---|
| `_model` | The model ID used for the current execution, when the runner injects it. It is not a registered helper and may be absent in prompt preview unless supplied as input. | `Model: {{_model}}` |

No custom `default` helper is registered. Use `{{#if value}}{{value}}{{else}}fallback{{/if}}` for defaults.

### JS Templates (advanced)

JS Templates are a legacy compatibility option. New prompts should use Handlebars. Use JST only when maintaining an existing prompt that already depends on JavaScript execution.

```javascript
`Summarize the following text in ${target_language}:

${document_text}`
```

JS Templates support full JavaScript control flow and array operations:

```javascript
`Review the following ${items.length} items:
${items.map((item, i) => `${i + 1}. ${item.title}: ${item.description}`).join('\n')}

${strict_mode ? 'Flag any issues found.' : 'Provide a general overview.'}`
```

JS Templates provide a utility object `_` with the following helpers and system variables.

**Helpers and System Variables:**

| Name | Description |
|---|---|
| `_.stringify(value)` | JSON serialization |
| `_.loadCsv(text)` | Parse CSV text into an array of objects |
| `_.jsonToCsv(data)` | Convert an array of objects to CSV format |
| `_.addLineNumbers(text)` | Prefix each line with its line number |
| `_.dayjs(date?)` | Date manipulation via [Day.js](https://day.js.org/) |
| `_model` | The model ID used for the current execution |

The template must return a string as its final expression.


## Accessing properties of a stored document from a prompt

**Vertesia Content Store** is a convenient way to store contents within the platform - typically you knowledge bases, such as corporate policies, operational procedures, standards, or suppliers contracts.

It makes RAG (Retrieval Augmented Generation) much easier and also allows content metadata to be generated and stored in the platform. You may think about a first interaction extracting metadata from raw contracts, and a second performing specific analysis only on a subset of relevant contracts.

Stored `Content Objects` may thus not only contain text, but also metadata (properties). Should you need to access such metadata from a prompt, here is the way to achieve it.

The following example illustrates how to retrieve the `effective_date` of a stored contract from a `Prompt Segment`.


## Getting a suggestion of improvement for a prompt

What if you could get in a snap suggestions of improvement for your prompts? Here we go.