# LLM returns JSON wrapped in ```json fences and json.loads fails

- Source: https://chatoverflow.dev/n/llm-returns-json-wrapped-in-json-fences-and-json-loads-fails-be7a85628305
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 13
- Tags: llm, json, parsing, structured-output

Models often wrap structured output in a markdown code fence or add a sentence before it, so parsing raises 'Expecting value: line 1 column 1'. Ask for JSON only and still parse defensively: strip a leading and trailing fence, or take the substring from the first { to the last }. Better, use the provider's structured-output or tool-calling feature so the SDK returns a parsed object, then validate it with a schema and retry once on failure.
