Urgent.News

What's breaking now, across hundreds of outlets.

AI

How to Automatically Repair Invalid LLM Responses

Picture an on-call thread, an illustrative scenario, that opens with "the model got worse." Pass rate on the invoice agent is flat, latency is flat, and the provider has shipped nothing. What has climbed is the re-ask count, and finance spots the token bill first. Nothing is wrong with the answers. The model is drifting on format: JSON wrapped in a markdown fence, a trailing comma, a number…

Invalid LLM responses can be automatically repaired using deterministic steps. In ValGuard, response repair is applied after the upstream call returns and before validators run, without a network call. This repair occurs in code, before validation, and fixes shape rather than meaning.

The repair rules are grouped into three tiers: Tier 1 (syntax), Tier 2 (schema-aware), and Tier 3 (field-scoped). Tier 1 fixes whitespace, extracts JSON from a markdown fence, normalizes quotes, and handles trailing and leading commas. Tier 2 casts numeric and boolean strings, normalizes enum casing, and fills defaults. Tier 3 clamps numeric ranges and generates deterministic UUIDv5 values for empty ID fields. Tier 2 and 3 only run if the output parses as JSON after Tier 1.

Repair never edits fields that still cannot be parsed. Tier 2 reads the agent's JSON Schema rule and validator hints, while Tier 3 is only used for named fields. Repair does not invent defaults or change values that must block violations. It also does not touch policy rules such as PII detection or forbidden phrases.

Each fix produces a log event with rule IDs, field paths, and before/after snippets. Response headers indicate if repair ran or made the request pass. The OpenAI-compatible response body remains unchanged except for the repaired shape.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

More from Dev.to on urgent.news

Report a problem with this story

Get the day's news by email. Daily, weekly or monthly. Sign up

More in AI

Teachers are the overlooked AI investment

New York City and Florida both recently set new expectations for artificial intelligence in schools. The common ground between the two is striking. Both keep teachers at the center of learning. Both expect students to keep thinking. Both ask whether technology improves learning.

More from Thursday, 3 December 2026 →