{"record":{"id":"8b5e7dafbc4c42c4","repo":"instructure/canvas-lms","slug":"template-must-be-a-string","errorCode":null,"errorMessage":"Template must be a string","messagePattern":"Template must be a string","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"app/models/llm_config.rb","lineNumber":66,"sourceCode":"      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\n\n  private\n\n  def validate!\n    raise ArgumentError, \"Name must be a string\" unless @name.is_a?(String)\n    raise ArgumentError, \"Model ID must be a string\" unless @model_id.is_a?(String)\n    raise ArgumentError, \"Rate limit must be either nil, or hash with :limit and :period keys\" unless @rate_limit.nil? || (@rate_limit.is_a?(Hash) && @rate_limit.keys == %i[limit period])\n    raise ArgumentError, \"Template must be a string\" unless @template.is_a?(String)\n    raise ArgumentError, \"Options must be a hash\" unless @options.is_a?(Hash)\n  end\nend\n","sourceCodeStart":48,"sourceCodeEnd":70,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/models/llm_config.rb#L48-L70","documentation":"LlmConfig#validate! raises ArgumentError when the template passed to the initializer is not a String. The prompt template is required to be a string containing the placeholder tokens that generate_prompt_and_options will substitute.","triggerScenarios":"LlmConfig.new(name, model_id, rate_limit, template, ...) where template is nil, an array of prompt parts, a proc, or any non-string value.","commonSituations":"Building templates by joining arrays and forgetting to join; nil template from a missing config field; passing a lazily rendered block instead of a rendered string.","solutions":["Pass the fully rendered template String.","Join prompt parts with .join(\"\\n\") before constructing the config.","Fix the config source so the template field is present and a string."],"exampleFix":"// before\nLlmConfig.new(\"gpt4\", \"gpt-4\", nil, [\"Hello\", \"<NAME_PLACEHOLDER>\"], {})\n// after\nLlmConfig.new(\"gpt4\", \"gpt-4\", nil, \"Hello <NAME_PLACEHOLDER>\", {})","handlingStrategy":"type-guard","validationCode":"raise ArgumentError, \"template must be String\" unless template.is_a?(String)","typeGuard":"def valid_template?(v) = v.is_a?(String)","tryCatchPattern":"begin\n  cfg = LlmConfig.new(name, model_id, rate_limit, template, options)\nrescue ArgumentError => e\n  Rails.logger.error(\"Invalid template: #{e.message}\")\n  raise\nend","preventionTips":["Join multi-part prompts with .join(\"\\n\") before constructing the config","Fail fast on nil template when loading config files"],"tags":["argumenterror","validation","llm-config"],"backgroundTag":"invalid-constructor-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"}