{"record":{"id":"e10fb6cc931594d1","repo":"instructure/canvas-lms","slug":"template-still-contains-placeholder-remaining-placeholder-0","errorCode":null,"errorMessage":"Template still contains placeholder: #{remaining_placeholder[0]}","messagePattern":"Template still contains placeholder: #(.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"app/models/llm_config.rb","lineNumber":40,"sourceCode":"\n  def initialize(name:, model_id:, rate_limit: nil, template: nil, options: nil)\n    @name = name\n    @model_id = model_id\n    @rate_limit = rate_limit&.transform_keys(&:to_sym)\n    @template = template\n    @options = options || {}\n    validate!\n  end\n\n  def generate_prompt_and_options(substitutions:)\n    new_template = template.dup\n\n    substitutions.each do |placeholder_prefix, sub_value|\n      new_template.gsub!(\"<#{placeholder_prefix}_PLACEHOLDER>\") { sub_value.to_s }\n    end\n\n    if (remaining_placeholder = new_template.match(/<\\w+_PLACEHOLDER>/))\n      raise ArgumentError, \"Template still contains placeholder: #{remaining_placeholder[0]}\"\n    end\n\n    new_options = options.deep_dup\n\n    new_options.each do |key, value|\n      substitutions.each do |placeholder_prefix, sub_value|\n        new_options[key] = value.gsub(\"<#{placeholder_prefix}_PLACEHOLDER>\", sub_value.to_s) if value.is_a?(String)\n      end\n    end\n\n    new_options.each_value do |value|\n      if value.is_a?(String) && (remaining_placeholder = value.match(/<\\w+_PLACEHOLDER>/))\n        raise ArgumentError, \"Options still contain placeholder: #{remaining_placeholder[0]}\"\n      end\n    end\n\n    [new_template, new_options]\n  end","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/models/llm_config.rb#L22-L58","documentation":"generate_prompt_and_options substitutes '<PREFIX_PLACEHOLDER>' tokens in the template string; after substitution it scans for any remaining '<\\w+_PLACEHOLDER>' token and raises ArgumentError if one survives. This guards against templates referencing placeholders that were never supplied in the substitutions hash.","triggerScenarios":"Calling LlmConfig#generate_prompt_and_options where the template string contains a '<FOO_PLACEHOLDER>' token for which no matching :FOO key exists in the substitutions hash (or the prefix differs by case/spelling).","commonSituations":"Typos in template placeholder names; adding a new placeholder to a prompt template without updating callers; renaming a substitutions key but not the template.","solutions":["Add the missing key to the substitutions hash matching the placeholder name exactly (e.g. '<FOO_PLACEHOLDER>' needs key :FOO).","Fix the template text: remove or correct the placeholder spelling.","Log/inspect the template being used in the LlmConfig definition that still contains the stale placeholder."],"exampleFix":"// before\ncfg.generate_prompt_and_options(user_name: \"Ada\")  # template has <USER_ID_PLACEHOLDER>\n// after\ncfg.generate_prompt_and_options(user_name: \"Ada\", user_id: 42)","handlingStrategy":"validation","validationCode":"missing = template.scan(/<(\\w+)_PLACEHOLDER>/).flatten.map(&:downcase).uniq - substitutions.keys.map(&:to_s).map(&:downcase)\nraise \"unsubstituted placeholders: #{missing.join(',')}\" unless missing.empty?","typeGuard":null,"tryCatchPattern":"begin\n  prompt, opts = config.generate_prompt_and_options(substitutions)\nrescue ArgumentError => e\n  Rails.logger.error(\"LLM template placeholder error: #{e.message}\")\n  raise\nend","preventionTips":["Keep placeholder names and substitution keys in one shared constant list","Add a spec asserting each production template has zero remaining placeholders with default substitutions","Grep templates for _PLACEHOLDER after renaming substitution keys"],"tags":["argumenterror","template","llm"],"backgroundTag":"missing-required-argument","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}