{"record":{"id":"efefc55633174ca3","repo":"google-gemini/gemini-cli","slug":"template-validation-failed-missing-required-input","errorCode":null,"errorMessage":"Template validation failed: Missing required input parameters: ${missingKeys.join(', ')}. Available inputs: ${Object.keys(inputs).join(', ')}","messagePattern":"Template validation failed: Missing required input parameters: (.+?)\\. Available inputs: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/agents/utils.ts","lineNumber":33,"sourceCode":" * @throws {Error} if any placeholder key is not found in the inputs.\n */\nexport function templateString(template: string, inputs: AgentInputs): string {\n  const placeholderRegex = /\\$\\{(\\w+)\\}/g;\n\n  // First, find all unique keys required by the template.\n  const requiredKeys = new Set(\n    Array.from(template.matchAll(placeholderRegex), (match) => match[1]),\n  );\n\n  // Check if all required keys exist in the inputs.\n  const inputKeys = new Set(Object.keys(inputs));\n  const missingKeys = Array.from(requiredKeys).filter(\n    (key) => !inputKeys.has(key),\n  );\n\n  if (missingKeys.length > 0) {\n    // Enhanced error message showing both missing and available keys\n    throw new Error(\n      `Template validation failed: Missing required input parameters: ${missingKeys.join(', ')}. ` +\n        `Available inputs: ${Object.keys(inputs).join(', ')}`,\n    );\n  }\n\n  // Perform the replacement using a replacer function.\n  return template.replace(placeholderRegex, (_match, key) =>\n    String(inputs[key]),\n  );\n}\n","sourceCodeStart":15,"sourceCodeEnd":44,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/core/src/agents/utils.ts#L15-L44","documentation":"Thrown by templateString() when a template contains ${placeholder} tokens for which no corresponding key exists in the inputs object. The function scans the template with the regex /\\$\\{(\\w+)\\}/g, collects all unique placeholder names, and verifies each one is present in the inputs before performing substitution. The error message lists both the missing and available keys for fast diagnosis.","triggerScenarios":"Calling templateString(template, inputs) where template references a ${key} that is not a property of inputs. For example, templateString('Hello ${name}, you are ${role}', { name: 'Alice' }) throws because 'role' is missing.","commonSituations":"Agent input templates in definitions reference variables that the caller didn't supply; refactoring an agent's input schema to rename a field without updating the template (or vice versa); dynamically generated templates where placeholder names don't match runtime input keys; passing a subset of inputs to a template designed for a fuller context.","solutions":["Compare the error's 'Missing required input parameters' list against 'Available inputs' and add the missing keys to the inputs object.","If a placeholder is optional or may be absent, provide a default: { ...inputs, role: inputs.role ?? 'guest' } before calling templateString.","After renaming an input field, grep all templates that reference the old name and update them.","Add a unit test that asserts templateString succeeds for the expected input set of each agent definition."],"exampleFix":"// before\nconst result = templateString('Hello ${name}, role: ${role}', { name: 'Alice' });\n// throws: Missing required input parameters: role. Available inputs: name\n\n// after — supply all referenced keys\nconst result = templateString('Hello ${name}, role: ${role}', {\n  name: 'Alice',\n  role: 'admin',\n});","handlingStrategy":"validation","validationCode":"// Before calling templateString, verify all placeholders are satisfiable\nfunction validateTemplateInputs(template: string, inputs: Record<string, unknown>): string[] {\n  const placeholderRegex = /\\$\\{(\\w+)\\}/g;\n  const required = new Set(\n    Array.from(template.matchAll(placeholderRegex), (m) => m[1])\n  );\n  const available = new Set(Object.keys(inputs));\n  return [...required].filter((k) => !available.has(k));\n}\n\nconst missing = validateTemplateInputs(template, inputs);\nif (missing.length > 0) {\n  throw new Error(`Missing template inputs: ${missing.join(', ')}`);\n}","typeGuard":"function isTemplateSatisfiable(\n  template: string,\n  inputs: AgentInputs\n): boolean {\n  const placeholderRegex = /\\$\\{(\\w+)\\}/g;\n  const inputKeys = new Set(Object.keys(inputs));\n  for (const match of template.matchAll(placeholderRegex)) {\n    if (!inputKeys.has(match[1])) return false;\n  }\n  return true;\n}","tryCatchPattern":"try {\n  result = templateString(template, inputs);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Template validation failed')) {\n    // Provide defaults for missing keys or skip the template\n    const enriched = { ...inputs, missingKey: '' };\n    result = templateString(template, enriched);\n  } else throw e;\n}","preventionTips":["Add a unit test for each agent template asserting all placeholders resolve.","Use Zod to validate that input objects match the template's expected keys.","Run template validation at agent definition load time, not just at runtime.","Keep template placeholder names in sync with input schema field names."],"tags":["templating","validation","agents","input-schema"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}