Output into paragraphs

What is the best way to have my agent output it’s responses into paragraphs? Currently it only outputs long blocks of text. Formatting would be nice.

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

To achieve your desired result, you can make use of the assistant message option inside of the AI Agent node.

Using this field you can enforce rules towards the output, for instance you can enforce a rule to the model that makes it act like a pirate:

Yeah, I’ve tried everything in the system prompt, even demanding that it not use markdown or asterisks. It still outputs asterisks on my website even though it works fine on the n8n chat. So I have added some code to my website script as follows. This is a piece of the script that outputs responses.

function appendMessage(sender, text) {
      const chatLog = document.getElementById('chat-log');
      if (!chatLog) return;
      
      // Create wrapper for the message.
      const wrapper = document.createElement('div');
      wrapper.classList.add("chat-text");
      
      // Create the actual message bubble.
      const bubble = document.createElement('div');
      bubble.style.textAlign = sender === "user" ? 'right' : 'left';
      bubble.style.margin = '0';
      
      // Format text: remove markdown asterisks, convert newlines to <br>, and add target="_blank" to <a> tags.
      let formattedText = text.replace(/\*\*/g, '').replace(/(\r\n|\r|\n)/gm, '<br>');
      formattedText = addTargetToLinks(formattedText);
      bubble.innerHTML = formattedText;
      
      if (sender === "user") {
        bubble.classList.add("user-text");
      } else {
        bubble.classList.add("agent-text");
      }
      
      // Append the bubble into the wrapper and then into the chat log.
      wrapper.appendChild(bubble);
      chatLog.appendChild(wrapper);
      chatLog.scrollTop = chatLog.scrollHeight;
      
      // Update stored history.
      let history = loadChatHistory();
      history.push({ sender, text });
      saveChatHistory(history);
    }

However, I would still like to find a better solution within n8n.

Sorry.

  • n8n version: 1.81.4
  • Database (default: SQLite): Notion & Window Buffer Memory
  • n8n EXECUTIONS_PROCESS setting (default: own, main): ?
  • Running n8n via (Docker, npm, n8n cloud, desktop app): cloud
  • Operating system: Windows 11

@N8TR0N I got some good news for you!
So using regular expressions and 3 lines of code, I was able to only retrieve json from the LLM.

By passing through a JSON Schema as mentioned in this article, you can force the LLM to return JSON in a consistant structure.

I hope this helped!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.