{"record":{"id":"122ea0830500d809","repo":"invoke-ai/InvokeAI","slug":"unknown-model-model-key","errorCode":null,"errorMessage":"Unknown model: {model_key}","messagePattern":"Unknown model: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/sdxl.py","lineNumber":43,"sourceCode":"\n\n@invocation(\"sdxl_model_loader\", title=\"Main Model - SDXL\", tags=[\"model\", \"sdxl\"], category=\"model\", version=\"1.0.4\")\nclass SDXLModelLoaderInvocation(BaseInvocation):\n    \"\"\"Loads an sdxl base model, outputting its submodels.\"\"\"\n\n    model: ModelIdentifierField = InputField(\n        description=FieldDescriptions.sdxl_main_model,\n        ui_model_base=BaseModelType.StableDiffusionXL,\n        ui_model_type=ModelType.Main,\n    )\n    # TODO: precision?\n\n    def invoke(self, context: InvocationContext) -> SDXLModelLoaderOutput:\n        model_key = self.model.key\n\n        # TODO: not found exceptions\n        if not context.models.exists(model_key):\n            raise Exception(f\"Unknown model: {model_key}\")\n\n        unet = self.model.model_copy(update={\"submodel_type\": SubModelType.UNet})\n        scheduler = self.model.model_copy(update={\"submodel_type\": SubModelType.Scheduler})\n        tokenizer = self.model.model_copy(update={\"submodel_type\": SubModelType.Tokenizer})\n        text_encoder = self.model.model_copy(update={\"submodel_type\": SubModelType.TextEncoder})\n        tokenizer2 = self.model.model_copy(update={\"submodel_type\": SubModelType.Tokenizer2})\n        text_encoder2 = self.model.model_copy(update={\"submodel_type\": SubModelType.TextEncoder2})\n        vae = self.model.model_copy(update={\"submodel_type\": SubModelType.VAE})\n\n        return SDXLModelLoaderOutput(\n            unet=UNetField(unet=unet, scheduler=scheduler, loras=[]),\n            clip=CLIPField(tokenizer=tokenizer, text_encoder=text_encoder, loras=[], skipped_layers=0),\n            clip2=CLIPField(tokenizer=tokenizer2, text_encoder=text_encoder2, loras=[], skipped_layers=0),\n            vae=VAEField(vae=vae),\n        )\n\n\n@invocation(","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/sdxl.py#L25-L61","documentation":"The SDXL main-model loader raises this when the ModelField's key (`self.model.key`) does not exist in the model manager's record store at invoke time. The TODO comment notes proper not-found exceptions were intended; a generic Exception is used as a placeholder. It means the referenced model was deleted, never installed, or the queue item references stale model state.","triggerScenarios":"context.models.exists(model_key) returns False because the model record was deleted between enqueue and execution, the model was never installed/converted, a workflow JSON was shared across installs with different model IDs, or the main-model invocation's `model` field points at a nonexistent/invalid key.","commonSituations":"Running old saved graphs after clearing the models directory; switching between SQLite databases; renaming/moving models outside the app; importing workflows from other users; partial model downloads failing to register.","solutions":["Install the referenced SDXL model (or fix its path/scan) so the key exists, then reopen the workflow and reselect the model in the Model Loader node.","Re-select the model in the SDXL Main Model Loader node so the graph stores a fresh valid key.","If the model exists, rescan the models directory or restart so the model records rebuild.","Do not hand-edit workflow JSON model keys; export/import via the UI instead."],"exampleFix":"// before\nraise Exception(f\"Unknown model: {model_key}\")\n// after\nfrom invokeai.app.services.shared.exceptions import UnknownModelException\nif not context.models.exists(model_key):\n    raise UnknownModelException(f\"Unknown model: {model_key}\")","handlingStrategy":"validation","validationCode":"if not context.models.exists(model_loader.model.key):\n    raise LookupError(f\"Model {model_loader.model.key} is not installed\")","typeGuard":"def model_exists(context, model) -> bool:\n    return context.models.exists(model.key)","tryCatchPattern":"try:\n    output = graph_executor.invoke(context)\nexcept Exception as e:\n    if str(e).startswith(\"Unknown model:\"):\n        # re-select models in the graph and requeue\n        requeue_with_valid_models(graph)\n    else:\n        raise","preventionTips":["Re-select models in the UI after reinstalling or moving model files","Never hand-edit model keys in workflow JSON","Rescan the models directory before running imported workflows","Keep one model-manager database per install"],"tags":["model-loading","sdxl","invalid-model-key"],"backgroundTag":"model-not-found","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}