Defending Against LLM Output: Parsing Dirty JSON in C#
Post 3 in my series on an automation hub for a ticket-resale business. If you've ever put an LLM into a production pipeline, you know the feeling: the prompt clearly says "return ONLY valid JSON," and the model responds with... a friendly greeting, a markdown code fence, and then the JSON — occasionally missing a bracket. This post collects the techniques I use to parse LLM output safely in C#. The problem: an LLM is an "API" with no schema guarantee In my email-classification pipeline (see post 2), the model must return a list of objects like: { "uid": "452455", "subject": "Presale starts Friday!", "performer": "...", "venue": "...", "event_date": "Oct 10, 2026", "label": "PRESALES", "confidence": 0.92 } In practice the model returns every possible variation: uid is sometimes a string and sometimes a number, label i...