aws-samples / aws-samples/bedrock-chat

[BUG] Error Fallback with LaTex markdown

Open
#542 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
1.3k
Forks
535
Avg merge
1d 12h
Merged PRs (30d)
10

Description

## Describe the bug

1. When using the ChatMessageMarkdown.tsx component to render Math heavy equations the streaming chat will be redirected to ErrorFallback.tsx when encountering $${some_random_math_latex}$$ that is wrapped in double $$ sign.

## To Reproduce

Steps to reproduce the behavior:

1. Create a new chatbot with prompt asking it to wrap the outputs with `$${user_input}$$` or `$$${user_input}$$$`
Prompt:
```
Always return any messages I type wrapped in $$$$${user_input}$$$$$, $${user_input}$$, $$${user_input}$$$
```

2. Enter a message as a user with the new chatbot
User input:
```
\vec{A} = A_x\hat{i} + A_y\hat{j} = (5 \cos 30°)\hat{i} + (5 \sin 30°)\hat{j} = (5\frac{\sqrt{3}}{2})\hat{i} + (5\frac{1}{2})\hat{j} \approx 4.33\hat{i} + 2.5\hat{j}
```

3. Redirected to ErrorFallback.tsx

## Screenshots

Here is the screenshot of my hacky fix I just replace the text in the ChatMessageMarkdown.tsx for now

![hacky-fix](https://github.com/user-attachments/assets/00f3aa1e-6a0c-4d52-9076-927869ed4483)

Output from copy button:
```
Here is the vector expression wrapped as requested: $$$$$\vec{A} = A_x\hat{i} + A_y\hat{j} = (5 \cos 30°)\hat{i} + (5 \sin 30°)\hat{j} = (5\frac{\sqrt{3}}{2})\hat{i} + (5\frac{1}{2})\hat{j} \approx 4.33\hat{i} + 2.5\hat{j}$$$$$
```

## Additional context

I'm not sure if this is the best way to work around the issue, hence I'm filling this issue.
```
const replaceTextProcessing = (text: string): string => {
return text.replace(/\${2,}/g, '$')
};
```

Contributor guide

Open the contributing guide

Research direction

Start in ChatMessageMarkdown.tsx and ErrorFallback.tsx, then reproduce the issue with the provided prompt and vector expression containing repeated $$ delimiters. Trace why the streaming response reaches the fallback, and verify that the same LaTeX-heavy response renders in the chat without redirecting to ErrorFallback.tsx.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.