akelad: Thanks for submitting this PR, we'll give it a review as soon as possible
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 56db9ebfb4f..61313e489fe 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -27,6 +27,7 @@ Fixed
 -----
 - ``rasa test core`` can handle compressed model files
 - Rasa can handle story files containing multi line comments
+- Template will retain `{` if escaped with `{`. e.g. `{{"foo": {bar}}}` will result in `{"foo": "replaced value"}`
 
 
 [1.1.8] - 2019-07-25
diff --git a/rasa/core/nlg/interpolator.py b/rasa/core/nlg/interpolator.py
index 43a4ac84c7f..fe2cb827ea2 100644
--- a/rasa/core/nlg/interpolator.py
+++ b/rasa/core/nlg/interpolator.py
@@ -10,10 +10,21 @@ def interpolate_text(template, values):
         # "{tag_name}" to "{0[tag_name]}"
         # as described here:
         # https://stackoverflow.com/questions/7934620/python-dots-in-the-name-of-variable-in-a-format-string#comment9695339_7934969
-        # assuming that slot_name do not contain newline character here
+        # black list character and make sure to not to allow
+        # (a) newline in slot name
+        # (b) { or } in slot name
         try:
-            text = re.sub(r"{([^\n]+?)}", r"{0[\1]}", template)
-            return text.format(values)
+            text = re.sub(r"{([^\n{}]+?)}", r"{0[\1]}", template)
+            text = text.format(values)
+            if "0[" in text:
+                # regex replaced tag but format did not replace
+                # likely cause would be that tag name was enclosed
+                # in double curly and format func simply escaped it.
+                # we don't want to return {0[SLOTNAME]} thus
+                # restoring original value with { being escaped.
+                return template.format({})
+
+            return text
         except KeyError as e:
             logger.exception(
                 "Failed to fill utterance template '{}'. "

Leave curly braces in template
**Rasa version**:
master

**Issue**:
Recently on the forum, this question was raised or issue was reported.

https://forum.rasa.com/t/how-to-print-curly-braces/12043

When template value has curly braces `{{"variable":"{value}"}}` it failed to replace slot.

proposed solution https://github.com/RasaHQ/rasa/pull/3951
diff --git a/tests/core/test_nlg.py b/tests/core/test_nlg.py
index 48bead0ce91..3cf6c3241da 100644
--- a/tests/core/test_nlg.py
+++ b/tests/core/test_nlg.py
@@ -17,7 +17,7 @@ from rasa.core.agent import Agent
 from tests.core.conftest import DEFAULT_ENDPOINTS_FILE
 
 
-@pytest.fixture(scope="module")
+@pytest.fixture(scope="session")
 def loop():
     loop = asyncio.new_event_loop()
     asyncio.set_event_loop(loop)
@@ -165,8 +165,27 @@ def test_nlg_fill_template_custom(slot_name, slot_value):
     }
 
 
+@pytest.mark.parametrize(
+    "template_text, expected",
+    [
+        ('{{"variable":"{slot_1}"}}', '{"variable":"foo"}'),
+        ("{slot_1} and {slot_2}", "foo and bar"),
+        ("{{{slot_1}, {slot_2}!}}", "{foo, bar!}"),
+        ("{{{slot_1}}}", "{foo}"),
+        ("{{slot_1}}", "{slot_1}"),
+    ],
+)
+def test_nlg_fill_template_text_with_json(template_text, expected):
+    template = {"text": template_text}
+    t = TemplatedNaturalLanguageGenerator(templates=dict())
+    result = t._fill_template(
+        template=template, filled_slots={"slot_1": "foo", "slot_2": "bar"}
+    )
+    assert result == {"text": expected}
+
+
 @pytest.mark.parametrize("slot_name, slot_value", [("tag_w_\n", "a")])
-def test_nlg_fill_template_w_bad_slot_name2(slot_name, slot_value):
+def test_nlg_fill_template_with_bad_slot_name(slot_name, slot_value):
     template_text = "{" + slot_name + "}"
     t = TemplatedNaturalLanguageGenerator(templates=dict())
     result = t._fill_template(

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov pytest-localserver pytest-sanic responses freezegun nbsphinx aioresponses moto
apt-get update apt-get install -y gcc
3.6
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
absl-py==1.4.0
aiofiles==0.8.0
aiohttp==3.5.4
aioresponses==0.7.6
alabaster==0.7.13
anyio==3.6.2
APScheduler==3.6.0
astor==0.8.1
async-generator==1.10
async-timeout==3.0.1
attrs==22.2.0
Babel==2.11.0
backports.zoneinfo==0.2.1
bleach==4.1.0
boto3==1.23.10
botocore==1.26.10
cached-property==1.5.2
certifi==2021.5.30
cffi==1.15.1
chardet==3.0.4
charset-normalizer==3.0.1
click==7.1.2
colorclass==2.2.0
coloredlogs==10.0
colorhash==1.0.2
ConfigArgParse==0.15.2
contextvars==2.4
coverage==6.2
cryptography==40.0.2
cycler==0.11.0
dataclasses==0.8
decorator==5.1.1
defusedxml==0.7.1
docopt==0.6.2
docutils==0.15.2
entrypoints==0.4
fakeredis==1.0.3
fbmessenger==6.0.0
Flask==1.1.4
Flask-Cors==3.0.10
freezegun==1.2.2
future==0.18.3
gast==0.6.0
gevent==1.4.0
greenlet==2.0.2
grpcio==1.48.2
h11==0.12.0
h5py==3.1.0
httpcore==0.14.7
httptools==0.6.0
httpx==0.22.0
humanfriendly==10.0
idna==2.8
idna-ssl==1.1.0
imagesize==1.4.1
immutables==0.19
importlib-metadata==4.8.3
importlib-resources==5.4.0
iniconfig==1.1.1
ipython-genutils==0.2.0
itsdangerous==1.1.0
Jinja2==2.11.3
jmespath==0.10.0
jsonpickle==1.1
jsonschema==2.6.0
jupyter-client==7.1.2
jupyter-core==4.9.2
jupyterlab-pygments==0.1.2
kafka-python==1.4.6
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.2
kiwisolver==1.3.1
Markdown==3.3.7
MarkupSafe==2.0.1
matplotlib==3.0.3
mattermostwrapper==2.1
mistune==0.8.4
mock==5.2.0
moto==4.0.13
multidict==4.7.6
nbclient==0.5.9
nbconvert==6.0.7
nbformat==5.1.3
nbsphinx==0.8.8
nest-asyncio==1.6.0
networkx==2.3
numpy==1.16.3
packaging==19.2
pandocfilters==1.5.1
pika==1.0.1
pluggy==1.0.0
prompt-toolkit==2.0.10
protobuf==3.19.6
psycopg2-binary==2.8.2
py==1.11.0
pycparser==2.21
pydot==1.4.1
Pygments==2.14.0
PyJWT==2.4.0
pykwalify==1.7.0
pymongo==3.8.0
pyparsing==3.1.4
PySocks==1.7.1
pytest==7.0.1
pytest-cov==4.0.0
pytest-localserver==0.9.0.post0
pytest-sanic==1.7.1
python-crfsuite==0.9.10
python-dateutil==2.8.0
python-engineio==4.11.2
python-socketio==4.0.1
python-telegram-bot==11.1.0
pytz==2019.1
pytz-deprecation-shim==0.1.0.post0
PyYAML==6.0.1
pyzmq==25.1.2
questionary==1.1.1
-e git+https://github.com/RasaHQ/rasa.git@9dcfc76d21eeba584217acc964e5f644b9154631#egg=rasa
rasa-sdk==1.1.1
redis==3.2.1
requests==2.22.0
requests-toolbelt==1.0.0
responses==0.17.0
rfc3986==1.5.0
rocketchat-API==0.6.31
ruamel.yaml==0.15.94
s3transfer==0.5.2
sanic==19.3.1
Sanic-Cors==0.9.8
sanic-jwt==1.3.1
Sanic-Plugins-Framework==0.9.5
scikit-learn==0.20.2
scipy==1.2.1
simple-websocket==1.1.0
simplejson==3.16.0
six==1.17.0
sklearn-crfsuite==0.3.6
slackclient==1.3.1
sniffio==1.2.0
snowballstemmer==2.2.0
sortedcontainers==2.4.0
Sphinx==5.3.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
SQLAlchemy==1.3.24
tabulate==0.8.10
tensorboard==1.13.1
tensorflow==1.13.1
tensorflow-estimator==1.13.0
termcolor==1.1.0
terminaltables==3.1.0
testpath==0.6.0
tomli==1.2.3
tornado==6.1
tqdm==4.31.0
traitlets==4.3.3
twilio==6.26.3
typing_extensions==4.1.1
tzdata==2025.2
tzlocal==4.2
ujson==4.3.0
urllib3==1.25.11
uvloop==0.14.0
wcwidth==0.2.13
webencodings==0.5.1
webexteamssdk==1.1.1
websocket-client==0.54.0
websockets==6.0
Werkzeug==1.0.1
wsproto==1.0.0
xmltodict==0.14.2
yarl==1.7.2
zipp==3.6.0

name: rasa
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - absl-py==1.4.0
      - aiofiles==0.8.0
      - aiohttp==3.5.4
      - aioresponses==0.7.6
      - alabaster==0.7.13
      - anyio==3.6.2
      - apscheduler==3.6.0
      - astor==0.8.1
      - async-generator==1.10
      - async-timeout==3.0.1
      - attrs==22.2.0
      - babel==2.11.0
      - backports-zoneinfo==0.2.1
      - bleach==4.1.0
      - boto3==1.23.10
      - botocore==1.26.10
      - cached-property==1.5.2
      - cffi==1.15.1
      - chardet==3.0.4
      - charset-normalizer==3.0.1
      - click==7.1.2
      - colorclass==2.2.0
      - coloredlogs==10.0
      - colorhash==1.0.2
      - configargparse==0.15.2
      - contextvars==2.4
      - coverage==6.2
      - cryptography==40.0.2
      - cycler==0.11.0
      - dataclasses==0.8
      - decorator==5.1.1
      - defusedxml==0.7.1
      - docopt==0.6.2
      - docutils==0.15.2
      - entrypoints==0.4
      - fakeredis==1.0.3
      - fbmessenger==6.0.0
      - flask==1.1.4
      - flask-cors==3.0.10
      - freezegun==1.2.2
      - future==0.18.3
      - gast==0.6.0
      - gevent==1.4.0
      - greenlet==2.0.2
      - grpcio==1.48.2
      - h11==0.12.0
      - h5py==3.1.0
      - httpcore==0.14.7
      - httptools==0.6.0
      - httpx==0.22.0
      - humanfriendly==10.0
      - idna==2.8
      - idna-ssl==1.1.0
      - imagesize==1.4.1
      - immutables==0.19
      - importlib-metadata==4.8.3
      - importlib-resources==5.4.0
      - iniconfig==1.1.1
      - ipython-genutils==0.2.0
      - itsdangerous==1.1.0
      - jinja2==2.11.3
      - jmespath==0.10.0
      - jsonpickle==1.1
      - jsonschema==2.6.0
      - jupyter-client==7.1.2
      - jupyter-core==4.9.2
      - jupyterlab-pygments==0.1.2
      - kafka-python==1.4.6
      - keras-applications==1.0.8
      - keras-preprocessing==1.1.2
      - kiwisolver==1.3.1
      - markdown==3.3.7
      - markupsafe==2.0.1
      - matplotlib==3.0.3
      - mattermostwrapper==2.1
      - mistune==0.8.4
      - mock==5.2.0
      - moto==4.0.13
      - multidict==4.7.6
      - nbclient==0.5.9
      - nbconvert==6.0.7
      - nbformat==5.1.3
      - nbsphinx==0.8.8
      - nest-asyncio==1.6.0
      - networkx==2.3
      - numpy==1.16.3
      - packaging==19.2
      - pandocfilters==1.5.1
      - pika==1.0.1
      - pluggy==1.0.0
      - prompt-toolkit==2.0.10
      - protobuf==3.19.6
      - psycopg2-binary==2.8.2
      - py==1.11.0
      - pycparser==2.21
      - pydot==1.4.1
      - pygments==2.14.0
      - pyjwt==2.4.0
      - pykwalify==1.7.0
      - pymongo==3.8.0
      - pyparsing==3.1.4
      - pysocks==1.7.1
      - pytest==7.0.1
      - pytest-cov==4.0.0
      - pytest-localserver==0.9.0.post0
      - pytest-sanic==1.7.1
      - python-crfsuite==0.9.10
      - python-dateutil==2.8.0
      - python-engineio==4.11.2
      - python-socketio==4.0.1
      - python-telegram-bot==11.1.0
      - pytz==2019.1
      - pytz-deprecation-shim==0.1.0.post0
      - pyyaml==6.0.1
      - pyzmq==25.1.2
      - questionary==1.1.1
      - rasa-sdk==1.1.1
      - redis==3.2.1
      - requests==2.22.0
      - requests-toolbelt==1.0.0
      - responses==0.17.0
      - rfc3986==1.5.0
      - rocketchat-api==0.6.31
      - ruamel-yaml==0.15.94
      - s3transfer==0.5.2
      - sanic==19.3.1
      - sanic-cors==0.9.8
      - sanic-jwt==1.3.1
      - sanic-plugins-framework==0.9.5
      - scikit-learn==0.20.2
      - scipy==1.2.1
      - simple-websocket==1.1.0
      - simplejson==3.16.0
      - six==1.17.0
      - sklearn-crfsuite==0.3.6
      - slackclient==1.3.1
      - sniffio==1.2.0
      - snowballstemmer==2.2.0
      - sortedcontainers==2.4.0
      - sphinx==5.3.0
      - sphinxcontrib-applehelp==1.0.2
      - sphinxcontrib-devhelp==1.0.2
      - sphinxcontrib-htmlhelp==2.0.0
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==1.0.3
      - sphinxcontrib-serializinghtml==1.1.5
      - sqlalchemy==1.3.24
      - tabulate==0.8.10
      - tensorboard==1.13.1
      - tensorflow==1.13.1
      - tensorflow-estimator==1.13.0
      - termcolor==1.1.0
      - terminaltables==3.1.0
      - testpath==0.6.0
      - tomli==1.2.3
      - tornado==6.1
      - tqdm==4.31.0
      - traitlets==4.3.3
      - twilio==6.26.3
      - typing-extensions==4.1.1
      - tzdata==2025.2
      - tzlocal==4.2
      - ujson==4.3.0
      - urllib3==1.25.11
      - uvloop==0.14.0
      - wcwidth==0.2.13
      - webencodings==0.5.1
      - webexteamssdk==1.1.1
      - websocket-client==0.54.0
      - websockets==6.0
      - werkzeug==1.0.1
      - wsproto==1.0.0
      - xmltodict==0.14.2
      - yarl==1.7.2
      - zipp==3.6.0
prefix: /opt/conda/envs/rasa

tests/core/test_nlg.py::test_nlg_fill_template_text_with_json[{{"variable":"{slot_1}"}}-{"variable":"foo"}] tests/core/test_nlg.py::test_nlg_fill_template_text_with_json[{{{slot_1}, tests/core/test_nlg.py::test_nlg_fill_template_text_with_json[{{{slot_1}}}-{foo}] tests/core/test_nlg.py::test_nlg_fill_template_text_with_json[{{slot_1}}-{slot_1}]
[ tests/core/test_nlg.py::test_nlg tests/core/test_nlg.py::test_nlg_endpoint_config_loading tests/core/test_nlg.py::test_nlg_schema_validation tests/core/test_nlg.py::test_nlg_schema_validation_empty_buttons tests/core/test_nlg.py::test_nlg_schema_validation_empty_image tests/core/test_nlg.py::test_nlg_fill_template_text[tag_w_underscore-a0] tests/core/test_nlg.py::test_nlg_fill_template_text[tag tests/core/test_nlg.py::test_nlg_fill_template_text[tag.with.dot-chocolate] tests/core/test_nlg.py::test_nlg_fill_template_text[tag-w-dash-apple tests/core/test_nlg.py::test_nlg_fill_template_text[tag-w-$-banana0] tests/core/test_nlg.py::test_nlg_fill_template_text[tag-w-@-one] tests/core/test_nlg.py::test_nlg_fill_template_text[tagCamelCase-two0] tests/core/test_nlg.py::test_nlg_fill_template_text[tag-w-*-three] tests/core/test_nlg.py::test_nlg_fill_template_text[tag_w_underscore-a1] tests/core/test_nlg.py::test_nlg_fill_template_text[tag.with.float.val-1.3] tests/core/test_nlg.py::test_nlg_fill_template_text[tag-w-$-banana1] tests/core/test_nlg.py::test_nlg_fill_template_text[tagCamelCase-two1] tests/core/test_nlg.py::test_nlg_fill_template_text[empty_string-] tests/core/test_nlg.py::test_nlg_fill_template_text[null-None] tests/core/test_nlg.py::test_nlg_fill_template_image[url-https://www.exampleimg.com] tests/core/test_nlg.py::test_nlg_fill_template_image[img1-https://www.appleimg.com] tests/core/test_nlg.py::test_nlg_fill_template_custom[tag_w_underscore-a0] tests/core/test_nlg.py::test_nlg_fill_template_custom[tag tests/core/test_nlg.py::test_nlg_fill_template_custom[tag.with.dot-chocolate] tests/core/test_nlg.py::test_nlg_fill_template_custom[tag-w-dash-apple tests/core/test_nlg.py::test_nlg_fill_template_custom[tag-w-$-banana0] tests/core/test_nlg.py::test_nlg_fill_template_custom[tag-w-@-one] tests/core/test_nlg.py::test_nlg_fill_template_custom[tagCamelCase-two0] tests/core/test_nlg.py::test_nlg_fill_template_custom[tag-w-*-three] tests/core/test_nlg.py::test_nlg_fill_template_custom[tag_w_underscore-a1] tests/core/test_nlg.py::test_nlg_fill_template_custom[tag.with.float.val-1.3] tests/core/test_nlg.py::test_nlg_fill_template_custom[tag-w-$-banana1] tests/core/test_nlg.py::test_nlg_fill_template_custom[tagCamelCase-two1] tests/core/test_nlg.py::test_nlg_fill_template_custom[empty_string-] tests/core/test_nlg.py::test_nlg_fill_template_custom[null-None] tests/core/test_nlg.py::test_nlg_fill_template_text_with_json[{slot_1} tests/core/test_nlg.py::test_nlg_fill_template_with_bad_slot_name[tag_w_\n-a] tests/core/test_nlg.py::test_nlg_fill_template_image_and_text[tag_w_underscore-a-url-https://www.exampleimg.com] tests/core/test_nlg.py::test_nlg_fill_template_image_and_text[tag tests/core/test_nlg.py::test_nlg_fill_template_text_and_custom[tag_w_underscore-a-tag.with.dot-chocolate] tests/core/test_nlg.py::test_nlg_fill_template_text_and_custom[tag tests/core/test_nlg.py::test_nlg_fill_template_attachment[attach_file-https://attach.pdf] tests/core/test_nlg.py::test_nlg_fill_template_button[button_1-button1] tests/core/test_nlg.py::test_nlg_fill_template_quick_replies[qreply-reply
CHANGELOG.rst rasa/core/nlg/interpolator.py
CHANGELOG.rst rasa/core/nlg/interpolator.py