{"record":{"id":"688ebc3e5c700afb","repo":"googleapis/mcp-toolbox","slug":"error-substituting-params-for-message-w","errorCode":null,"errorMessage":"error substituting params for message: %w","messagePattern":"error substituting params for message: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/prompts/messages.go","lineNumber":67,"sourceCode":"\t}\n\treturn nil\n}\n\n// SubstituteMessages takes a slice of Messages and a set of parameter values,\n// and returns a new slice with all template variables resolved.\nfunc SubstituteMessages(messages []Message, arguments Arguments, argValues parameters.ParamValues) ([]Message, error) {\n\tsubstitutedMessages := make([]Message, 0, len(messages))\n\targsMap := argValues.AsMap()\n\n\tvar params parameters.Parameters\n\tfor _, arg := range arguments {\n\t\tparams = append(params, arg.Parameter)\n\t}\n\n\tfor _, msg := range messages {\n\t\tsubstitutedContent, err := parameters.ResolveTemplateParams(params, msg.Content, argsMap)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error substituting params for message: %w\", err)\n\t\t}\n\n\t\tsubstitutedMessages = append(substitutedMessages, Message{\n\t\t\tRole:    msg.Role,\n\t\t\tContent: substitutedContent,\n\t\t})\n\t}\n\n\treturn substitutedMessages, nil\n}\n","sourceCodeStart":49,"sourceCodeEnd":78,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/prompts/messages.go#L49-L78","documentation":"SubstituteMessages resolves {{.param}} template variables in each prompt message's content using the provided argument values via parameters.ResolveTemplateParams. It wraps and rethrows any per-message template resolution failure, attributing it to the specific message being substituted.","triggerScenarios":"A message content references a template variable that has no corresponding parameter definition (missing from argsMap), or the template syntax is malformed (e.g. `{{.name` unclosed, or invalid Go template expression) — ResolveTemplateParams errors for each message in turn.","commonSituations":"Renaming an argument in the `arguments:` list but not in message content; typo in the template variable ({{.userNam}}); using unsupported template constructs like pipelines or functions the resolver rejects; a caller invokes a prompt without supplying all declared parameters and the resolver requires them.","solutions":["Read the wrapped %w error to find the offending variable/syntax, then fix that message's content template.","Ensure every {{.x}} in message content has a matching entry in the prompt's `arguments:` list and that the caller supplies its value.","Fix Go template syntax: use {{.paramName}} with matching braces and no unsupported expressions.","Test the prompt locally with all parameters filled before deploying the config."],"exampleFix":"// before\ncontent: \"List tables in {{.databse}}\"\n// after\ncontent: \"List tables in {{.database}}\"","handlingStrategy":"validation","validationCode":"// Pre-check: every {{.var}} in message content has a declared argument\nfor _, msg := range cfg.Messages {\n\tfor _, v := range extractTemplateVars(msg.Content) {\n\t\tif !declaredArgs[v] {\n\t\t\treturn fmt.Errorf(\"message references undeclared parameter %q\", v)\n\t\t}\n\t}\n}","typeGuard":null,"tryCatchPattern":"sub, err := prompts.SubstituteParams(prompt, args)\nif err != nil {\n\tif strings.Contains(err.Error(), \"error substituting params for message\") {\n\t\treturn fmt.Errorf(\"check that all {{.param}} in prompt content match declared arguments and are supplied: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Keep argument names in `arguments:` and {{.name}} in content in sync; rename both together.","Only use simple {{.paramName}} substitution syntax, not full Go template features.","Supply all declared parameters when invoking the prompt.","Test prompt rendering with sample parameter values in unit tests."],"tags":["templates","prompts","validation","configuration"],"backgroundTag":"parameter-template-resolution-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}