[Bug]: Error when Using System Prompt with LaTeX Instructions and \text{...}
Is there an existing issue for the same bug?
- [x] I have checked the existing issues.
RAGFlow workspace code commit ID
g17fa2e9e
RAGFlow image version
v0.16.0-39-g17fa2e9e slim
Other environment information
Hardware parameters: N/A
OS type: Windows
Others: System chat models tested: OpenAI models (e.g., GPT-4o-mini, GPT-4o), Gemini models. Issue appears to be independent of the specific LLM.
Actual behavior
Setting a system prompt with LaTeX formatting instructions in chat model, especially when including instructions and examples for the \text{...} command, results in different types of errors during prompt processing, depending on the specific prompt structure. Here's a breakdown of how to reproduce each observed error:
-
ERROR: Replacement index 1 out of range for positional args tuple: This error occurs when the system prompt includes more complex LaTeX instructions, especially when combining multiple formula examples and the\text{...}instruction. For instance, using the full system prompt provided in "Steps to reproduce" below, which includes examples for inline formulas, display formulas, and\text{...}, will reliably trigger this error. It suggests a problem with how RAGFlow handles string formatting or placeholder substitution when encountering multiple LaTeX special characters and patterns within a longer prompt string. -
ERROR: 'j\\theta': This specific LaTeX syntax error is triggered when the system prompt includes LaTeX examples with incorrect syntax, specifically usingj\\thetainstead of the correctj\thetafor representing "j times theta" in mathematical notation. This was observed when using a system prompt with an Euler's formula example wherej\\thetawas mistakenly used. This indicates that while RAGFlow's prompt processing can detect some LaTeX syntax issues (after the initial processing error), it still fails during the initial prompt application due to the broader parsing problem. -
ERROR: '解释文字'(or similar errors indicating problems with the Chinese phrase "解释文字" within the\text{...}instruction): This error arises even with simplified prompts that focus solely on the\text{...}instruction. For example, a prompt that only includes instructions on how to use\text{...}, even without formula examples, and uses the Chinese phrase "解释文字" (or its English translation attempts like "explanatory text" or "your explanation") as a placeholder within the\text{...}instruction, will trigger this error. This strongly suggests that RAGFlow's prompt processing misinterprets the phrase "解释文字" (or similar placeholders) within the\text{...}instruction context as a variable or placeholder that needs substitution, leading to an error if no such substitution is defined.
In summary, RAGFlow's prompt processing exhibits errors when handling system prompts that incorporate LaTeX formatting instructions, particularly when \text{...} is involved, and the errors vary depending on the complexity and specific syntax of the LaTeX instructions within the prompt.
Expected behavior
The system should successfully accept and apply system prompts containing LaTeX formatting instructions and examples, including instructions on using \text{...} for inline text within formulas. The prompt processing should correctly handle LaTeX special characters and commands within the system prompt without throwing errors. The chat model should then follow the system prompt instructions and generate responses with mathematical formulas formatted in LaTeX, including using \text{...} for inline explanations when needed.
Steps to reproduce
1. Navigate to the chat interface in RAGFlow v0.16.0 full (workspace code commit ID g17fa2e9e, image version v0.16.0-39-g17fa2e9e slim).
2. **To reproduce `ERROR: Replacement index 1 out of range for positional args tuple`**: Attempt to set the following system prompt for the chat model:
Additional information
No response
How to re-produce? I can't get any error message like following.
How to re-produce? I can't get any error message like following.
1.re-produce in here
2.using systerm prompt:
Please provide all mathematical formulas in LaTeX format, using the amsmath package.
-
Inline formulas: Use
\( ... \)or$ ... $to enclose formulas within text lines. For example:\( f_s = \frac{1}{2\pi\sqrt{L_q C_q}} \)or$f_s = \frac{1}{2\pi\sqrt{L_q C_q}}$. -
Displayed (separate line) formulas: Use
\[ ... \]to enclose formulas that should appear on their own line. For example:\[ f_s = \frac{1}{2\pi\sqrt{L_q C_q}} \]. - Use
\text{...}to include any explanatory text within formulas. - Ensure all formulas are clear, understandable, and easily copy-pasted into a LaTeX document.
- Pay attention to the display of expressions like
L_q, ensuring both the subscriptqand the baseLare rendered correctly. - Utilize the provided knowledge base, combined with your existing knowledge, to generate accurate responses.
3.the bug: Ask any question and you will trigger this:
Double braces like {{xxx}}, how about this?
Double braces like
{{xxx}}, how about this?
I previously tried, but it didn't work and still reported an error: ERROR: Replacement index 1 out of range for positional args tuple
I didn't re-produce it by this. Did I miss something?
using system prompt like this please:
Please provide all mathematical formulas in LaTeX format, using the amsmath package.
-
Inline formulas: Use
\( ... \)or$ ... $to enclose formulas within text lines. For example:\( f_s = \frac{1}{2\pi\sqrt{L_q C_q}} \)or$f_s = \frac{1}{2\pi\sqrt{L_q C_q}}$. -
Displayed (separate line) formulas: Use
\[ ... \]to enclose formulas that should appear on their own line. For example:\[ f_s = \frac{1}{2\pi\sqrt{L_q C_q}} \]. - Use
\text{...}to include any explanatory text within formulas. - Ensure all formulas are clear, understandable, and easily copy-pasted into a LaTeX document.
- Pay attention to the display of expressions like
L_q, ensuring both the subscriptqand the baseLare rendered correctly. - Utilize the provided knowledge base, combined with your existing knowledge, to generate accurate responses.