How to print curly braces

Hi, Recently there has been a change to the text generation to use regex for placing variable values inside templates instead of string.format. How do you place “{” or “}” inside a template to do something like this:

- text: '{{"variable":"{value}"}}'

should print


It does not work as it is. Looks like a patch is needed somewhere around

I briefly tested out and adding open curly braces to blacklist character should do it.

>>> text = re.sub(r'{([^\n,{]+?)}', r'{0[\1]}', '{{"variable":"{value}"}}')
>>> text
>>> text.format({"value": "new value"})
'{"variable":"new value"}'

I can find time this weekend to patch but if you need earlier, plz try the code above and see.

No rush, I created a variable in my actions file and sent the variable through so long.

body = "{curly braces}"
dispatcher.utter_template('template_name', tracker, **{'body': body})

FYI - Fixed regex to find slot by black listing curly braces within curly b… by naoko · Pull Request #3951 · RasaHQ/rasa · GitHub

1 Like

@naoko thanks for PRing your fix!

1 Like