{"record":{"id":"5aeee626f3eae8eb","repo":"ruvnet/ruflo","slug":"unknown-template-preset-template-use-objec","errorCode":null,"errorMessage":"Unknown template preset: ${template}. Use: ${Object.keys(presets).join(', ')}","messagePattern":"Unknown template preset: (.+?)\\. Use: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/ruvector/ruvllm-wasm.ts","lineNumber":347,"sourceCode":"export async function formatChat(\n  messages: ChatMessage[],\n  template: TemplatePreset | { custom: string } | { modelId: string },\n): Promise<string> {\n  await initRuvllmWasm();\n  const mod = await import('@ruvector/ruvllm-wasm');\n\n  // Build template\n  let tmpl: any;\n  if (typeof template === 'string') {\n    const presets: Record<string, () => any> = {\n      llama3: () => mod.ChatTemplateWasm.llama3(),\n      mistral: () => mod.ChatTemplateWasm.mistral(),\n      chatml: () => mod.ChatTemplateWasm.chatml(),\n      phi: () => mod.ChatTemplateWasm.phi(),\n      gemma: () => mod.ChatTemplateWasm.gemma(),\n    };\n    const factory = presets[template];\n    if (!factory) throw new Error(`Unknown template preset: ${template}. Use: ${Object.keys(presets).join(', ')}`);\n    tmpl = factory();\n  } else if ('custom' in template) {\n    tmpl = mod.ChatTemplateWasm.custom(template.custom);\n  } else if ('modelId' in template) {\n    tmpl = mod.ChatTemplateWasm.detectFromModelId(template.modelId);\n  }\n\n  // Build messages\n  const wasmMessages = messages.map(m => {\n    switch (m.role) {\n      case 'system': return mod.ChatMessageWasm.system(m.content);\n      case 'user': return mod.ChatMessageWasm.user(m.content);\n      case 'assistant': return mod.ChatMessageWasm.assistant(m.content);\n      default: throw new Error(`Unknown role: ${m.role}`);\n    }\n  });\n\n  return tmpl.format(wasmMessages);","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/ruvector/ruvllm-wasm.ts#L329-L365","documentation":"When formatChatTemplate is given a string template, it looks it up in a fixed preset map with exactly five keys: llama3, mistral, chatml, phi, gemma. An unrecognized string throws synchronously, listing the valid keys in the message. The check runs before any WASM template object is constructed, so no resource is allocated on failure.","triggerScenarios":"Calling the chat-template builder with template='llama' (typo of llama3), 'llama-3', 'gpt-4', 'qwen', 'vicuna', or any casing variant like 'Mistral'. Also when passing a model nickname that is not one of the five supported presets.","commonSituations":"Copy-pasting a HuggingFace model id (e.g. 'meta-llama/Meta-Llama-3-8B') into the template field instead of the preset name; version drift where a newer @ruvector/ruvllm-wasm exposes more presets than this wrapper maps; UI/CLI that forwards a user-typed model name verbatim.","solutions":["Use one of the five presets exactly: llama3, mistral, chatml, phi, gemma (lowercase, no version suffix).","If your model is not in the preset list, pass { custom: '<jinja-template>' } or { modelId: '<hf-id>' } instead of a string.","Guard the input: validate against the preset list before calling, and surface the allowed names to the user."],"exampleFix":"// before\nconst out = buildTemplate('llama', messages); // typo, throws\n\n// after: use the exact preset, or detect from model id\nconst out = buildTemplate('llama3', messages);\n// or:\nconst out = buildTemplate({ modelId: 'meta-llama/Meta-Llama-3-8B-Instruct' }, messages);","handlingStrategy":"type-guard","validationCode":"const TEMPLATE_PRESETS = ['llama3', 'mistral', 'chatml', 'phi', 'gemma'] as const;\ntype TemplatePreset = typeof TEMPLATE_PRESETS[number];\n\nfunction isPreset(s: string): s is TemplatePreset {\n  return (TEMPLATE_PRESETS as readonly string[]).includes(s);\n}","typeGuard":"function resolveTemplate(t: string | { custom: string } | { modelId: string }) {\n  if (typeof t === 'string') {\n    if (!isPreset(t)) throw new Error(`Unknown template preset: ${t}. Use: ${TEMPLATE_PRESETS.join(', ')}`);\n    return t;\n  }\n  return t;\n}","tryCatchPattern":null,"preventionTips":["Validate preset names against the constant list before calling the formatter.","Prefer { modelId } for arbitrary HuggingFace ids; reserve string presets for the five known names.","Surface the allowed preset list in your UI/CLI help text."],"tags":["chat-template","llm","validation","ruvector"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}