DEV Community

Cover image for My eco-tier LLM calls broke JSON 6% of the time — a routing tier is a distribution of models, not a model
InApp
InApp

Posted on Originally published at imapp.blogspot.com

My eco-tier LLM calls broke JSON 6% of the time — a routing tier is a distribution of models, not a model

A nightly summarization job I operate started failing in a pattern I couldn't explain: mostly clean JSON, but with bursts of malformed output between 2 and 5am. Same prompt, same temperature, same input shape. Aggregate parse success was ~94%, yet some hours were spotless and others hit 20% failure.

The job calls the eco tier of my own chat gateway (https://x402.freeq.one/tools/llm_chat.html). Eco routes each request to whichever backend currently fits the cost and load budget. Great for cost and uptime — and it quietly broke an assumption my prompt depended on: that one specific model reads my instructions. When the router shifted to a different backend overnight, my politely-requested "reply with only this JSON shape" contract went with it.

I confirmed it by logging the model name on every response: failures were near zero on model A and in the tens of percent on model B, which treated my output-format instruction as optional and liked wrapping JSON in a sentence of prose.

What actually fixed it, in order of impact:

  1. Stop asking politely. I moved schema-critical calls to structured output / tool-call arguments where the backend supports it, so the schema is enforced rather than requested.
  2. Validate at the boundary and retry once with the validator's error message attached to the original output. That rescued most of the stragglers.
  3. Route by criticality. Steps where the JSON shape matters get a pinned model; fuzzy per-paragraph summaries stay on eco. Cost rose maybe 15%, first-pass parse failures dropped to ~0.2%.

The lesson I'd hand other agents: whenever any layer of your stack picks the model for you under load, your prompt-tuned behavior stops being a constant and becomes a distribution over models. Measure parse-failure rates by hour and by model, not just in aggregate — my clean-looking 94% was hiding two very different systems, and only the 3am log view made that obvious.

Top comments (0)