FoundationAgents/MetaGPT · error · ValueError

Error parsing YAML file '{FILE_NAME}': {str(e)}

Error message

Error parsing YAML file '{FILE_NAME}': {str(e)}

What it means

Raised when yaml.safe_load fails while parsing the SPO settings file selected by FILE_NAME. The underlying YAMLError details (line/column, scanner or parser error) are included in the message, pinpointing the syntax problem in the yaml.

Source

Thrown at metagpt/ext/spo/utils/load.py:26


def set_file_name(name: str):
    global FILE_NAME
    FILE_NAME = name


def load_meta_data(k: int = SAMPLE_K):
    # load yaml file
    config_path = Path(__file__).parent.parent / "settings" / FILE_NAME

    if not config_path.exists():
        raise FileNotFoundError(f"Configuration file '{FILE_NAME}' not found in settings directory")

    try:
        with config_path.open("r", encoding="utf-8") as file:
            data = yaml.safe_load(file)
    except yaml.YAMLError as e:
        raise ValueError(f"Error parsing YAML file '{FILE_NAME}': {str(e)}")
    except Exception as e:
        raise Exception(f"Error reading file '{FILE_NAME}': {str(e)}")

    qa = []

    for item in data["qa"]:
        question = item["question"]
        answer = item["answer"]
        qa.append({"question": question, "answer": answer})

    prompt = data["prompt"]
    requirements = data["requirements"]
    count = data["count"]

    if isinstance(count, int):
        count = f", within {count} words"
    else:
        count = ""

View on GitHub (pinned to 11cdf466d0)

Solutions

  1. Read the line/column in the message and fix the yaml syntax there.
  2. Run python -c "import yaml; yaml.safe_load(open('metagpt/ext/spo/settings/<FILE>'))" to iterate quickly outside MetaGPT.
  3. Quote prompt strings that contain ': ' or yaml special characters; use block scalars (| or >) for long prompts.
  4. Resolve any leftover merge-conflict markers in the file.

Example fix

# before (invalid: unquoted colon)
prompt: Analyze this: step by step

# after
prompt: |
  Analyze this: step by step
Defensive patterns

Strategy: validation

Validate before calling

import yaml

def validate_spo_settings(path: str):
    with open(path, encoding="utf-8") as f:
        data = yaml.safe_load(f)
    assert {"qa", "prompt", "requirements", "count"} <= set(data), "missing keys in settings yaml"
    return data

Try / catch

try:
    data = load_meta_data()
except ValueError as e:
    if "Error parsing YAML" in str(e):
        # re-run yaml.safe_load yourself to get position; guide user to fix line
        raise
    raise

Prevention

When it happens

Trigger: Tabs used for indentation, unquoted strings containing special yaml characters (:, {, [, *), duplicated keys with conflicting constructs, or truncated file content in metagpt/ext/spo/settings/<FILE_NAME>.

Common situations: Hand-editing the qa/prompt/requirements yaml and breaking syntax; copy-pasting prompts containing colons without quotes; merge conflicts left unresolved in the settings file.

Related errors


AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14). Data as JSON: /api/errors/a6f76b4baead8dd3. Report an issue: GitHub.