Turn SMS cost rules into a release gate.
Run deterministic checks after rendering and before delivery. Warn, require approval or stop the send when the encoded result violates your policy.
Place the check at the right point
- Render the final message with production variables.
- Analyze encoding, Unicode findings and segments.
- Apply your own thresholds.
- Show a human-readable reason when review is required.
- Create the delivery request only after the policy passes.
A minimal JavaScript gate
const result = await textpreflight.analyze({
text: renderedMessage,
recipients,
unitPrice,
currency: "USD"
});
if (result.data.segments.count > 2) {
throw new Error("SMS requires cost review");
}
if (result.data.unicode.riskLevel === "high") {
throw new Error("SMS contains a high-risk Unicode finding");
}
Prefer policy over silent rewriting
Typography-only replacements can reduce cost, but automatic rewriting is not appropriate for every language or message. Keep optimization inspectable. Store the policy decision and request identifier—not the private message body—when you need an audit trail.
Useful policy examples
- Require review when encoding changes from the expected alphabet.
- Reject more than two segments for transactional alerts.
- Require approval above a campaign cost threshold.
- Block bidirectional controls in destinations and account notices.
- Warn when a template's worst case exceeds its typical case.
Keep delivery providers replaceable.
A preflight gate that runs before delivery keeps cost and safety rules separate from a particular provider integration.
Protect the next send.
Turn the fields that matter to your product into explicit rules.