As we use LLMs for more complex tasks, prompts are growing longer and are often formatted on the fly with variables.

This is making the development process significantly harder. One template could work with a certain set of variables and break with another. The developer experience is also impacted since printing large texts in a notebook/terminal is far from ideal.

The Template & Variables feature tackles those issues by providing a segmented visualization of your prompts.

Setup

If you did not already setup the generation object, go here. Once this is done, open the Prompt Playground.

Template View

The template view will only be displayed if the template property is set in your generation object. For Chat LLMs, the template property is at the GenerationMessage level.

Template format

The template format is the Python f-string format. In the future we might support more template formats.

This means variables are encapsulated by curly brackets like {name}. If you want curly brackets in your output like "Hi {world}!", you should escape them by doubling them like so: Hi {{world}}!.

Highlighting

When using a variable in your template, the variable will be highlighted to clarify that it will get replaced by the content of the variable in the formatted template.

You can click on the highlighted variable to edit them.

Update a variable

One of the common use cases is to use the prompt playground to try different variable content.

Start with selecting the variable you want to edit.

Or simply click on the highlighted variable from the prompt template or formatted view.

You can then edit the variable in the opened modal. Click on “Save” to save the variable.

Edit a variable in the Prompt Playground

You can then click on “Submit” to get an updated completion.

If you want to preview the full prompt with your updated variables, go to the formatted view. Note that you can edit variables either from the Template or Formatted views.

Switch to the formatted view