{"record":{"id":"5d75dcdfcc914705","repo":"instructure/canvas-lms","slug":"unsupported-prompt","errorCode":null,"errorMessage":"Unsupported prompt","messagePattern":"Unsupported prompt","errorType":"validation","errorClass":"InvalidPrompt","httpStatus":null,"severity":"warning","filePath":"app/services/study_assist.rb","lineNumber":100,"sourceCode":"      return :chips if prompt.blank?\n\n      TOOLS.find { |_, cfg| prompt.match?(cfg[:prompt_pattern]) }&.first || :unknown\n    end\n\n    def initialize(course:, user:, prompt:, state:, locale: I18n.locale.to_s, regenerate: false)\n      @course = course\n      @user = user\n      @prompt = prompt.to_s\n      @state = state || {}\n      @locale = locale\n      @regenerate = regenerate || @prompt.match?(REGENERATE_PROMPT_PATTERN)\n    end\n\n    def call\n      return build_chips if @prompt.blank?\n\n      tool_key, tool_config = TOOLS.find { |_, cfg| @prompt.match?(cfg[:prompt_pattern]) }\n      raise InvalidPrompt, \"Unsupported prompt\" unless tool_key\n\n      unless @course.feature_enabled?(:study_assist) && @course.feature_enabled?(tool_config[:feature_flag])\n        raise ToolDisabled, tool_key.to_s\n      end\n\n      content = resolve_content\n\n      llm_config = LLMConfigs.config_for(tool_config[:llm_config])\n      raise \"No LLM config found for #{tool_config[:llm_config]}\" if llm_config.nil?\n\n      cache_key = response_cache_key(tool_key, llm_config, content)\n      Rails.cache.delete(cache_key) if @regenerate\n\n      Rails.cache.fetch(cache_key, expires_in: RESPONSE_CACHE_TTL) do\n        InstLLMHelper.with_rate_limit(user: @user, llm_config:) do\n          raw = call_cedar(tool_key, llm_config, content)\n          build_response(tool_key, raw)\n        end","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/services/study_assist.rb#L82-L118","documentation":"StudyAssist::InvalidPrompt raised by StudyAssist#call when the user's prompt matches none of the TOOLS prompt_pattern regexes. StudyAssist routes free-form prompts to a specific tool (flashcards, quizzes, etc.); unrouteable prompts are rejected before any tool runs.","triggerScenarios":"Calling StudyAssist.new(course:, prompt: \"some free text\").call where the prompt does not match any tool's prompt_pattern regex, and is not blank (blank prompts build chips instead).","commonSituations":"Users typing generic questions ('help me study') that no regex matches; localized/non-English prompts; TOOLS patterns narrowed by a recent change; frontend sending raw input instead of a predefined chip prompt.","solutions":["Use one of the supported prompt forms matched by the TOOLS prompt_patterns (e.g. 'make flashcards about ...')","Inspect StudyAssist::TOOLS to see the accepted prompt patterns","Update the prompt_pattern regexes to cover new phrasings if the tool should handle them","Handle InvalidPrompt in the controller/API layer and show the user the supported prompts"],"exampleFix":"// before\nStudyAssist.new(course:, prompt: params[:prompt]).call\n// after\nbegin\n  StudyAssist.new(course:, prompt: params[:prompt]).call\nrescue StudyAssist::InvalidPrompt\n  render json: { error: 'Unsupported prompt', supported: StudyAssist::TOOLS.keys }, status: :bad_request\nend","handlingStrategy":"try-catch","validationCode":"supported = StudyAssist::TOOLS.any? { |_, cfg| prompt.match?(cfg[:prompt_pattern]) }\nraise ArgumentError, 'unsupported prompt' unless supported","typeGuard":"null","tryCatchPattern":"begin\n  StudyAssist.new(course:, prompt:).call\nrescue StudyAssist::InvalidPrompt\n  # return 400 with the list of supported prompts\nrescue StudyAssist::ToolDisabled => e\n  # return 403 indicating the feature flag is off for this course\nend","preventionTips":["Constrain frontend input to predefined chip prompts","Keep TOOLS prompt_patterns in sync with UI copy","Enable study_assist and the tool's feature_flag on the course before calling","Handle both InvalidPrompt and ToolDisabled at the API boundary"],"tags":["ruby","rails","llm","study-assist","routing","ai"],"backgroundTag":"invalid-argument-value","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"}