Built a self-healing social content generator (handles broken AI output + any language)

Hey everyone :waving_hand:

I kept running into the same problem with AI content workflows: the model returns malformed JSON, the workflow crashes, and the whole automation silently dies. So I built one that repairs itself.

What it does:
→ Send a topic (in ANY language) via Telegram, Manual, or Schedule
→ Generates ready-to-post content for X, LinkedIn & Instagram
→ If the AI returns broken JSON, it auto-retries with a stricter prompt and repairs the output — your run never dies
→ You review each piece in Telegram (Approve / Reject buttons)
→ Everything logs to Google Sheets, sorted into Approved / Rejected / Failed tabs

A few things I’m happy with:

  • The self-healing parser — catches the markdown-wrapped JSON that Gemini loves to return
  • Language is auto-detected from your topic — write in Spanish, get Spanish content. No translation step, no extra tokens.
  • Three topic modes: random (no repeats), sequential, or your own custom topic

Built it with Gemini (cheap to run) + Telegram + Google Sheets. Took a lot of trial and error to make the JSON handling bulletproof.

Happy to answer any questions about how the self-healing part works — that was the trickiest bit.

I packaged the whole thing (workflow + setup guide + sheet template) here if it’s useful to anyone: Social Content Engine PRO — AI Social Media Content Generator (n8n Workflow)

2 Likes

Welcome @Mehmetcan_Bolukbas!

The auto-retry on malformed JSON is exactly the right pattern - the markdown-wrapped JSON from Gemini trips up a lot of content workflows. One thing you could layer on top of the self-healing parser is enabling the “Structured Output” option in the Gemini node (if your model supports it), which enforces valid JSON at the API level before n8n even receives the response - that should cut down the retry rate and reduce token spend on the repair calls.

Thanks, really appreciate the welcome and the tip! Enabling Structured Output on the Gemini node is a great call – I’II add that as the primary layer to enforce valid JSON up front. I’II keep the self-healing parser underneath as a model-agnostic fallback, so the workflow stays robust if someone swaps in a model that doesn’t support structured output ( or a lighter Gemini variant that still slips occasionally ) . Best of both worlds :folded_hands:

Quick update — added a short demo (under a minute) so the flow is easier to picture:

You can see it end to end: topic in → AI writes the post → malformed output gets repaired automatically → approve in Telegram → logged to Sheets.

And to the point above about Structured Output — totally agree, using Gemini’s responseMimeType as the first line of defense makes it even cleaner. I see it as complementary: Structured Output to prevent bad output, the self-healing parser as a model-agnostic fallback for when the feature isn’t available or the model slips. Best of both.

Happy to dig into any part of the setup!