{"record":{"id":"18f64228fb0156cc","repo":"unclecode/crawl4ai","slug":"llm-did-not-return-valid-json-raw","errorCode":null,"errorMessage":"LLM did not return valid JSON: {raw}","messagePattern":"LLM did not return valid JSON: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crawl4ai/extraction_strategy.py","lineNumber":2818,"sourceCode":"        # ── LLM call (with retry/backoff)\n        resp = perform_completion_with_backoff(\n            provider=llm_config.provider,\n            prompt_with_variables=\"\\n\\n\".join([system_msg, user_msg]),\n            json_response=True,\n            api_token=llm_config.api_token,\n            base_url=llm_config.base_url,\n            extra_args=kwargs,\n        )\n\n        # ── clean & load JSON (fix common escape mistakes *before* json.loads)\n        raw = resp.choices[0].message.content\n        raw = raw.replace(\"\\x08\", \"\\\\b\")                     # stray back-space → \\b\n        raw = re.sub(r'(?<!\\\\)\\\\(?![\\\\u\"])', r\"\\\\\\\\\", raw)   # lone \\ → \\\\\n\n        try:\n            pattern_dict = json.loads(raw)\n        except Exception as exc:\n            raise ValueError(f\"LLM did not return valid JSON: {raw}\") from exc\n\n        # quick sanity-compile\n        for lbl, pat in pattern_dict.items():\n            try:\n                re.compile(pat)\n            except re.error as e:\n                raise ValueError(f\"Invalid regex for '{lbl}': {e}\") from None\n\n        return pattern_dict\n","sourceCodeStart":2800,"sourceCodeEnd":2828,"githubUrl":"https://github.com/unclecode/crawl4ai/blob/7e801521428ee12509994d39151006f64055ebe3/crawl4ai/extraction_strategy.py#L2800-L2828","documentation":"Error \"LLM did not return valid JSON: {raw}\" thrown in unclecode/crawl4ai.","triggerScenarios":"Thrown at crawl4ai/extraction_strategy.py:2818 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the LLM prompt requests strict JSON output and set response_format to JSON where supported.","Validate and strip markdown fences from the raw response before parsing, or retry with a clearer instruction."],"exampleFix":"config = LLMConfig(provider=\"openai/gpt-4o\"); strategy = LLMExtractionStrategy(llm_config=config, instruction=\"Return only valid JSON\")","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7e801521428ee12509994d39151006f64055ebe3","analyzedAt":"2026-08-14T20:46:20.673Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}