When you insert a variable into an option, oftentimes you’ll want to transform the variable to a different format, type, or value before the step runs. A few examples:

  1. Summarize a piece of text
  2. Change a date’s format
  3. Extract text from an image

You can sometimes convert the value by adding a new step to your Spell, but this takes up space and can be cumbersome for converting multiple values.

To make it easier, Respell provides “converters” on variables to let you convert variables inside of options.

Converter Basics

Let’s look at an example:

In this case, we want to pass an object to a text option. An object is a collection of “keys” and “values” - like “company: Respell”. Since the variable is a different type than the option, this isn’t valid on its own - we don’t know what you mean by “put this object in this text box”. But we do have converters to turn the object to text; in this case, let’s access the first field in the object. This converter will look for the first field (“A”), and replace the variable with the A’s value.

Some converters may perform the same transformation as a step would, so why would you use a converter? There are two main reasons:

  1. Adding an extra step can make your spell larger and more difficult to read.
  2. Some converters don’t have steps with the same functionality.

With that said, converters don’t always offer the same level of flexibility of its corresponding step. The Describe Image step allows you to define extra options to describe an image in the way you expect, so if you need this control over the conversion you should consider using the Describe Image step.

Converted variables are also not persisted as new variables, so you will have to convert them in all options where you want the converted value. Finally, you cannot conditionally apply converters - if you use a converter on a variable, it will always happen.

Here are some tips for when you might want to use a step instead:

  1. You need more control over the conversion logic.
  2. You want to reuse the transformed variable in multiple places.
  3. You only want to use the converted variable sometimes (depending on a condition).

How To Use Converters

When you insert a variable in an option, you can hover over the variable to view the available converters for that variable. When you choose a converter, it will be appended to the variable’s pill. You can only use one converter per variable, so you can’t chain converters for now.