4 Production Bugs That Break Automated AI News Pipelines (And How to Fix Them)
Running an automated AI and financial news pipeline sounds simple on paper: fetch RSS feeds, call an LLM to summarize or analyze the story, and publish.
In production, however, LLM-powered publishing pipelines fail in subtle, embarrassing ways - truncated JSON leaking directly into live posts, empty headlines, mid-sentence cuts, and duplicate stories flooding your feed.
While scaling automated editorial workflows for AlgoChain News, we ran into all four of these failure modes. Here is the exact engineering checklist and defensive code we use to keep automated publishing clean and reliable.
1. The Silent Killer: Truncated JSON Falling Through to Plain Text
When you ask an LLM to return structured JSON (headline, summary, body_html, tags) with a tight max_tokens limit (like 800-950), multi-byte UTF-8 text or verbose reasoning can truncate the response right before the closing }.
If your parser falls back to "use raw text when json_decode() fails," your live site or social channel suddenly publishes raw JSON:
{ "decision" : "approve" , "headline" : "New open-weight model...
The Fix: Raise Token Headroom + Block JSON-Like Fallbacks
First, give structured JSON responses at least 1400-1600 max_tokens. Second, explicitly reject any plain-text fallback that looks like broken JSON:
function looksLikeRawJson(string $text): bool {
$trimmed = ltrim($text);
if (str_starts_with($trimmed, '{') || str_starts_with($trimmed, '[{')) {
return true;
}
return (bool) preg_match('/"(?:decision|headline|summary|telegram_html|body_html)"\s*:/i', $trimmed);
}
If json_decode() returns null AND looksLikeRawJson($raw) is true, abort and retry with a fallback model - never pass it downstream.
2. Run Your Quality Gate After Sanitization, Not Before
A common pipeline bug is validating length (strlen($body) >= 120) on the raw LLM response, and then running HTML sanitization and length truncation afterward.
If your sanitizer strips disallowed tags or your paragraph truncator drops an oversized first paragraph, you can end up publishing a stub post containing only a title and a link.
The Fix: Post-Sanitization Structural Validation
Always sanitize and format first, then verify that the final output still contains:
- A valid headline
- At least one real body paragraph (≥ 80-120 characters of plain text)
- Zero raw JSON or leaked
<think>...</think>reasoning tags
function passesFinalQualityGate(string $sanitizedHtml): bool {
if (looksLikeRawJson($sanitizedHtml) || str_contains($sanitizedHtml, '<think>')) {
return false;
}
$paragraphs = array_values(array_filter(array_map('trim', preg_split("/\n\n+/", $sanitizedHtml) ?: [])));
if (count($paragraphs) < 3) {
return false;
}
// Check body paragraphs (between headline and footer)
$bodyPlain = trim(strip_tags(implode("\n", array_slice($paragraphs, 1, -1))));
return mb_strlen($bodyPlain) >= 100;
}
3. Never Truncate Summaries With Blind substr()
Blind character slicing (mb_substr($text, 0, 140) . '...') cuts right through words and clauses, making automated digests look robotic and lowering reader retention.
The Fix: Sentence-Boundary & Word-Boundary Trimming
Prefer ending on a full sentence (., ?, !) when possible, and fall back to the last clean whitespace boundary:
function cleanSentenceExcerpt(string $text, int $maxLength = 165): string {
$text = trim((string) preg_replace('/\s+/u', ' ', strip_tags($text)));
if (mb_strlen($text) <= $maxLength) {
return $text;
}
$slice = mb_substr($text, 0, $maxLength);
if (preg_match('/^(.{70,}[.?!])/u', $slice, $match)) {
return trim($match[1]);
}
$lastSpace = mb_strrpos($slice, ' ');
if ($lastSpace !== false && $lastSpace >= 50) {
$slice = mb_substr($slice, 0, $lastSpace);
}
return rtrim($slice, " \t\n\r\0\x0B,;:--") . '…';
}
4. Deduplicate by Semantic Overlap, Not Just URL
RSS feeds syndicate the exact same breaking AI or crypto story under 5 different URLs within an hour. Exact-URL checks miss this completely and cause repetitive publishing.
A lightweight Jaccard token similarity check against your last 50-80 published titles catches 90%+ of duplicate stories in milliseconds with zero vector-DB overhead:
function jaccardSimilarity(array $tokensA, array $tokensB): float {
if (!$tokensA || !$tokensB) {
return 0.0;
}
$a = array_flip($tokensA);
$b = array_flip($tokensB);
$intersection = count(array_intersect_key($a, $b));
$union = count($a + $b);
return $union > 0 ? $intersection / $union : 0.0;
}
Reject any incoming candidate with a similarity score >= 0.58 against items published in the last 14-30 days.
Wrapping Up
Reliable AI content systems aren't about finding a "perfect" prompt - they're about putting deterministic engineering guardrails around probabilistic model outputs.
You can see these publishing patterns in action daily across our live AI & Tech Newsroom, or explore our free interactive developer and finance utilities at the AlgoChain Tools Hub.
What's the weirdest LLM failure mode you've caught in production? Drop it in the comments!
Comments
No comments yet. Start the discussion.