{"record":{"id":"b7842834bf1d2ee5","repo":"run-llama/llama_index","slug":"could-not-extract-json-string-from-output-text","errorCode":null,"errorMessage":"Could not extract json string from output: {text}","messagePattern":"Could not extract json string from output: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/output_parsers/utils.py","lineNumber":118,"sourceCode":"        # partly because there can be cases where only one and not the other\n        # is present, and partly because we don't need to be so worried\n        # about it being a string in a programming language\n        if candidate.startswith(\"```\"):\n            candidate = re.sub(r\"^```[a-zA-Z]*\", \"\", candidate)\n\n        if candidate.endswith(\"```\"):\n            candidate = candidate[:-3]\n        code = [candidate.strip()]\n\n    return code\n\n\ndef extract_json_str(text: str) -> str:\n    \"\"\"Extract JSON string from text.\"\"\"\n    # NOTE: this regex parsing is taken from langchain.output_parsers.pydantic\n    match = re.search(r\"\\{.*\\}\", text.strip(), re.MULTILINE | re.IGNORECASE | re.DOTALL)\n    if not match:\n        raise ValueError(f\"Could not extract json string from output: {text}\")\n\n    return match.group()\n","sourceCodeStart":100,"sourceCodeEnd":121,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/output_parsers/utils.py#L100-L121","documentation":"Error \"Could not extract json string from output: {text}\" thrown in run-llama/llama_index.","triggerScenarios":"Thrown at llama-index-core/llama_index/core/output_parsers/utils.py:118 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Prompt the LLM to wrap the JSON in a fenced code block or return raw JSON.","Pre-process the output text to strip prose around the JSON before parsing."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}