Trafficaro guides · Message Templates

Writing Template Variables That Do Not Break

Jul 12, 2026 · Trafficaro Editorial Team

Approval and delivery are separate hurdles. A template can pass review cleanly and then fail for a real customer because the data filling it was not what you assumed. These failures are silent, individual, and easy to miss.

What breaks a send

  • Empty values. A missing first name sends "Hi , your order is ready" or fails outright.
  • Newlines and tabs inside a variable are rejected at send time.
  • Over-long values. A product name that runs to 300 characters can push the message past its limit.
  • Wrong count. Supplying three values to a four-variable template fails the whole send.
  • Unescaped junk from a CRM — stray HTML, double spaces, trailing commas.

Design so a gap is survivable

The best defence is writing templates that still read correctly when a value is generic. Compare:

Fragile: "Hi {{1}}, your {{2}} order for {{3}} arrives {{4}}." Miss the product name and the sentence collapses.

Robust: "Hi {{1}}, your order {{2}} is on its way and should arrive by {{3}}." Fewer variables, each one a field that reliably exists, and a fallback of "there" for the name still reads acceptably.

The default-value habit

Give every variable a fallback before it reaches the send: name defaults to "there", date to "shortly", amount to the numeral zero. A slightly generic message that arrives beats a personalised one that does not.

Sanitise on the way in

  1. Trim whitespace at both ends.
  2. Replace newlines and tabs with a single space.
  3. Collapse repeated spaces.
  4. Truncate to a sensible maximum, on a word boundary, with an ellipsis.
  5. Substitute the fallback if the result is empty.

Five rules, applied once at the point where data enters your messaging layer, remove nearly all send-time variable failures.

Watch out for names

Customer name fields are the messiest data most businesses hold. They contain full names in a first-name field, ALL CAPS entries, emails where a name should be, single letters, and test entries. Personalisation using them fails loudly and publicly.

If your name data has not been audited, take the first token, reject anything containing an at-sign or a digit, reject single characters, and fall back to "there". It is unglamorous and it prevents "Hi ASDF@GMAIL.COM" reaching a real customer.

Test with awkward data

Before a campaign, send to a small internal set that deliberately includes the difficult cases: an empty name, a very long product title, a name with an accent, a name in a non-Latin script, and an amount with decimals. Two minutes of that catches problems a clean test never will.

Watch the failures

Send failures are reported per message, so a campaign that is 3% broken looks entirely successful on a summary screen. Check the failure count on every campaign, and treat any recurring reason as a data problem to fix upstream rather than a message to retry.

Related guides

Try Trafficaro free