Detecting Unrendered Template Variables Before Email Dispatch
A pre-send lint gate catches unrendered variables before they reach inboxes.

To catch unrendered template variables before email dispatch, a system needs a pre-send lint gate, because message-structure validation does not prove that rendering is complete. For agentic email, the gate must check every outbound message, name unresolved variables and missing compliance fields, and block dispatch until the agent or developer fixes them. Post-send monitoring cannot provide that protection.
Why email-sending systems let raw tokens reach the inbox
Structure validation confirms that a message has a subject, a sender, and a recipient. Render-completeness validation confirms that every required token was substituted before dispatch. These are separate checks, and most pipelines perform only the first. Consequently, a well-formed API call can still send Hi {{name}} to thousands of inboxes. The failure begins at the validation boundary.
Request handlers may take any content values and store them without checking whether they are strings that can be rendered. A list or object stored as a body can therefore pass request validation but fail at render time. Even with valid strings, a mismatch between the render context and the template leaves content unresolved. In one reviewed codebase, the denial email’s context and default template used different names for the rejection reason, so the reason never appeared.
Another implementation had a template renderer with exactly one caller, the preview endpoint. The actual sender built messages from raw notification fields without reading the template row. In that architecture, previewing a correct message demonstrated nothing about the dispatch path. The preview and sender were exercising different systems.
What a delivered raw token reveals about the sending system
A delivered raw token exposes more than unfinished copy. It can reveal automated mass-mail infrastructure, place the recipient’s address in a campaign contact database, and show a security analyst where configuration or substitution failed. Internal variable names show how the sending pipeline works. That information escapes with the message itself. A later template correction cannot withdraw it from the recipient’s inbox.
IRONSCALES’ April 2026 report documented a credential-harvesting email containing raw CPL_Agreement and reference placeholders, exposing a phishing kit deployed before configuration was complete. Its subject read “[Action required] Your_Mail_Box_Is_Full”, and its single body link pointed to the placeholder URL hxxp://vm/. The message passed SPF, DKIM, and DMARC from a compromised authenticated account. Authentication did not establish that its content was complete. The same distinction applies to any sending system.
Sublime Security’s detection rule flags unfilled placeholders or recipient email addresses in HTML element class attributes. It assigns high severity to that pattern because it indicates failed personalization or recipient identifiers embedded for tracking or evasion. Broken templates also drive spam complaints, and complaint rates that cross a threshold can trigger delivery blocks that take weeks to remediate. The cost can extend beyond the failed batch.
How agentic senders make the problem harder to catch manually
An agent can generate and dispatch messages without the review pause that exists in a human-operated campaign. A developer inspecting a draft may catch {{plan}} before sending. An autonomous sender can propagate one template misconfiguration across a sending program before anyone sees the first broken message. Requiring a human to review each message would rule out unattended sending.
The API itself supplies no substitute for that review. Agents call the same send endpoint as human senders, so malformed payloads remain indistinguishable unless the system explicitly checks their content. An agent assembling context from upstream data may supply a key that differs from the template’s declared variable without knowing it. If an HTTP call times out or orchestration restarts, re-invoking the tool with the same arguments reproduces the same defect unless a gate refuses it.
Why the right fix is a pre-send lint gate, not post-send monitoring
A pre-send lint gate belongs at the point where a broken message can still be refused. Monitoring observes a message after dispatch, when complaints, bounces, or analyst findings can only describe what escaped. By then, the batch may have landed. The choice is between preventing an invalid send and learning about one afterward.
Dispatch PR #25, merged September 2026, provides a concrete implementation of that boundary. Its renderTemplate function in packages/core substitutes {{variable}} placeholders into subject, HTML, and text. When values are missing, it refuses the render and returns every missing key in a discriminated result. Missing data is caller input. Representing refusal in the result type also makes the distinction between sendable output and incomplete output explicit, so a half-rendered send should not be able to compile.
Graceful degradation is the main objection to blocking. A team may prefer a plain fallback to losing a notification, but a silent fallback can replace one unnoticed failure with another. The recipient gets a message other than the one intended, while the sender gets no request that says what to fix. For an agent, named missing keys provide a repair target that a generic render failure does not.
How do you prevent broken merge tags and missing unsubscribe links before sending?
A check that catches {{first_name}} can still miss {{ First Name }}, {First Name}, and [Name]. A check that matches only a single word inside braces also misses dotted flat keys such as {{user.name}} and filtered expressions such as {{ variable | upper }}. Single-brace formats and square-bracket placeholders such as [LINK] and [Company] cannot be covered by a double-brace-only pattern.
Field coverage is equally important because the body is not the whole message. Unresolved tokens can be in subject lines, plain-text alternatives, and HTML class attributes. Sublime Security’s rule illustrates why inspecting only visible body copy leaves a gap. A message can appear complete to a reader while its markup still exposes unresolved personalization. The lint gate must inspect those attributes as well as the displayed content.
Reporting must be complete within a single refusal. Dispatch’s renderTemplate returns every missing name rather than stopping at the first, allowing the caller to address the full set of gaps before trying again. That helps when the shape of an agent’s upstream data differs from the context the template expects. One missing key should not conceal the next. Otherwise, correction becomes a sequence of avoidable failed attempts.
Render quality also requires checking that substituted HTML values are escaped, so a company name containing & appears as & in HTML. Substitution alone does not establish safe markup. Compliance checks belong at the same gate, where a bulk campaign missing a List-Unsubscribe header, or a message missing a required unsubscribe link in the body, should be blocked with the omission named.
How variable substitution itself can introduce new failures if implemented naively
Substitution can run and still produce the wrong output. Building a substitution pattern with new RegExp from a variable key treats regex characters in keys that contain .*, [, or (a+)+ as regex instructions. JavaScript’s String.replace can also read patterns in the values it is given as replacement patterns. Both problems arise in the substitution operation, before a raw-token scan can judge the result.
UseSend PR #478 addresses these implementation failures by replacing regex-based substitution with string.split(key).join(value) to make replacement literal and linear. It also changes the double opt-in path to pass values through a function, preventing replacement-pattern expansion. These fixes distinguish names and values from executable replacement syntax. The same PR addresses a separate template-selection failure. Numeric coercion turned every cuid string ID into NaN, causing all templates in a batch to share one cache entry.
Template selection must also stay scoped to the sending team. Otherwise, one team’s template can be rendered in another team’s context, even if every token is successfully replaced. Completeness alone cannot detect that selection error.
For Jinja2, unrestricted rendering introduces another implementation risk. Saved template text rendered through jinja2.Environment() can permit executable server commands in template content. The prescribed fix is SandboxedEnvironment() and template pre-validation before storage, with autoescape=True added for HTML output. Sandboxing and escaping address different failures. Autoescaping protects HTML output against XSS, but on its own it cannot stop server-side template injection.
Where the lint gate sits in an agent’s email workflow
The agent first constructs the render context, and the template engine substitutes its variables. The lint gate then inspects the rendered output before the send API is called. It checks raw tokens, required compliance fields, and escaped HTML as a synchronous blocking step. Clean output proceeds to dispatch. A failed check returns a structured result naming each problem to the agent instead.
That return is part of the tool contract. A result naming plan as missing tells the agent which key it needs from its data source. A generic failure gives the agent no such way to fix the problem without a human’s help. This distinction applies when sending is exposed through agent tooling as well as through a direct API call. The transport does not remove the need for an actionable refusal between rendering and sending.
Retries require their own boundary discipline. An idempotency key prevents duplicate sends after a network retry, but it does not prove that a payload is render-complete. The lint gate must check each new payload, even if an earlier call passed the check. Domain authentication serves another separate purpose. SPF, DKIM, and DMARC must be configured correctly on the sending domain, because lint-clean content from an unauthenticated domain can still fail inbox placement.
AgentSend’s guardrails layer occupies this pre-dispatch position, intercepting every outbound message to inspect malformed or non-compliant content. It returns a machine-readable error with a specific fix for agents operating without human review.
Testing the lint gate so it catches what it claims to catch
The test must start with fixture data that has been left incomplete on purpose. A render context missing user.name, or containing a null order_id, must produce a structured refusal naming that key. Output such as “Dear undefined” is a failure, even if the send endpoint accepts it. The test must establish that dispatch was blocked. Otherwise, it verifies error reporting without verifying the guardrail.
A fixture containing {{name}}, {{ Name }}, {name}, and [Name] in both subject and body should cause all four forms to be caught. Detecting only the first leaves the implementation undertested. The tests must cover plain text and HTML attributes in the same way.
Passing assertions must cover the sender, recipient, subject, HTML body, plain-text body, every dynamic variable, every link, and required compliance headers. A 200 response proves only that a request succeeded. It does not prove that the recipient received complete content or that required fields survived rendering. Negative fixtures must therefore assert refusal, while complete fixtures must assert the intended rendered message.
Dispatch’s PR provides the concrete standard for the refusal path. Its discriminated result refuses incomplete rendering and identifies every missing key. A test built around that contract must assert the full set of missing names and reject the incomplete output as sendable content. “Email was sent” is not the success criterion.


