{"record":{"id":"c0072a30ad083b5f","repo":"run-llama/llama_index","slug":"got-invalid-json-object-error-e-json-e-yaml-c0072a","errorCode":null,"errorMessage":"Got invalid JSON object. Error: {e_json} {e_yaml}. Got JSON string: {json_string}","messagePattern":"Got invalid JSON object\\. Error: (.+?) (.+?)\\. Got JSON string: (.+?)","errorType":"exception","errorClass":"OutputParserException","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/output_parsers/utils.py","lineNumber":55,"sourceCode":"\n\ndef parse_json_markdown(text: str) -> Any:\n    if \"```json\" in text:\n        text = text.split(\"```json\")[1].strip().strip(\"```\").strip()\n\n    json_string = _marshal_llm_to_json(text)\n\n    try:\n        json_obj = json.loads(json_string)\n    except json.JSONDecodeError as e_json:\n        try:\n            # NOTE: parsing again with pyyaml\n            #       pyyaml is less strict, and allows for trailing commas\n            #       right now we rely on this since guidance program generates\n            #       trailing commas\n            json_obj = yaml.safe_load(json_string)\n        except yaml.YAMLError as e_yaml:\n            raise OutputParserException(\n                f\"Got invalid JSON object. Error: {e_json} {e_yaml}. \"\n                f\"Got JSON string: {json_string}\"\n            )\n        except NameError as exc:\n            raise ImportError(\"Please pip install PyYAML.\") from exc\n\n    return json_obj\n\n\ndef parse_code_markdown(text: str, only_last: bool) -> List[str]:\n    # Regular expression pattern to match code within triple-backticks\n    pattern = r\"```(.*?)```\"\n\n    # Regular expression pattern to match code within triple backticks with\n    # a Python marker. Like: ```python df.columns```\n    python_str_pattern = re.compile(r\"^```python\", re.IGNORECASE)\n    text = python_str_pattern.sub(\"```\", text)\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/output_parsers/utils.py#L37-L73","documentation":"Error \"Got invalid JSON object. Error: {e_json} {e_yaml}. Got JSON string: {json_string}\" thrown in run-llama/llama_index.","triggerScenarios":"Thrown at llama-index-core/llama_index/core/output_parsers/utils.py:55 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the LLM output so it is valid JSON or YAML before parsing.","Use an output parser with a format prompt or repair step (e.g. parse_fenced_json) to coerce the output."],"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"}