{"record":{"id":"b953f98cb9615e64","repo":"instructure/canvas-lms","slug":"submission-must-be-at-least-5-words-long","errorCode":null,"errorMessage":"Submission must be at least 5 words long","messagePattern":"Submission must be at least 5 words long","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/services/grade_service.rb","lineNumber":158,"sourceCode":"               .gsub(/<[^>]*>/, \"\")                                       # Remove any remaining opening tags\n               .gsub(%r{</[^>]*>}, \"\")                                    # Remove any remaining closing tags\n\n    # Remove any content between \\&lt; and \\&gt; (including the entities themselves)\n    text = text.gsub(%r{\\\\&lt;[^&]*\\\\&gt;.*?\\\\&lt;/[^&]*\\\\&gt;}, \"\")      # Remove content between encoded opening and closing tags\n               .gsub(/\\\\&lt;[^&]*\\\\&gt;/, \"\")                             # Remove any remaining encoded opening tags\n               .gsub(%r{\\\\&lt;/[^&]*\\\\&gt;}, \"\")                          # Remove any remaining encoded closing tags\n\n    raise \"No essay submission found after removing text between <>\" if text.blank?\n\n    # Remove lines starting with more than 3 # characters\n    text = text.split(\"\\n\").reject { |line| line.strip.start_with?(\"####\") }.join(\"\\n\")\n\n    # Clean up any resulting double spaces and trim\n    text.gsub(/\\s+/, \" \").strip\n  end\n\n  def validate_essay_length(text)\n    raise \"Submission must be at least 5 words long\" if text.split.size < 5\n  end\n\n  def friendly_cedar_error_for(error)\n    case error\n    when InstructureMiscPlugin::Extensions::CedarClient::CedarLimitReachedError\n      I18n.t(\"Grading is temporarily unavailable. Please try again later.\")\n    when InstructureMiscPlugin::Extensions::CedarClient::ContentTooLongError\n      I18n.t(\"The submission is too long to be graded automatically.\")\n    when InstructureMiscPlugin::Extensions::CedarClient::UnsupportedLanguageError\n      I18n.t(\"The submission language is not supported for automatic grading.\")\n    else\n      I18n.t(\"An unexpected error occurred while grading.\")\n    end\n  end\n\n  def rubric_matches_default_template?\n    predefined_criteria_templates = [\n      [\"Exit Ticket Prompt\", \"Preparation\", \"Time\", \"Participation\"],","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/services/grade_service.rb#L140-L176","documentation":"GradeService#validate_essay_length requires the (sanitized) essay to contain at least 5 words before sending it to the external Cedar AI grader. This minimum-length guard avoids wasting grading API calls on trivially short submissions. It runs during call(), after sanitize_essay.","triggerScenarios":"Calling GradeService.call with an essay of fewer than 5 whitespace-separated words after sanitization; very short answers to an essay question on an assignment with AI grading enabled; a submission that shrinks below 5 words once tags/multiple spaces are stripped.","commonSituations":"Students submitting one-line answers to essay prompts; auto-graded practice assignments with AI grading enabled on short-answer questions; tests with stub essays shorter than 5 words.","solutions":["Have the student resubmit with a longer response, or disable AI/essay grading for short-answer questions","Guard in the caller: text.split.size >= 5 before constructing GradeService, showing a friendly message otherwise","If legitimate short responses should be graded, lower the threshold or bypass GradeService for those items"],"exampleFix":"// before\nGradeService.new(essay: submission.body, rubric:).call\n// after\nif submission.body.split.size < 5\n  return { error: I18n.t('Submission must be at least 5 words long') }\nend\nGradeService.new(essay: submission.body, rubric:).call","handlingStrategy":"validation","validationCode":"raise 'too short' if essay.to_s.split.size < 5","typeGuard":"essay.to_s.split.size >= 5","tryCatchPattern":"begin\n  GradeService.new(essay:, rubric:, rubric_association:).call\nrescue RuntimeError => e\n  show_too_short_error if e.message.include?('at least 5 words')\nend","preventionTips":["Enforce a client-side minimum word count on essay boxes","Only enable AI grading for long-form questions","Count words after sanitization, not before"],"tags":["grading","validation","ai"],"backgroundTag":"value-out-of-range","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"}