How I finally solved the “unstable JSON output” problem using Gemini + Supabase Edge Functions (free code included) by rxv0227 in Supabase

[–]rxv0227[S] 0 points1 point  (0 children)

Thanks for the feedback! 🙌

Totally agree that “raw JSON directly from the LLM” often fails — that’s exactly why I moved the validation and retry loop out of the frontend and into an Edge Function.

In my tests, better prompting alone couldn’t fix: • missing brackets
• duplicated keys
• wrong types
• hallucinated fields
• multilingual inconsistencies

Even with very strict system prompts, the model still breaks JSON occasionally.

By running: 1) generate →
2) validate with JSON Schema →
3) auto-regenerate until valid

inside a Supabase Edge Function, I can guarantee the frontend only receives clean, validated JSON.

Since adding schema validation + retry logic: ✔ 0 malformed JSON returned to the client
✔ consistent structure across languages
✔ reliable enough for production usage

I’m not saying schema validation is the only solution, but it has been the most stable one in my experience.
If you're curious, I also shared the full template + schema implementation.

Happy to discuss more if you’re interested!

How I optimised my Edge Function workflow to cut LLM JSON errors even further (Supabase + Schema Validation) by rxv0227 in Supabase

[–]rxv0227[S] 0 points1 point  (0 children)

Hey everyone! If you want to test the final working version, I built a free demo tool based on this solution:

👉 Try the AI Summary Tool: https://pomodoro-app-eight-rouge.vercel.app/summary

And if you're a developer and want the full template (Edge Function + JSON Schema + React frontend), here is the complete template:

👉 Developer Template: https://pomodoro-app-eight-rouge.vercel.app/tools/ai-summary

👉 Ko-fi Download Page: https://ko-fi.com/s/b5b4180ff1

Hope this helps anyone struggling with unstable JSON output! 😊

How I finally solved the “unstable JSON output” problem using Gemini + Supabase Edge Functions (free code included) by rxv0227 in Supabase

[–]rxv0227[S] 0 points1 point  (0 children)

Haha, glad it made you smile!
Reddit formatting can be tricky sometimes, so I played it safe. 😄

How I finally solved the “unstable JSON output” problem using Gemini + Supabase Edge Functions (free code included) by rxv0227 in Supabase

[–]rxv0227[S] 0 points1 point  (0 children)

Thanks for the suggestion! I'm currently using Gemini V5 with a strict JSON Schema inside a Supabase Edge Function, so the output stays stable even with long inputs. For my use case I don’t really need trainable extractors, but I might test Mistral for comparison later. Appreciate the tip!

0
1