Why LLMs Still Write Needy Copy & Leak Paid Tiers — 3 Deterministic TypeScript Guardrails We Shipped
How we stopped an LLM from writing needy relationship copy, fixed subordinate-clause regex stripping, and isolated single-unlock vs pass tiers in Next.js.
When you ship an AI consumer product with paid tiers, the hardest bugs to eliminate are not crashes—they are subtle output regressions that quietly erode user trust right before checkout.
While expanding our interactive tarot web app with dedicated relationship flows—including our Ace of Cups as feelings, The Devil as feelings, and is he cheating tarot pages—we ran a 14-scenario live audit across free readings, single-reading unlocks, and 30-day passes. That pass uncovered three recurring engineering problems that prompt edits alone could not reliably solve:
- The model kept generating overly needy message scripts even when told to stay calm.
- Our mid-sentence refusal stripper left broken subordinate clauses (
"If you're wondering...") dangling in Sentence 1. - Our paywall copy accidentally leaked relationship-specific perks onto career and general readings.
Here are the three deterministic TypeScript guardrails we shipped in Next.js to close every one of those gaps.
1. Why Prompting "Match Their Emotional Temperature" Fails Without a Validator
One of our highest-value paid sections gives users a grounded, low-pressure message draft when they are deciding whether to text someone during silence or uncertainty.
Even with detailed prompt instructions asking the model to match the other person's emotional temperature, fast models reliably fell back to relationship-blog clichés inside quoted drafts:
- "I've been thinking about you lately..."
- "Had a really good time with you, just checking in..."
- "I miss feeling close to you..."
When someone hasn't heard back in two weeks, opening with "I've been thinking about you" feels needy and immediately breaks the credibility of the advice.
The Fix: Deterministic Quoted-Script Validation + Targeted Retry
Instead of piling more adjectives into the system prompt, we built a lightweight deterministic validator that inspects only quoted message strings inside the generated section and flags high-frequency needy clichés before the response reaches the client:
const QUOTED_SCRIPT_RE = /["“]([^"”]{10,220})["”]/g;
const NEEDY_SCRIPT_CLICHE_RE =
/\b(i['’]ve\s+been\s+thinking\s+about\s+you|thinking\s+of\s+you\s+lately|how\s+things\s+ended|had\s+a\s+really\s+good\s+time\s+with\s+you|i\s+miss\s+feeling\s+close\s+to\s+you)\b/i;
export function hasNeedyScriptCliche(text: string): boolean {
for (const match of text.matchAll(QUOTED_SCRIPT_RE)) {
const quoted = match[1] ?? '';
if (NEEDY_SCRIPT_CLICHE_RE.test(quoted)) {
return true;
}
}
return false;
}
Scoping the regex strictly to quoted dialogue matters: the narrator is still allowed to discuss "how things ended" in analytical prose, while the copy-pasteable text message itself is guaranteed to stay grounded and low-pressure. When hasNeedyScriptCliche triggers, our server runs a single focused repair pass with the exact offending phrase rejected.
2. The Subordinate-Clause Bug in Refusal Lead-In Stripping
Sometimes an LLM answers a deep follow-up question by starting Sentence 1 with a robotic meta-disclaimer:
"The cards can't reveal his exact private thoughts, what they show is a pull toward caution."
Or even trickier, a refusal embedded after a conditional clause:
"If you're wondering what happens next, tarot can't predict exact dates — what the cards point to is a shift once the current tension settles."
Our first deterministic sanitizer tried to slice off the disclaimer prefix and keep the insight after "what they show is". On plain sentences, that worked cleanly. On the second example, however, stripping from the middle of Sentence 1 left a broken sentence fragment behind:
"If you're wondering what happens next, a shift once the current tension settles."
The Fix: Guard Against Orphaned Subordinate Clauses Before Slicing
Before stripping a mid-sentence refusal lead-in, we check whether the surviving prefix starts with a subordinate conjunction (If, When, While, Because, Although, Since, Unless). If it does, we discard the incomplete leading clause cleanly and promote the complete main insight to Sentence 1:
const SUBORDINATE_CLAUSE_START_RE =
/^(?:if|when|while|because|although|though|since|unless|once|whether)\b/i;
export function stripColdWaterLeadIn(text: string): string {
const refusalIdx = text.search(
/\b(?:the\s+cards?\s+can(?:not|'t)|tarot\s+can(?:not|'t)|i\s+can(?:not|'t)\s+(?:read|see\s+inside|predict))\b/i
);
if (refusalIdx === -1 || refusalIdx > 180) return text;
const prefix = text.slice(0, refusalIdx).trim().replace(/[,;:\-—]+$/, '').trim();
const pivotMatch = text
.slice(refusalIdx)
.match(/\b(?:what\s+(?:they|the\s+cards?)\s+(?:do\s+|actually\s+)?(?:show|point\s+to|reveal)\s+is|instead[,\s]+|here[,\s]+)\s*/i);
if (!pivotMatch || pivotMatch.index === undefined) return text;
const remainder = text.slice(refusalIdx + pivotMatch.index + pivotMatch[0].length).trim();
if (!remainder) return text;
const capitalized = remainder.charAt(0).toUpperCase() + remainder.slice(1);
// Drop orphaned leading subordinate clauses instead of producing broken grammar
if (!prefix || SUBORDINATE_CLAUSE_START_RE.test(prefix)) {
return capitalized;
}
return `${prefix}. ${capitalized}`;
}
Our adversarial test suite caught this exact edge case during pre-merge review—turning a silent grammatical break into a crisp, direct opening sentence every time.
3. Enforcing Tier Quotas & Intent-Isolated Checkout Copy Server-Side
As our product grew from a single reading unlock ($4.99) to a 30-day unlimited pass ($12.99), we ran into two classic SaaS architecture mistakes:
- Blurred quota boundaries: Single-reading unlocks initially shared the same generous follow-up quota as the 30-day pass, leaving users with no concrete reason to upgrade even after asking 10+ follow-ups.
- Cross-intent benefit leaks: Checkout bullets written for relationship users ("decode their mixed texts & draft your next reply") accidentally surfaced on career and general guidance checkout cards.
The Fix: Explicit Tier Resolution + Pure Intent Benefit Map
We separated tier entitlement resolution on the backend so quota enforcement never relies on client flags:
export type UnlockTier = 'free' | 'single' | 'pass';
export const SINGLE_UNLOCK_FOLLOW_UPS = 5;
export const PASS_UNLOCK_FOLLOW_UPS = 100;
export function resolveFollowUpCap(tier: UnlockTier): number {
if (tier === 'pass') return PASS_UNLOCK_FOLLOW_UPS;
if (tier === 'single') return SINGLE_UNLOCK_FOLLOW_UPS;
return 0;
}
And on the checkout UI side, every paywall surface reads from a single pure intent map (getIntentCheckoutPack(intent)) with strict domain boundaries:
export type ReadingIntent =
| 'ex_reconciliation'
| 'cheating_trust'
| 'ambiguous_crush'
| 'feelings_clarity'
| 'career'
| 'soulmate'
| 'general';
const LOVE_TEXT_DECODE_INTENTS = new Set<ReadingIntent>([
'ex_reconciliation',
'cheating_trust',
'ambiguous_crush',
'feelings_clarity',
]);
export function supportsLoveTextDecoding(intent: ReadingIntent): boolean {
return LOVE_TEXT_DECODE_INTENTS.has(intent);
}
Both the $4.99 card and the $12.99 upgrade card check supportsLoveTextDecoding(intent) before rendering text-decoding perks. A career or general user sees career/decision clarity perks—never a stray bullet about decoding an ex's mixed messages.
Key Takeaway
Prompts are great for nuance, empathy, and creative synthesis. They are terrible for hard invariants—whether that invariant is "never put needy clichés inside a suggested text message", "never leave a broken If... clause after stripping a refusal", or "never promise love-text decoding on a career checkout card". Moving those invariants into tiny, unit-tested TypeScript functions gave us predictable production behavior without slowing down the reading flow.
Frequently Asked Questions
Why validate quoted text separately instead of running a regex over the full LLM output?
Analytical prose often needs to reference phrases like "how things ended" or "thinking about you" to describe a user's situation accurately. Scoping the cliché filter strictly to quoted speech blocks needy message drafts without causing false positives in the rest of the reading.
Why handle refusal stripping in code if the prompt already forbids meta-disclaimers?
Smaller, lower-latency models still emit occasional refusal lead-ins under edge-case follow-up phrasing. A deterministic post-processor acts as a fail-closed safety net so users never see cold robotic disclaimers—even on the 3% of responses where the prompt slips.
How should multi-tier AI quotas be enforced in Next.js?
Always derive the active entitlement tier (free, single, or pass) from verified server-side order/pass records in the API route before invoking the LLM, and return structured cap metadata so the UI can cleanly transition from the single-unlock limit to an upgrade card.
Sumber artikel open-source oleh Felix M di DEV Community — Baca artikel asli. Topik:
#ai#llm#typescript#nextjs

Komentar