top of page

Why Don’t <br> Tags Work When AI Outputs Content to Other Systems?

  • May 3
  • 2 min read
My AI returns <br> for line breaks, but when I push it into another system, they disappear.

…and quickly turns into:

  • formatting issues

  • API errors

  • large payload headaches

Let’s break it down.


The root issue: Most systems are not HTML renderers

Even if your AI returns:

Line 1<br>Line 2<br>Line 3

Many platforms will strip or ignore <br> when content is inserted via:

  • APIs

  • automations

  • integrations


Developer reviewing AI-generated text and formatting issues on a laptop while troubleshooting API errors and document rendering.

Why? Because most modern systems convert content into their own internal formats rather than rendering raw HTML.


What’s happening under the hood

Instead of storing HTML directly, systems often convert content into:

  • structured document formats (e.g., JSON-based schemas)

  • proprietary storage formats

  • sanitized HTML

During that conversion:

  • inline HTML like <br> is removed or ignored

  • spacing is normalized

  • formatting is reinterpreted


What actually works for line breaks

Instead of <br>, use formats that systems understand natively:

Double line breaks (most reliable):

Line 1Line 2Line 3

Structured formatting:

  • paragraphs

  • lists

  • tables

These map cleanly into most document models.


Why behavior differs between interfaces

You may notice:

  • AI chat interfaces → render formatting correctly

  • downstream systems (pages, tickets, docs) → behave differently

That’s because:

  • chat interfaces render text directly

  • external systems reprocess and store the content

So what looks correct in AI output may not survive insertion.


That “400 error” isn’t what you think

A common error looks like:

INVALID_MESSAGEIllegal unquoted character ((CTRL-CHAR, code 10))

This is not a size issue—it’s invalid JSON.

What’s happening:

  • raw line breaks are being passed inside a JSON string

  • JSON requires escaped line breaks (\n)


How to fix it

Option 1: Proper JSON encoding

  • replace line breaks with \n

  • escape quotes

  • use a client/library that handles encoding automatically

Option 2: Send structured payloads

  • avoid raw string blobs

  • send content as objects where supported


Markdown ≠ universally supported

Another key point:

Most systems do not accept Markdown directly via APIs.

Instead, they expect:

  • structured JSON formats

  • or specific HTML subsets

So Markdown output from AI often needs conversion before insertion.


Why large outputs break things

When AI generates large responses, issues increase:

  • deeply nested JSON structures

  • large tables

  • long text fields

  • API payload limits

Result:

  • truncation

  • failed requests

  • inconsistent formatting


Why simpler formats help

Using simpler formats (like basic HTML or flatter structures) can:

  • reduce nesting

  • improve reliability

  • make payloads easier to process


But limits still exist. You still need to:

  • split large outputs

  • trim content

  • avoid sending everything at once


Best practices (save yourself the headache)

If you’re pushing AI-generated content into other systems:

  1. Avoid <br> entirely

  2. Use structured formatting (paragraphs, lists, tables)

  3. Batch large outputs

    • split into sections or multiple requests

  4. Keep content concise

    • link out instead of embedding everything

  5. Match the target system’s format

    • don’t assume HTML or Markdown will work


Takeaway

Most of these issues aren’t AI problems. They’re:

  • format mismatches

  • encoding errors

  • system constraints

AI generates content. The destination system decides how it survives.

Comments


bottom of page