{"record":{"id":"34903d81c1e4c125","repo":"plandex-ai/plandex","slug":"s-is-not-built-in-not-being-imported-and-not","errorCode":null,"errorMessage":"'%s' is not built-in, not being imported, and not an existing custom model","messagePattern":"'(.+?)' is not built-in, not being imported, and not an existing custom model","errorType":"validation","errorClass":null,"httpStatus":422,"severity":"error","filePath":"app/server/handlers/models.go","lineNumber":241,"sourceCode":"\t\tdbModel.Id = model.Id\n\t\tdbModel.OrgId = auth.OrgId\n\n\t\ttoUpsertCustomModels = append(toUpsertCustomModels, dbModel)\n\t}\n\n\tfor _, modelPack := range updatedModelsInput.CustomModelPacks {\n\t\t// ensure that all models are either built-in, being imported, or already exist\n\t\tallModelIds := modelPack.AllModelIds()\n\n\t\tfor _, modelId := range allModelIds {\n\t\t\t_, exists := existingCustomModelIds[modelId]\n\t\t\t_, creating := inputModelIds[string(modelId)]\n\t\t\tbm, builtIn := shared.BuiltInBaseModelsById[modelId]\n\n\t\t\tif !exists && !creating && !builtIn {\n\t\t\t\tmsg := fmt.Sprintf(\"'%s' is not built-in, not being imported, and not an existing custom model\", modelId)\n\t\t\t\tlog.Println(msg)\n\t\t\t\thttp.Error(w, msg, http.StatusUnprocessableEntity)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif builtIn && os.Getenv(\"IS_CLOUD\") != \"\" && bm.IsLocalOnly() {\n\t\t\t\tmsg := fmt.Sprintf(\"'%s' is a local-only built-in model, so it can't be used on Plandex Cloud\", modelId)\n\t\t\t\tlog.Println(msg)\n\t\t\t\thttp.Error(w, msg, http.StatusUnprocessableEntity)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tmp := modelPack.ToModelPack()\n\t\tdbMp := db.ModelPackFromApi(&mp)\n\t\tdbMp.OrgId = auth.OrgId\n\t\tdbMp.Id = mp.Id\n\n\t\ttoUpsertModelPacks = append(toUpsertModelPacks, dbMp)\n\t}","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/models.go#L223-L259","documentation":"A 422 validation error from UpsertCustomModelsHandler: a model pack references a model id (from modelPack.AllModelIds()) that is not a built-in base model (shared.BuiltInBaseModelsById), not an existing stored custom model for the org, and not included in the same request's CustomModels. Every model a pack references must be resolvable to one of those three sources.","triggerScenarios":"POST to the upsert endpoint with a CustomModelPacks entry whose roles (planner, coder, summarizer, etc.) reference a model id that was never defined — e.g. referencing 'gpt-4-turbo-custom' when no such custom model exists and the pack omits its definition, or a model that was dropped from CustomModels in this same full-replace request.","commonSituations":"Hand-editing a model pack and referencing a model defined in a different file; partial imports that send packs but not their models; a previous full-replace upsert deleted the custom model the pack depends on; typo in a base model id that is close to but not exactly a built-in id.","solutions":["Include the referenced custom model's definition in the same request's CustomModels array","Fix the model id to exactly match a built-in base model id","Create the custom model first with a prior upsert, then submit the pack","Verify ids against the org's current custom models list before submitting"],"exampleFix":"// before\n{\"customModelPacks\": [{\"name\": \"my-pack\", \"planner\": {\"modelId\": \"my-missing-model\"}}]}\n// after\n{\"customModels\": [{\"modelId\": \"my-missing-model\", \"providers\": [...]}], \"customModelPacks\": [{\"name\": \"my-pack\", \"planner\": {\"modelId\": \"my-missing-model\"}}]}","handlingStrategy":"validation","validationCode":"// ensure every model id referenced by packs resolves to built-in, existing, or in-request\nexisting := fetchExistingCustomModelIds(org)\ninRequest := map[string]bool{}\nfor _, m := range in.CustomModels { inRequest[string(m.ModelId)] = true }\nfor _, pack := range in.CustomModelPacks {\n    for _, id := range pack.AllModelIds() {\n        _, builtIn := shared.BuiltInBaseModelsById[id]\n        if !builtIn && !existing[id] && !inRequest[string(id)] {\n            return fmt.Errorf(\"pack references unresolvable model id: %q\", id)\n        }\n    }\n}","typeGuard":"func modelIdResolvable(id shared.ModelId, existing map[shared.ModelId]bool, inRequest map[string]bool) bool {\n    if _, ok := shared.BuiltInBaseModelsById[id]; ok { return true }\n    return existing[id] || inRequest[string(id)]\n}","tryCatchPattern":"// deterministic 422 — no retry; include missing models and resubmit\nif resp.StatusCode == 422 && strings.Contains(bodyText, \"not built-in, not being imported, and not an existing custom model\") {\n    return fmt.Errorf(\"add missing model definitions to CustomModels: %s\", bodyText)\n}","preventionTips":["Send model packs together with every custom model they reference","Beware full-replace semantics: dropping a model from CustomModels deletes it and breaks packs","Validate all AllModelIds() before submission","Keep pack and model definitions in one config source"],"tags":["validation","http-422","model-packs"],"backgroundTag":"unresolved-model-reference","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}