Advanced Problem
AI-assisted writing apps break when prompt logic, fallback behavior, and editing UX are tangled together. The result is inconsistent output quality and difficult incident debugging.
Step 1: Treat prompt templates as versioned assets
{
"template_id": "rewrite_v3",
"system_role": "technical-writing-coach",
"constraints": ["keep examples concrete", "avoid generic summaries"]
}
Step 2: Add provider fallback with quality gates
async function generateWithFallback(primary: () => Promise<string>, secondary: () => Promise<string>) {
try {
const out = await primary();
if (out.length < 200) throw new Error('too_short');
return out;
} catch {
return secondary();
}
}
Step 3: Keep editing state independent from generation state
Writers should be able to revise manually without corrupting provider-level diagnostics.