Learn how to fix broken Markdown formatting in Claude messages from n8n with simple steps to ensure clean, reliable outputs.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
The direct fix is: clean or escape the markdown before sending it to Claude. In n8n the Claude node will break formatting if the incoming text contains unescaped backticks, mismatched triple‑backticks, or malformed line breaks. The safe production pattern is to preprocess the message in a Function node so you output clean, valid markdown, or wrap the entire message in a fenced code block from n8n rather than passing through user‑generated raw text. In practice, you sanitize the text before it reaches the Claude node.
n8n passes data between nodes as plain JSON. If the text comes from a webhook, database, or another API, it can contain unclosed backticks, weird line breaks, or accidental triple‑backticks. Claude is strict about markdown fences, so malformed or nested backticks cause Claude to render everything incorrectly or to prematurely close code blocks.
The simplest stable solution is to preprocess the text before passing it to Claude. You strip or escape problematic sequences. In n8n this is done with a Function node, which gives you clean control of the exact string being output.
// n8n Function node
// This escapes backticks and normalizes line breaks
const input = $json.text || ""
const cleaned = input
.replace(/```/g, "ʼʼʼ") // replace triple-backticks with safe chars
.replace(/`/g, "ʼ") // replace single backticks
.replace(/\r\n/g, "\n") // normalize line breaks
.trim()
return [{ text: cleaned }]
This produces markdown that Claude will accept safely. Replace characters however you prefer; the key idea is that you remove anything that could prematurely close a markdown code fence.
If your use case is “send raw text and let Claude reason about it,” you can wrap the entire input in a controlled triple‑backtick block so Claude never interprets internal formatting.
// Function node wrapping content safely
const t = $json.text || ""
return [{
text: "```\n" + t + "\n```"
}]
Only do this if you want Claude to treat the content as literal text, not mixed instructions and markdown.
Claude only breaks formatting when the incoming string is malformed. The fix is to make sure your workflow produces valid markdown. The safest production strategy in n8n is to run every user‑generated or external text through a Function node that cleans or wraps it before sending it to Claude.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.