Skip to main content

Variables

In most AI applications, prompts will not be static text. Often, they are composable texts, or templates that the application fills with information, such as:

  • user data (name, etc.)
  • application state context
  • date & time
  • knowledge retrieval results (for RAG)

Promptscape considers this, and enables composable & templated prompts through the use of variables.

Adding Variables to a Prompt

To add a variable to a prompt, all you need to do is wrap a placeholder variable name with curly braces in the prompt text. For example, consider this prompt;

This prompt contains a {variable}.

It's as easy as that!

note

There should be no spaces between the curly braces and the variable name, and no spaces in the name. The extension will warn if either incorrect configurations are encountered.

Providing Variable Values

If you're using the Promptscape Studio and you have the option 'Auto-parse template variables' toggled on, then the extension will automatically provide an form with input textfields for every variable in your prompt.

As an example, consider this prompt, with two variables:

Provide a {task} for the word {word}.

This prompt has two variables: task, and word. So, we are able to provide values for each in the auto-provided text fields:

variable-prompt

In this example, we provide 'definition' as the task variable value, and 'intelligence' as the value for the word variable. If we then change the task to 'synonym', and the word to 'artificial', the same template will be filled, and the response will reflect those variable values.

RAG Simulation

To simulate RAG context injection, the variable values are not restricted in length. You can use variables to define where in your prompt template your data will go, and then easily provide large retrieval results to test your prompt's context faithfulness & groundedness in real time.

tip

If you find yourself re-using the same variable and message combinations often during testing, you might benefit from Promptscape Scenarios!