regex

Contents

regex#

class langworks.dsl.constraints.regex.Regex#

A constraint specifying a regular expression that the LLM must conform to during generation. They may be embedded in queries as follows:

```
The sentiment is: {% regex "(positive)|(negative)" %}.
```

Any of the default constraint arguments may also be passed:

```
The sentiment is: {% 
    regex "(positive)|(negative)", var = "sentiment", params = Params(max_tokens = 2) 
%}
```

Properties#

spec: str = None#

The regular expression that specifies the constraint.