{"record":{"id":"ef2178bbf43c895e","repo":"instructure/canvas-lms","slug":"content-exceeds-max-content-chars-character-limit","errorCode":null,"errorMessage":"Content exceeds #{MAX_CONTENT_CHARS} character limit","messagePattern":"Content exceeds #(.+?) character limit","errorType":"validation","errorClass":"ContentTooLarge","httpStatus":null,"severity":"error","filePath":"app/services/study_assist.rb","lineNumber":150,"sourceCode":"    end\n\n    # --- Content resolution ---\n\n    def resolve_content\n      page_id = @state[\"pageID\"] || @state[:pageID]\n      file_id = @state[\"fileID\"] || @state[:fileID]\n\n      content =\n        if page_id.present?\n          resolve_page(page_id)\n        elsif file_id.present?\n          resolve_file(file_id)\n        else\n          raise ContentUnavailable, \"No pageID or fileID provided\"\n        end\n\n      if content.text.length > MAX_CONTENT_CHARS\n        raise ContentTooLarge, \"Content exceeds #{MAX_CONTENT_CHARS} character limit\"\n      end\n\n      content\n    end\n\n    def resolve_page(page_id)\n      page = @course.wiki_pages.not_deleted.find_by(url: page_id)\n      raise ContentUnavailable, \"Page not found\" if page.nil?\n      raise ContentUnavailable, \"Page access denied\" unless page.grants_right?(@user, :read)\n\n      shard_safe_key = shard_safe_cache_key_for(page)\n      text = Rails.cache.fetch(text_cache_key_for(:page, shard_safe_key), expires_in: TEXT_CACHE_TTL) do\n        html_to_text(page.body.to_s)\n      end\n\n      Content.new(kind: :page, id: page.id, cache_key_with_version: shard_safe_key, text:)\n    end\n","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/services/study_assist.rb#L132-L168","documentation":"StudyAssist::ContentTooLarge is raised by resolve_content when the resolved content's extracted text exceeds MAX_CONTENT_CHARS characters. The service caps prompt size to protect LLM token limits and latency; oversized content is rejected rather than truncated.","triggerScenarios":"Calling #call with page_id or file_id whose extracted text length > MAX_CONTENT_CHARS (e.g. a very long wiki page or large text file), after successful content resolution.","commonSituations":"Extremely long course pages; concatenated/merged documents; uploads of big text files that pass the byte check on file size but extract into more characters than allowed; MAX_CONTENT_CHARS lowered in a config change making previously working content too large.","solutions":["Use shorter content (split the page or select a portion before passing page_id/file_id)","Chunk the content and make multiple StudyAssist calls on smaller excerpts","Raise MAX_CONTENT_CHARS if the LLM context window genuinely allows it","Verify extraction isn't inflating text (e.g. duplicated hidden content) via html_to_text"],"exampleFix":"// before\nStudyAssist.new(course:, user:, prompt:, page_id: 'huge-page').call\n// after\npage_text = html_to_text(page.body)\nStudyAssist.new(course:, user:, prompt:, page_id: 'huge-page').call if page_text.length <= StudyAssist::MAX_CONTENT_CHARS","handlingStrategy":"validation","validationCode":"content_text = resolved_text(course:, page_id:, file_id:)\nraise StudyAssist::ContentTooLarge if content_text.length > StudyAssist::MAX_CONTENT_CHARS","typeGuard":"null","tryCatchPattern":"begin\n  StudyAssist.new(course:, user:, prompt:, page_id:).call\nrescue StudyAssist::ContentTooLarge\n  render json: { error: 'content too large; select a shorter excerpt' }, status: :unprocessable_entity\nend","preventionTips":["Chunk long pages before submitting","Keep MAX_CONTENT_CHARS aligned with the LLM context window","Check extraction output size during development"],"tags":["ruby","study-assist","size-limit","llm","payload"],"backgroundTag":"payload-too-large","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"}