run-llama/llama_index · error · OutputParserException

Got invalid JSON object. Error: {e_json} {e_yaml}. Got JSON

Error message

Got invalid JSON object. Error: {e_json} {e_yaml}. Got JSON string: {json_string}

What it means

Error "Got invalid JSON object. Error: {e_json} {e_yaml}. Got JSON string: {json_string}" thrown in run-llama/llama_index.

Source

Thrown at llama-index-core/llama_index/core/output_parsers/utils.py:55


def parse_json_markdown(text: str) -> Any:
    if "```json" in text:
        text = text.split("```json")[1].strip().strip("```").strip()

    json_string = _marshal_llm_to_json(text)

    try:
        json_obj = json.loads(json_string)
    except json.JSONDecodeError as e_json:
        try:
            # NOTE: parsing again with pyyaml
            #       pyyaml is less strict, and allows for trailing commas
            #       right now we rely on this since guidance program generates
            #       trailing commas
            json_obj = yaml.safe_load(json_string)
        except yaml.YAMLError as e_yaml:
            raise OutputParserException(
                f"Got invalid JSON object. Error: {e_json} {e_yaml}. "
                f"Got JSON string: {json_string}"
            )
        except NameError as exc:
            raise ImportError("Please pip install PyYAML.") from exc

    return json_obj


def parse_code_markdown(text: str, only_last: bool) -> List[str]:
    # Regular expression pattern to match code within triple-backticks
    pattern = r"```(.*?)```"

    # Regular expression pattern to match code within triple backticks with
    # a Python marker. Like: ```python df.columns```
    python_str_pattern = re.compile(r"^```python", re.IGNORECASE)
    text = python_str_pattern.sub("```", text)

View on GitHub (pinned to afd0fef371)

Solutions

  1. Fix the LLM output so it is valid JSON or YAML before parsing.
  2. Use an output parser with a format prompt or repair step (e.g. parse_fenced_json) to coerce the output.

When it happens

Trigger: Thrown at llama-index-core/llama_index/core/output_parsers/utils.py:55 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/c0072a30ad083b5f. Report an issue: GitHub.