Skip to content

Commit

Permalink
fix: remove autoescaping for jinja2 standard security level
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzLaurer committed Feb 6, 2025
1 parent a75e64d commit 32d9ee2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion prompt_templates/populators.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def __init__(self, security_level: Jinja2SecurityLevel = "standard"):
undefined=jinja2.StrictUndefined,
trim_blocks=True,
lstrip_blocks=True,
autoescape=True, # Keep autoescaping
autoescape=False,
cache_size=100, # Limited cache
auto_reload=False, # Still no auto reload
)
Expand Down
46 changes: 46 additions & 0 deletions scripts/testing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,52 @@
"logging.basicConfig(level=logging.INFO)"
]
},
{
"cell_type": "markdown",
"id": "d14c414a",
"metadata": {},
"source": [
"### Issue reproduction"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "a44d9323",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1. String before populate: The Atlantic Ocean is the second-largest of the world's oceans. It covers approximately 20 percent of Earth's surface\n",
"2. String after populate: \n",
" You are a helpful assistant that can answer questions about the world.\n",
" You are given the following information:\n",
" The Atlantic Ocean is the second-largest of the world's oceans. It covers approximately 20 percent of Earth's surface\n",
" \n"
]
}
],
"source": [
"from prompt_templates import TextPromptTemplate\n",
"\n",
"prompt_template = TextPromptTemplate(\n",
" template=\"\"\"\n",
" You are a helpful assistant that can answer questions about the world.\n",
" You are given the following information:\n",
" {{info}}\n",
" \"\"\",\n",
" template_variables=[\"info\"],\n",
")\n",
"\n",
"info = \"The Atlantic Ocean is the second-largest of the world's oceans. It covers approximately 20 percent of Earth's surface\"\n",
"print(f\"1. String before populate: {info}\")\n",
"\n",
"message = prompt_template.populate(info=info)\n",
"print(f\"2. String after populate: {message}\")"
]
},
{
"cell_type": "markdown",
"id": "914ed423",
Expand Down

0 comments on commit 32d9ee2

Please sign in to comment.