top of page

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

May 3
3 min read

Updated: Sep 22

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


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


Infographic explaining why <br> line breaks may appear correctly in AI chat but disappear when content is sent to another system, highlighting format conversion, native structured formatting, and API encoding as the main factors.

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. Use actual paragraph breaks or the target system’s supported paragraph format:

Line 1

Line 2

Line 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

  • encode line breaks as escaped newline characters (\n) inside JSON strings, or use a client/library that does this safely

  • 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: Many systems do not accept Markdown directly via APIs, or they only support a limited Markdown subset that must be converted before storage. 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.


Use this Prompt: Act as an AI-to-API formatting troubleshooter. Review this formatting issue: [describe the AI output, target system, API or automation method, payload format, error message, and final result]. Identify whether the issue is caused by raw HTML, unsupported Markdown, unescaped JSON line breaks, payload size, unsupported document schema, or target-system formatting rules. Return the answer as a table with: symptom, likely cause, evidence to check, safest format to use, payload fix, and test needed before scaling.

Comments


bottom of page