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

We have seen in the **Quickstart/Concepts** section that 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) and **JS Templates**. 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.

**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:**

| Name | Description | Example |
|---|---|---|
| `_now` | Returns the current ISO timestamp | `Report generated at {{_now}}` |
| `_model` | The model ID used for the current execution | `Model: {{_model}}` |
| `stringify` | Converts a value to its JSON representation | `Input data: {{stringify data}}` |
| `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}}` |

### JS Templates (advanced)

For advanced composition and templating needs, JS Templates provide the full power of JavaScript. Set the prompt segment's `content_type` to `"jst"`. JS Templates use JavaScript string interpolation and run in a sandboxed environment. Use JST when you need complex data transformations, CSV processing, date manipulation, or programmatic prompt construction that goes beyond what Handlebars conditionals and loops can express.

```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.