{"record":{"id":"511a81220d29a92e","repo":"Unity-Technologies/ml-agents","slug":"there-was-an-error-decoding-config-file-from-conf","errorCode":null,"errorMessage":"There was an error decoding Config file from {config_path}. Make sure your file is save using UTF-8","messagePattern":"There was an error decoding Config file from (.+?)\\. Make sure your file is save using UTF-8","errorType":"exception","errorClass":"TrainerConfigError","httpStatus":null,"severity":"error","filePath":"ml-agents/mlagents/trainers/cli_utils.py","lineNumber":328,"sourceCode":"    torch_conf.add_argument(\n        \"--torch-device\",\n        default=None,\n        dest=\"device\",\n        action=DetectDefault,\n        help='Settings for the default torch.device used in training, for example, \"cpu\", \"cuda\", or \"cuda:0\"',\n    )\n    return argparser\n\n\ndef load_config(config_path: str) -> Dict[str, Any]:\n    try:\n        with open(config_path) as data_file:\n            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","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents/mlagents/trainers/cli_utils.py#L310-L346","documentation":"load_config reads the trainer config YAML as UTF-8 text; a UnicodeDecodeError means the bytes are not valid UTF-8 (e.g. the file was saved in Latin-1 or contains a UTF-8 BOM/invisible characters), so it raises TrainerConfigError asking you to re-save as UTF-8.","triggerScenarios":"Opening a config YAML edited in a non-UTF-8 editor or downloaded with a different encoding; the exception is raised during open/read in load_config (via main/from_argparse).","commonSituations":"Configs edited on Windows in Notepad with ANSI encoding, files with smart quotes or special characters pasted from docs, or YAML exported from Excel.","solutions":["Re-save the YAML with UTF-8 encoding in your editor","Convert in place: iconv -f latin1 -t utf-8 config.yaml -o config_utf8.yaml","Remove/retype non-ASCII characters (smart quotes, em dashes) in the config"],"exampleFix":"// before\n# config saved as ANSI/Latin-1\nmlagents-learn config.yaml ...\n// after\niconv -f WINDOWS-1252 -t UTF-8 config.yaml > config_utf8.yaml\nmlagents-learn config_utf8.yaml ...","handlingStrategy":"validation","validationCode":"raw = open(config_path, 'rb').read()\ntry:\n    raw.decode('utf-8')\nexcept UnicodeDecodeError as e:\n    raise SystemExit(f\"{config_path} is not UTF-8: {e}; re-save the file as UTF-8\")","typeGuard":null,"tryCatchPattern":"try:\n    config = load_config(config_path)\nexcept TrainerConfigError as e:\n    if 'decoding' in str(e):\n        print(f\"Re-save {config_path} as UTF-8\")\n    raise","preventionTips":["Configure your editor to save YAML as UTF-8 (no BOM)","Avoid pasting characters like smart quotes or em dashes into configs","Run file -bi config.yaml to check the encoding before training"],"tags":["config","encoding","utf-8","ml-agents","yaml"],"backgroundTag":"invalid-file-encoding","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}