run-llama/llama_index · error · ImportError
Please pip install PyYAML.
Error message
Please pip install PyYAML.
What it means
Error "Please pip install PyYAML." thrown in run-llama/llama_index.
Source
Thrown at llama-index-core/llama_index/core/output_parsers/utils.py:60
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)
# Find all matches of the pattern in the text
matches = re.findall(pattern, text, re.DOTALL)
# Return the last matched group if requested
code = matches[-1] if matches and only_last else matchesView on GitHub (pinned to afd0fef371)
Solutions
- Install PyYAML: `pip install PyYAML`.
When it happens
Trigger: Thrown at llama-index-core/llama_index/core/output_parsers/utils.py:60 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/f6c8bd86a2272935.
Report an issue: GitHub.