{"record":{"id":"17294311089f56d3","repo":"Unity-Technologies/ml-agents","slug":"error-parsing-yaml-file-please-check-for-formatti","errorCode":null,"errorMessage":"Error parsing yaml file. Please check for formatting errors. A tool such as http://www.yamllint.com/ can be helpful with this.","messagePattern":"Error parsing yaml file\\. Please check for formatting errors\\. A tool such as http://www\\.yamllint\\.com/ can be helpful with this\\.","errorType":"exception","errorClass":"TrainerConfigError","httpStatus":null,"severity":"error","filePath":"ml-agents/mlagents/trainers/cli_utils.py","lineNumber":341,"sourceCode":"            return _load_config(data_file)\n    except OSError:\n        abs_path = os.path.abspath(config_path)\n        raise TrainerConfigError(f\"Config file could not be found at {abs_path}.\")\n    except UnicodeDecodeError:\n        raise TrainerConfigError(\n            f\"There was an error decoding Config file from {config_path}. \"\n            f\"Make sure your file is save using UTF-8\"\n        )\n\n\ndef _load_config(fp: TextIO) -> Dict[str, Any]:\n    \"\"\"\n    Load the yaml config from the file-like object.\n    \"\"\"\n    try:\n        return yaml.safe_load(fp)\n    except yaml.parser.ParserError as e:\n        raise TrainerConfigError(\n            \"Error parsing yaml file. Please check for formatting errors. \"\n            \"A tool such as http://www.yamllint.com/ can be helpful with this.\"\n        ) from e\n\n\nparser = _create_parser()\n","sourceCodeStart":323,"sourceCodeEnd":348,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents/mlagents/trainers/cli_utils.py#L323-L348","documentation":"_load_config runs yaml.safe_load on the config; a yaml.parser.ParserError (structural YAML syntax problem, not semantic) is converted into a TrainerConfigError suggesting a YAML linter. The message is generic — the original ParserError is chained as __cause__ for details.","triggerScenarios":"load_config encountering YAML with broken indentation, tabs instead of spaces, unbalanced quotes/brackets, or a stray 'key: value:' structure. Called from load_config and directly in tests.","commonSituations":"Hand-editing trainer config YAML and mis-nesting hyperparameters, pasting YAML from a chat/doc losing indentation, using tabs, or forgetting a space after a colon.","solutions":["Read the chained ParserError (line/column) in the traceback and fix that YAML line","Validate the file at http://www.yamllint.com/ or run yamllint config.yaml","Replace tabs with spaces and ensure consistent 2-space indentation","Add a space after colons and quote values containing special characters (:)"],"exampleFix":"// before\nhyperparameters:\n\tbatch_size: 64\n   learning_rate:3e-4\n// after\nhyperparameters:\n  batch_size: 64\n  learning_rate: 3.0e-4","handlingStrategy":"validation","validationCode":"import yaml\ndef validate_yaml(path):\n    with open(path) as f:\n        try:\n            yaml.safe_load(f)\n        except yaml.parser.ParserError as e:\n            raise SystemExit(f\"YAML syntax error in {path}: {e}\")","typeGuard":null,"tryCatchPattern":"try:\n    config = load_config(config_path)\nexcept TrainerConfigError as e:\n    import yaml\n    try:\n        yaml.safe_load(open(config_path))\n    except yaml.parser.ParserError as pe:\n        print(f\"Fix YAML at line {pe.problem_mark.line + 1}: {pe.problem}\")\n    raise","preventionTips":["Run yamllint (or yamllint.com) on trainer configs before training runs","Use spaces, never tabs, and consistent 2-space indentation in YAML","Add a CI step that parses all config YAMLs with yaml.safe_load"],"tags":["config","yaml","parse-error","ml-agents"],"backgroundTag":"yaml-parse-error","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}