Skip to content

The open alternative to Salesforce, designed for AI.

fix(ai): render record links inside markdown headings in AI chat (#20074)

nitin480e5796ec55
diff --git a/packages/twenty-front/src/modules/ai/components/LazyMarkdownRenderer.tsx b/packages/twenty-front/src/modules/ai/components/LazyMarkdownRenderer.tsx
index 315c21ad5b5..43f60f32e93 100644
--- a/packages/twenty-front/src/modules/ai/components/LazyMarkdownRenderer.tsx
+++ b/packages/twenty-front/src/modules/ai/components/LazyMarkdownRenderer.tsx
@@ -121,6 +121,24 @@ const MarkdownRenderer = lazy(async () => {
li: ({ children }) => (
<li>{processChildrenForRecordLinks(children)}</li>
),
+ h1: ({ children }) => (
+ <h1>{processChildrenForRecordLinks(children)}</h1>
+ ),
+ h2: ({ children }) => (
+ <h2>{processChildrenForRecordLinks(children)}</h2>
+ ),
+ h3: ({ children }) => (
+ <h3>{processChildrenForRecordLinks(children)}</h3>
+ ),
+ h4: ({ children }) => (
+ <h4>{processChildrenForRecordLinks(children)}</h4>
+ ),
+ h5: ({ children }) => (
+ <h5>{processChildrenForRecordLinks(children)}</h5>
+ ),
+ h6: ({ children }) => (
+ <h6>{processChildrenForRecordLinks(children)}</h6>
+ ),
a: ({ children, href, title, node: _node }) => (
<a
className="markdown-link"
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/constants/chat-system-prompts.const.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/constants/chat-system-prompts.const.ts
index 876467fb1ec..fd2888383d5 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/constants/chat-system-prompts.const.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/constants/chat-system-prompts.const.ts
@@ -59,6 +59,7 @@ Record References - IMPORTANT:
- Tool responses include a "recordReferences" array with clickable links
- ONLY use record references that are returned by tools - NEVER make up IDs
- Copy the exact format from the tool response: [[record:objectName:recordId:displayName]]
+- Use record references only in paragraphs, lists, or markdown tables (\`| ... |\`); never in headings, code, links, or raw HTML
- The recordId MUST be a real UUID (like "abc12345-1234-5678-abcd-123456789012")
- DO NOT create record references before calling the tool
- DO NOT use placeholder IDs like "rec-snowflake" or "rec-person-1"