{"record":{"id":"ca9fa736085cbbd6","repo":"mudler/LocalAI","slug":"lora-directory-not-set-cannot-parse-loras-from-pr","errorCode":null,"errorMessage":"LoRA directory not set, cannot parse LoRAs from prompt\\n","messagePattern":"LoRA directory not set, cannot parse LoRAs from prompt\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"backend/go/stablediffusion-ggml/cpp/gosd.cpp","lineNumber":179,"sourceCode":"static bool is_absolute_path(const std::string& p) {\n#ifdef _WIN32\n    // Windows: C:/path or C:\\path\n    return p.size() > 1 && std::isalpha(static_cast<unsigned char>(p[0])) && p[1] == ':';\n#else\n    // Unix: /path\n    return !p.empty() && p[0] == '/';\n#endif\n}\n\n// Parse LoRAs from prompt string (e.g., \"<lora:name:1.0>\" or \"<lora:name>\")\n// Returns a vector of LoRA info and the cleaned prompt with LoRA tags removed\n// Matches upstream implementation more closely\nstatic std::pair<std::vector<sd_lora_t>, std::string> parse_loras_from_prompt(const std::string& prompt, const char* lora_dir) {\n    std::vector<sd_lora_t> loras;\n    std::string cleaned_prompt = prompt;\n\n    if (!lora_dir || strlen(lora_dir) == 0) {\n        fprintf(stderr, \"LoRA directory not set, cannot parse LoRAs from prompt\\n\");\n        return {loras, cleaned_prompt};\n    }\n\n    // Discover LoRA files for name-based lookup\n    std::map<std::string, std::string> discovered_lora_map = discover_lora_files(lora_dir);\n\n    // Map to accumulate multipliers for the same LoRA (matches upstream)\n    std::map<std::string, float> lora_map;\n    std::map<std::string, float> high_noise_lora_map;\n\n    static const std::regex re(R\"(<lora:([^:>]+):([^>]+)>)\");\n    static const std::vector<std::string> valid_ext = {\".pt\", \".safetensors\", \".gguf\"};\n    std::smatch m;\n\n    std::string tmp = prompt;\n\n    fprintf(stderr, \"Parsing LoRAs from prompt: %s\\n\", prompt.c_str());\n","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/go/stablediffusion-ggml/cpp/gosd.cpp#L161-L197","documentation":"Warning from parse_loras_from_prompt(): the prompt contains <lora:...> tags but no LoRA directory was configured (lora_dir empty at load time), so the tags cannot be resolved to files. The function returns an empty LoRA list; the tags are still stripped from the cleaned prompt and generation proceeds without LoRA effects.","triggerScenarios":"Generating with a prompt like 'a cat <lora:style:0.8>' while the backend was loaded without a lora_dir option (which also triggers the load-time warning 'LoRA model directory not set').","commonSituations":"Prompts copy-pasted from CivitAI/shared UIs that embed <lora:...> tags, used against a backend instance configured without a LoRA directory.","solutions":["Set the lora_dir option at model load to a directory containing the LoRA files","Or remove the <lora:...> tags from the prompt if LoRAs are not intended","Watch for the companion load-time warning to catch the missing lora_dir early"],"exampleFix":"// before: loaded without lora_dir\nprompt = \"a cat <lora:pixar:0.8>\"; // tag silently ignored\n\n// after: configure the directory at load time\nloadModel(\"...,lora_dir=/models/loras\");","handlingStrategy":"validation","validationCode":"// Go caller: reject LoRA tags when no directory is configured\nvar loraTag = regexp.MustCompile(`<lora:[^>]*>`)\nif opts.LoraDir == \"\" && loraTag.MatchString(req.Prompt) {\n    return fmt.Errorf(\"prompt contains <lora:...> tags but no lora_dir is configured\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Configure lora_dir whenever prompts from external sources are accepted","Validate prompts for LoRA tags and surface a clear error instead of silently ignoring them"],"tags":["stablediffusion","lora","prompt-parsing","config"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}