Sub topic 4
Fallback values for missing data
This chapter assumes you can insert a merge tag that maps to a contact field, and that you know what a contact, a list, and a field are. Liquid-style syntax is used throughout. Tag names and filter names differ between platforms, so check your platform's documentation before copying anything.
Why fallbacks exist
A merge tag copies a value from a contact record into the email. If the record has no value, the tag renders as an empty string. Most contact lists have gaps. People sign up with only an email address, import files skip columns, and integrations fail to sync a field.
Without a fallback, an empty first name produces this:
Hi {{ customer.first_name }},The subscriber receives "Hi ,". That looks broken, and it shows that the sender did not check the template. A fallback value (also called a default value) is the text the platform uses when the field is empty or missing.
Some platforms behave worse than an empty string. They may print the raw tag, such as {{ customer.first_name }}, or *|FNAME|* in Mailchimp-style syntax. Others skip the send for that contact. Learn which behavior your platform uses before you build anything.
Writing a fallback in Liquid
Liquid-style platforms use the default filter. A filter is a modifier that follows a pipe character and changes the value on its left.
Hi {{ customer.first_name | default: "there" }},
Thanks for being with us.If first_name has a value, such as "Priya", the output is "Hi Priya,". If it is empty or missing, the output is "Hi there,". The text after default: is the fallback.
Other platforms use different forms:
| Platform style | Example syntax | Column | Column |
|---|---|---|---|
| Liquid (Shopify, Klaviyo, Braze, Brevo, and others) | `{{ first_name \ | default: "there" }}` | |
| Mailchimp merge tags | `*\ | FNAME\ | *` with a default set in the field settings |
| Handlebars-style (SendGrid) | `{{#if first_name}}{{first_name}}{{else}}there{{/if}}` | ||
| Jinja2 | `{{ first_name \ | default("there", true) }}` |
When a platform has no filter, you can get the same result with conditional logic, which a later chapter covers.
What counts as missing
"Missing" has more than one meaning, and platforms handle each case differently.
- Field absent: The contact record has no such field. Many Liquid engines treat this as nil (no value) and apply the default.
- Field empty: The field exists but holds an empty string. Liquid's
defaultreplaces this. - Whitespace only: A value such as
" "is not empty. Mostdefaultfilters leave it alone, and the email reads "Hi ,". Trim whitespace when you import data. - Placeholder values: Values such as "N/A", "unknown", "test", or "." are real text. No fallback fires, and the subscriber sees "Hi N/A,". The data-quality chapter covers cleaning these.
- False and zero: In Liquid,
falsetriggers the default unless you passallow_false: true. Jinja2 behaves differently again, as the next section shows.
Seeing the behavior in Jinja2
You can test fallback logic outside your email platform. Python's Jinja2 library has similar syntax. The example below also shows a testing technique: StrictUndefined makes a missing field raise an error instead of silently rendering a blank.
from jinja2 import Environment, StrictUndefined
env = Environment(undefined=StrictUndefined)
template = env.from_string("Hi {{ first_name | default('there', true) }}, your plan is {{ plan }}.")
print(template.render(first_name="", plan="Pro"))
try:
template.render(first_name="Sam")
except Exception as error:
print(type(error).__name__)This prints:
Hi there, your plan is Pro.
UndefinedErrorTwo details matter here:
- In Jinja2,
default('there', true)treats any falsy value, including an empty string, as missing. Without the second argumenttrue, only a truly undefined variable triggers the default, and an empty string would pass through. - The second render fails because
planhas no fallback and was not supplied. In a real send, that failure would be a blank space or a skipped message. Failing loudly during testing is the point.
Choosing good fallback text
A fallback must read naturally in the sentence around it, and it must work with every other merge tag nearby. Some patterns:
- Greeting: "Hi there," or "Hello," works for a first name. Avoid "Hi Customer," because it reads like a form letter.
- Standalone phrase: "Hi {{ firstname | default: "there" }}" stands alone. A sentence like "Your {{ productname }} is ready" needs a fallback such as "order", so it becomes "Your order is ready".
- Grammar around the tag: A fallback that changes the sentence structure can break the text that follows. "Welcome back, {{ firstname | default: "valued customer" }}!" works. "{{ firstname | default: "" }}, welcome back!" leaves a stray comma when the name is missing.
- Numbers and dates: Do not invent a fallback for a figure such as a balance or a delivery date. A wrong number is worse than a blank. Use a conditional block to hide the whole sentence when the value is missing.
- Links: A URL field with a bad fallback sends people to a broken page. Use a safe link, such as your site's homepage.
Fallbacks versus conditional content
A fallback replaces one value. A conditional block changes a whole stretch of content. Use the simplest tool that fits:
| Situation | Better tool |
|---|---|
| A first name may be empty | Fallback |
| A sentence only makes sense if a value exists | Conditional block |
| Two fields combine, such as city and country | Conditional block, so you avoid a dangling comma |
| A value has a safe generic substitute | Fallback |
For example, a loyalty-points line should disappear when the balance is unknown:
{% if customer.points %}
You have {{ customer.points }} points.
{% endif %}A fallback such as "0 points" would be false information for a customer who simply has no synced data.
Fallbacks in subject lines and preheaders
Subject lines are the highest-risk place for a missing value. The subscriber sees them before opening, and some platforms cannot show a preview of the failure. "{{ first_name }}, your offer ends soon" becomes ", your offer ends soon". Write the subject line so it works without the name, then add the tag with a fallback. A later chapter on subject lines covers this in detail.
Common errors
- Fallback on only some tags: You add
defaultto the greeting but forget the same field in the footer or a button label. Search the full template for every use of each field. - Wrong quote style: Some engines require double quotes around fallback text. A curly apostrophe pasted from a document can also break parsing. Paste code as plain text.
- Assuming one platform's behavior on another: After migrating platforms, the same template may treat empty strings differently. Re-test.
- Fallback masks bad data: If 40% of your contacts show the fallback, the real problem is your data, not your template. Track how often the fallback fires.
- Capitalization: "there" is correct mid-sentence, but "Dear {{ first_name | default: "there" }}" gives "Dear there". Rewrite the greeting if your fallback does not fit the opening word.
Summary of the working model
- A merge tag copies a field value into the email. If the field has no usable value, the result is blank, raw tag text, or a skipped send, depending on the platform.
- A fallback supplies replacement text for missing values. The
defaultfilter is the common Liquid form. - "Missing" differs by engine. Check how yours treats empty strings, whitespace, false, and zero.
- Choose fallback text that fits the sentence, and use a conditional block when no sensible substitute exists.
- Strict rendering in testing exposes missing fields that a fallback would otherwise hide.
Exercise
A template contains Hi {{ customer.first_name | default: "there" }},. A contact's first name was imported as a single space. What does the subscriber most likely see, and how would you prevent it?
Show answer
Most Liquid default filters only replace nil or empty strings, so a single space counts as a real value. The subscriber sees "Hi ," with a blank where the name should be. Prevent it by trimming whitespace on import, or by cleaning the field in the contact database. Some platforms also offer a strip filter, for example {{ customer.first_name | strip | default: "there" }}, which removes the space before the default check runs.
Exercise
You write Your balance is {{ customer.balance | default: "0" }}. Why can this be a bad choice, and what is a safer alternative?
Show answer
A missing balance usually means the data did not sync, not that the balance is zero. The email would state a false figure. A safer approach is a conditional block, such as {% if customer.balance %}Your balance is {{ customer.balance }}.{% endif %}, so the sentence is omitted when the value is unknown.