https://discord.gg/botpress logo
Hi everyone
# 🌎general
l
Hi everyone How to sanitize text inside TSX yield ? (Regex hook failing) I'm using Gemini 2.5 Flash Lite for RAG. When it strips KB citations, it leaves an annoying space before the period (e.g., "product ."). Strict prompting didn't fix it. I tried a Before Outgoing Message hook with regex (event.payload.text.replace(/\s+\./g, '.')), but it fails. I suspect it's because my bot uses a custom TSX router (yield ), so the text isn't directly in event.payload.text. Q: What is the exact payload path to access and sanitize the string inside a yielded TSX via a hook? Is there a better/built-in way to clean up citation whitespace when using lightweight LLMs? Thanks!
l
Hey @lively-dog-20024 I don't have an exact answer for this, i'll show you the solution our Docs Agent has provided and you can let me know if this works
Better way to clean citation whitespace Botpress does not provide a built‑in citation formatter, but the recommended approach is to perform the cleanup in a **Before Outgoing Message hook **as shown above. Because the hook runs after the LLM generates the answer but before the message is rendered, your regex will reliably strip the extra space before periods.
w
when you use yield in a TSX card, the content bypasses the standard event.payload.text pipeline
the Before Outgoing Message hook runs on the serialized payload, but by that point the TSX has already been rendered and the text lives inside the message's content structure
not the top level text field
but your regex also has a little error
`event.payload.text = event.payload.text?.replace(/\s+\./g, '.')`fixed verison
but it still wont work for tsx-wielded messages unless you also patch the nested payload
you could also try sanitization inside the tsx component itself
Copy code
js
const cleanText = (text: string) =>
  text.replace(/\s+\./g, '.').replace(/\s+,/g, ',')

// In your flow node:
const raw = workflow.answer  // or wherever your RAG output lands
yield <Message text={cleanText(raw)} />
or that could be fixed by using a better model on the response side
you're using gemini 2.5 flash lite for rag which is good
but check what you're using for the responses
3 Views