This error is likely caused by the template formatter interpreting backslashes (`\`) in your `user_msg` as escape characters in a regular expression, which leads to invalid escape sequences like `\l` or `\6`. In Python's `re` module, unrecognized escape sequences (such as `\l`) will trigger a "bad escape" error. If your template formatter uses regular expressions to parse or substitute variables, any unescaped backslash in the input string can cause this issue. According to <https://github.com/Arize-ai/phoenix/blob/main/js/packages/phoenix-client/test/utils/formatPromptMessages.test.ts|formatPromptMessages.test.ts>, Phoenix's template formatting expects plain text and does not handle arbitrary backslashes as escapes.
To resolve this, ensure that any user input containing backslashes is properly escaped before being passed to the template formatter. For example, you can replace single backslashes with double backslashes (`\\`) in your `user_msg` before formatting. Would you like more detail or a code example for escaping backslashes?
Sources:
- <https://github.com/Arize-ai/phoenix/blob/main/js/packages/phoenix-client/test/utils/formatPromptMessages.test.ts|formatPromptMessages.test.ts>