{"record":{"id":"027db034604892c0","repo":"mudler/LocalAI","slug":"unknown-task-task-available-tasks-join","errorCode":null,"errorMessage":"Unknown task '{task}'. Available tasks: {', '.join(sorted(aliases.keys())[:20])}...","messagePattern":"Unknown task '(.+?)'\\. Available tasks: (.+?)\\.\\.\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/python/diffusers/diffusers_dynamic_loader.py","lineNumber":368,"sourceCode":"            f\"Available pipelines: {', '.join(sorted(registry.keys())[:20])}...\"\n        )\n\n    # 2. Task alias lookup\n    if task:\n        task_lower = task.lower().replace('_', '-')\n        if task_lower in aliases:\n            # Return the first matching pipeline for this task\n            matching_classes = aliases[task_lower]\n            if matching_classes:\n                return registry[matching_classes[0]]\n\n        # Try partial matching\n        for alias, classes in aliases.items():\n            if task_lower in alias or alias in task_lower:\n                if classes:\n                    return registry[classes[0]]\n\n        raise ValueError(\n            f\"Unknown task '{task}'. \"\n            f\"Available tasks: {', '.join(sorted(aliases.keys())[:20])}...\"\n        )\n\n    # 3. Try to infer from HuggingFace Hub\n    if model_id:\n        try:\n            from huggingface_hub import model_info\n            info = model_info(model_id)\n\n            # Check pipeline_tag\n            if hasattr(info, 'pipeline_tag') and info.pipeline_tag:\n                tag = info.pipeline_tag.lower().replace('_', '-')\n                if tag in aliases:\n                    matching_classes = aliases[tag]\n                    if matching_classes:\n                        return registry[matching_classes[0]]\n","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/python/diffusers/diffusers_dynamic_loader.py#L350-L386","documentation":"Raised by resolve_pipeline_class when no class_name was given, a task was given, and the task matches no alias exactly, no substring-partial alias match, and thus falls through to the error. The message lists up to 20 known task aliases (e.g. 'text-to-image', 'image-to-image').","triggerScenarios":"Calling load_diffusers_pipeline(task=...) with an unrecognized task string such as 'txt2img', 'image-gen', or 'video-generation' when the alias map only contains canonical diffusers task tags.","commonSituations":"Passing shorthand CLI-style names instead of HuggingFace pipeline_tag conventions, a task tag from a newer diffusers version, or misspelled/case-mangled tasks (the code lowercases and replaces underscores with hyphens, so 'Text_To_Image' works but 'text to image' with spaces does not).","solutions":["Use a canonical alias from the error's 'Available tasks' list, e.g. 'text-to-image'.","Prefer passing class_name= directly if you know the pipeline class — it skips task resolution entirely.","If a model_id is available, omit task and let the loader infer from the HuggingFace model card pipeline_tag.","Normalize your task string to lowercase-hyphenated form before calling."],"exampleFix":"# before\nload_diffusers_pipeline(task=\"txt2img\", model_id=\"stabilityai/sd-turbo\")\n\n# after\nload_diffusers_pipeline(task=\"text-to-image\", model_id=\"stabilityai/sd-turbo\")","handlingStrategy":"validation","validationCode":"aliases = get_task_aliases()\nnorm = task.lower().replace('_', '-')\nassert norm in aliases or any(norm in a or a in norm for a in aliases), f\"unknown task {task!r}\"","typeGuard":"def is_known_task(task: str) -> bool:\n    aliases = get_task_aliases()\n    t = task.lower().replace('_', '-')\n    return t in aliases or any(t in a or a in t for a in aliases)","tryCatchPattern":"try:\n    cls = resolve_pipeline_class(task=task, ...)\nexcept ValueError as e:\n    return error_reply(str(e))  # message lists available tasks","preventionTips":["Use HuggingFace pipeline_tag spellings ('text-to-image').","Prefer class_name or model_id when you know them; task matching is the loosest path.","Normalize tasks to lowercase-hyphenated form at the API boundary."],"tags":["diffusers","task-resolution","validation","image-generation"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}