{"record":{"id":"251950bb42bbbeb9","repo":"huggingface/transformers","slug":"export-config-dict-must-contain-key-export-format","errorCode":null,"errorMessage":"export_config_dict must contain key 'export_format' set to exporter name","messagePattern":"export_config_dict must contain key 'export_format' set to exporter name","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/exporters/auto.py","lineNumber":53,"sourceCode":"    \"dynamo\": DynamoConfig,\n    \"onnx\": OnnxConfig,\n}\n\nlogger = logging.get_logger(__name__)\n\n\nclass AutoExportConfig:\n    \"\"\"\n    The Auto-HF export config class that takes care of automatically dispatching to the correct\n    export config given an export config stored in a dictionary.\n    \"\"\"\n\n    @classmethod\n    def from_dict(cls, export_config_dict: dict):\n        export_format = export_config_dict.get(\"export_format\")\n\n        if export_format is None:\n            raise ValueError(\"export_config_dict must contain key 'export_format' set to exporter name\")\n\n        # Allow passing an ExportFormat enum value or a plain string\n        if isinstance(export_format, ExportFormat):\n            name = export_format.value\n        else:\n            name = export_format\n\n        if name not in AUTO_EXPORT_CONFIG_MAPPING:\n            raise ValueError(\n                f\"Unknown exporter type, got {name} - supported exporters are: {list(AUTO_EXPORT_CONFIG_MAPPING.keys())}\"\n            )\n\n        target_cls = AUTO_EXPORT_CONFIG_MAPPING[name]\n        return target_cls.from_dict(export_config_dict)\n\n\nclass AutoHfExporter:\n    \"\"\"","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/exporters/auto.py#L35-L71","documentation":"AutoExportConfig.from_dict dispatches to the right exporter by reading the 'export_format' key of the supplied dict. If the key is absent (dict.get returns None), it raises ValueError — an export config without a format cannot be mapped to any exporter class.","triggerScenarios":"Calling AutoExportConfig.from_dict({'per_channel': True, ...}) or passing a task-ish dict without 'export_format'; misspelling the key ('format', 'exporter').","commonSituations":"Building export configs programmatically and forgetting the key; copying a plain task dict where an export config dict is expected; key renamed between versions.","solutions":["Add 'export_format' to the dict with a supported exporter name (a ExportFormat enum value or plain string, e.g. 'onnx').","Prefer passing an ExportFormat enum (e.g. ExportFormat.ONNX) to avoid string typos.","Use one of the names listed in AUTO_EXPORT_CONFIG_MAPPING; an unknown name raises the sibling error."],"exampleFix":"# before\nAutoExportConfig.from_dict({\"per_channel\": True})\n\n# after\nAutoExportConfig.from_dict({\"export_format\": \"onnx\", \"per_channel\": True})","handlingStrategy":"validation","validationCode":"REQUIRED_KEY = \"export_format\"\n\ndef validate_export_config(cfg: dict) -> None:\n    if REQUIRED_KEY not in cfg:\n        raise ValueError(f\"export config missing '{REQUIRED_KEY}'\")","typeGuard":"def is_export_config_dict(cfg: object) -> bool:\n    return isinstance(cfg, dict) and \"export_format\" in cfg","tryCatchPattern":"try:\n    export_cfg = AutoExportConfig.from_dict(cfg)\nexcept ValueError as e:\n    if \"export_format\" in str(e):\n        cfg = {\"export_format\": ExportFormat.ONNX, **cfg}\n        export_cfg = AutoExportConfig.from_dict(cfg)\n    else:\n        raise","preventionTips":["Use the ExportFormat enum instead of raw strings.","Build export configs from one factory function that always sets export_format.","Validate config dicts at the CLI boundary."],"tags":["export","config","validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}