{"record":{"id":"1b10993767696d84","repo":"invoke-ai/InvokeAI","slug":"model-config-dict-format-field-must-be-a-string","errorCode":null,"errorMessage":"Model config dict 'format' field must be a string or Enum","messagePattern":"Model config dict 'format' field must be a string or Enum","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/model_manager/configs/base.py","lineNumber":177,"sourceCode":"        # See: https://docs.pydantic.dev/latest/concepts/unions/#discriminated-unions-with-callable-discriminator\n        if isinstance(v, Config_Base):\n            # We have an instance of a ModelConfigBase subclass - use its tag directly.\n            return v.get_tag().tag\n        if isinstance(v, dict):\n            # We have a dict - attempt to compute a tag from its fields.\n            tag_strings: list[str] = []\n            if type_ := v.get(\"type\"):\n                if isinstance(type_, Enum):\n                    type_ = str(type_.value)\n                elif not isinstance(type_, str):\n                    raise ValueError(\"Model config dict 'type' field must be a string or Enum\")\n                tag_strings.append(type_)\n\n            if format_ := v.get(\"format\"):\n                if isinstance(format_, Enum):\n                    format_ = str(format_.value)\n                elif not isinstance(format_, str):\n                    raise ValueError(\"Model config dict 'format' field must be a string or Enum\")\n                tag_strings.append(format_)\n\n            if base_ := v.get(\"base\"):\n                if isinstance(base_, Enum):\n                    base_ = str(base_.value)\n                elif not isinstance(base_, str):\n                    raise ValueError(\"Model config dict 'base' field must be a string or Enum\")\n                tag_strings.append(base_)\n\n            # Special case: CLIP Embed models also need the variant to distinguish them.\n            if (\n                type_ == ModelType.CLIPEmbed.value\n                and format_ == ModelFormat.Diffusers.value\n                and base_ == BaseModelType.Any.value\n            ):\n                if variant_ := v.get(\"variant\"):\n                    if isinstance(variant_, Enum):\n                        variant_ = variant_.value","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/configs/base.py#L159-L195","documentation":"Same discriminator logic as error 1015 but for the 'format' field: it must be a string or Enum, else ValueError. The tag built from type/format/base (and variant for CLIP Embed) selects the concrete config class in the discriminated union.","triggerScenarios":"Constructing a model config from a dict where 'format' is an int, None-like object, or bytes instead of a str/Enum (e.g. {'type': 'main', 'format': 1, ...}).","commonSituations":"Configs deserialized from external tools or DB rows where ModelFormat was stored as a numeric code; YAML with numeric-looking format values; typos that turned the value into something unexpected.","solutions":["Use the enum value string: {'format': ModelFormat.Diffusers.value} or {'format': 'diffusers'}.","Pass the ModelFormat Enum member directly.","Fix the importer/serializer to emit string enum values."],"exampleFix":"// before\n{'type': 'main', 'format': 0, 'base': 'sd-1'}\n// after\n{'type': 'main', 'format': ModelFormat.Diffusers.value, 'base': 'sd-1'}","handlingStrategy":"validation","validationCode":"def normalize_format(v) -> str:\n    return v.value if isinstance(v, Enum) else str(v)","typeGuard":"def is_valid_format(v: object) -> TypeGuard[str | Enum]:\n    return isinstance(v, (str, Enum))","tryCatchPattern":"try:\n    config = AnyModelConfig(**cfg)\nexcept ValueError as e:\n    if \"'format' field must be a string or Enum\" in str(e):\n        cfg['format'] = cfg['format'].value if isinstance(cfg['format'], Enum) else str(cfg['format'])\n        config = AnyModelConfig(**cfg)\n    else:\n        raise","preventionTips":["Always build config dicts using ModelFormat enum members or their .value strings.","Run pydantic round-trip tests on exported/imported model configs.","Map legacy numeric format codes to ModelFormat explicitly at import time."],"tags":["invokeai","pydantic","discriminator","type-mismatch"],"backgroundTag":"discriminator-validation-failed","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}