{
  "id": 23278947,
  "title": "How to Automatically Repair Invalid LLM Responses",
  "url": "https://urgent.news/2026/12/03/how-to-automatically-repair-invalid-llm-responses",
  "topic": "ai",
  "section": "AI",
  "published": "2026-12-03T13:10:20.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/robertbobrowski/how-to-automatically-repair-invalid-llm-responses-4nn6"
  },
  "original_language": null,
  "account": "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.\n\nThe 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.\n\nRepair 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.\n\nEach 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.",
  "summary": "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…",
  "summary_source": "publisher",
  "key_points": [
    "Invalid LLM responses repaired automatically in ValGuard",
    "Repair occurs after upstream call, before validators run",
    "Three-tier repair system fixes syntax, schema, and field issues"
  ],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "outlets_capped": false,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}