Repository: promptfoo/promptfoo
Issue: [Issue] SyntaxError when executing Python code with unterminated string literal
Root cause: Validation Gap

I encountered a SyntaxError while attempting to execute the following Python code as an Assertion:

```
max(0, len(output) - 300)
```
The error message I received is as follows:

typescript
```
SyntaxError: unterminated string literal (detected at line 1)
```

I need assistance in resolving this issue and understanding why the SyntaxError is occurring. 

Here is the full error message:

> Python code execution failed: Command failed: python -c "import json; import math; import os; import sys; import re; import datetime; import random; import collections; output='You can expect to receive your refund within 2-10 days after receiving a return confirmation via email. The refund will be processed to the same payment method used when placing your order. [1] Unfortunately, there is no information regarding the location of your refund. However, if you are looking for your invoice, it will be attached to the shipping confirmation email \"Your order has been shipped\" as soon as your order has been shipped from the warehouse. [2] Additionally, if you have made the payment through PayPal, you will receive an order confirmation which contains the link to your PayPal payment. [3]'; context='{\"prompt\":\"template_format: jinja2\n\n- role: system\n content: |\n You are a helpful assistant tasked with summarizing search results.<br>\n Follow guidelines:\n <br>Write the summary on behalf of about the search results you\'re provided with.\n <br>Respond in English or in the language of the search results.\n- role: user\n content: |\n Your goal is to summarize the search results in alignment with the provided query.<br>\n Follow guidelines:\n - Only include information relevant to the query.\n - Exclude any details not present in the search results.\n - Skip the introductory sentence that this is the summary, proceed directly to the summary text.\n - Be concise, logical, and factual.\n - Always try to provide sources and cite them using formats like [1] or [2][3] immediately after the respective sentence.\n <br><br>\n Query: Where is my refund<br>\n Search Results:\n <br><br>\n [1]<br>Passage: <strong>When will I receive my refund?</strong><p>It takes around 10-12 business days for us to receive and process your return. We will refund you the purchase amount to the same payment method used when placing your order. The refunded amount will be visible in your bank account within 2-10 days after you receive a return confirmation via email.</p><br><br>[2]<br>Passage: <strong>Where can I find my Invoice?</strong><p>Your invoice will be attached to the shipping confirmation email \\"Your order has been shipped\\" as soon as your order has been shipped from our warehouse.</p><br><br>[3]<br>Passage: <strong>What can I expect in my payment confirmation e-mail from PayPal?</strong><p>You will receive an order confirmation which contains the link to your PayPal payment. If for some reason, the payment process is interrupted, this link offers you the chance to reprocess your payment with PayPal.</p><br><br>\n <br>\",\"vars\":{\"query\":\"Where is my refund\",\"sections\":\"[1]<br>Passage: <strong>When will I receive my refund?</strong><p>It takes around 10-12 business days for us to receive and process your return. We will refund you the purchase amount to the same payment method used when placing your order. The refunded amount will be visible in your bank account within 2-10 days after you receive a return confirmation via email.</p><br><br>[2]<br>Passage: <strong>Where can I find my Invoice?</strong><p>Your invoice will be attached to the shipping confirmation email \\"Your order has been shipped\\" as soon as your order has been shipped from our warehouse.</p><br><br>[3]<br>Passage: <strong>What can I expect in my payment confirmation e-mail from PayPal?</strong><p>You will receive an order confirmation which contains the link to your PayPal payment. If for some reason, the payment process is interrupted, this link offers you the chance to reprocess your payment with PayPal.</p><br><br>\",\"language\":\"en\",\"account_name\":\"\"}}'; print(json.dumps(max(0, len(re.escape(output)) - 300)))" File "<string>", line 1 import json; import math; import os; import sys; import re; import datetime; import random; import collections; output='You can expect to receive your refund within 2-10 days after receiving a return confirmation via email. The refund will be processed to the same payment method used when placing your order. [1] Unfortunately, there is no information regarding the location of your refund. However, if you are looking for your invoice, it will be attached to the shipping confirmation email "Your order has been shipped" as soon as your order has been shipped from the warehouse. [2] Additionally, if you have made the payment through PayPal, you will receive an order confirmation which contains the link to your PayPal payment. [3]'; context='{"prompt":"template_format: jinja2\n\n- role: system\n content: |\n You are a helpful assistant tasked with summarizing search results.<br>\n Follow guidelines:\n <br>Write the summary on behalf of about the search results you\'re provided with.\n <br>Respond in English or in the language of the search results.\n- role: user\n content: |\n Your goal is to summarize the search results in alignment with the provided query.<br>\n Follow guidelines:\n - Only include information relevant to the query.\n - Exclude any details not present in the search results.\n - Skip the introductory sentence that this is the summary, proceed directly to the summary text.\n - Be concise, logical, and factual.\n - Always try to provide sources and cite them using formats like [1] or [2][3] immediately after the respective sentence.\n <br><br>\n Query: Where is my refund<br>\n Search Results:\n <br><br>\n [1]<br>Passage: <strong>When will I receive my refund?</strong><p>It takes around 10-12 business days for us to receive and process your return. We will refund you the purchase amount to the same payment method used when placing your order. The refunded amount will be visible in your bank account within 2-10 days after you receive a return confirmation via email.</p><br><br>[2]<br>Passage: <strong>Where can I find my Invoice?</strong><p>Your invoice will be attached to the shipping confirmation email \Your ^ 

It looks like some quotes are not properly escaped in the handling of Python asserts.  I've opened a PR (#156) to make this handling more robust.

In the meantime as a workaround, you can use the equivalent `javascript` assert:
```js
Math.max(0, output.length - 300)
```

This should be fixed in 0.24.1.  Please let me know if not!