{"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":null,"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/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/cli/src/ruvector/ruvllm-wasm.ts#L329-L365","documentation":"The chat-templating wrapper accepts a template either as one of five string presets — llama3, mistral, chatml, phi, gemma — or as an object ({custom: '...'} or {modelId: '...'}). A string that is not one of the five preset keys fails the factory lookup and throws, listing the valid keys in the message.","triggerScenarios":"Passing 'llama-3' or 'Llama3' (wrong casing/hyphen); passing a HuggingFace model id string like 'llama-3.1-8b-instruct' where a preset key is required; using a preset name added in a newer version of the package than the one installed.","commonSituations":"Config files carrying model names instead of preset names; upgrading models without updating the template field; copy-pasting template names from HF docs that do not match this wrapper's five-key vocabulary.","solutions":["Use exactly one of: llama3, mistral, chatml, phi, gemma","For arbitrary models, pass an object instead: {modelId: 'meta-llama/Llama-3.1-8B-Instruct'} (uses detectFromModelId) or {custom: '<your template string>'}","Upgrade @ruvector/ruvllm-wasm if you expect a newer preset vocabulary","Validate template strings at config-load time against the five keys"],"exampleFix":"// before\nconst prompt = await formatChat('llama-3.1', messages); // throws: Unknown template preset\n// after\nconst prompt = await formatChat(\n  { modelId: 'meta-llama/Llama-3.1-8B-Instruct' }, // or 'llama3' preset exactly\n  messages\n);","handlingStrategy":"type-guard","validationCode":"const PRESETS = ['llama3', 'mistral', 'chatml', 'phi', 'gemma'] as const;\nif (typeof template === 'string' && !PRESETS.includes(template as any)) {\n  template = { modelId: template }; // reinterpret a model id instead of failing\n}","typeGuard":"type ChatPreset = 'llama3' | 'mistral' | 'chatml' | 'phi' | 'gemma';\nconst isChatPreset = (s: string): s is ChatPreset =>\n  ['llama3', 'mistral', 'chatml', 'phi', 'gemma'].includes(s);","tryCatchPattern":"try {\n  text = await formatChat(template, messages);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Unknown template preset')) {\n    text = await formatChat({ modelId: template as string }, messages); // fall back to detectFromModelId\n  } else throw e;\n}","preventionTips":["Type template as ChatPreset | {custom: string} | {modelId: string} so strings are compile-time checked","Validate config-loaded template strings against the five keys at startup","Prefer {modelId} for anything not exactly one of the five presets"],"tags":["wasm","llm","chat-template","preset","invalid-enum"],"backgroundTag":"unknown-preset-name","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}