instructure/canvas-lms · error
User must be associated to rubric before LLM generation
Error message
User must be associated to rubric before LLM generation
What it means
validate_rubric_and_association_object asserts @rubric.user is present before allowing LLM generation: the rubric must be owned by (associated to) a user. Rubrics owned by an account or otherwise lacking a user owner cannot use LLM criteria generation.
Solutions
- Ensure the rubric is created in a user context so user_id is set before enabling LLM generation.
- Hide/disable the LLM generate UI for account-owned rubrics.
- Pre-check rubric.user in the controller and return a clear error instead of letting the service raise a bare string.
- If an existing rubric lacks an owner, re-create it under the current user rather than mutating ownership directly.
Example fix
// before
RubricLlmService.new(rubric).generate_criteria_via_llm(...)
// after
if rubric.user.nil?
return render json: { error: 'rubric must be owned by a user for AI generation' }, status: :unprocessable_entity
end
RubricLlmService.new(rubric).generate_criteria_via_llm(...) Defensive patterns
Strategy: validation
Validate before calling
return head :unprocessable_entity if rubric.user.nil?
Type guard
def user_owned_rubric?(rubric) rubric.respond_to?(:user) && rubric.user.present? end
Try / catch
begin
service.generate_criteria_via_llm(...)
rescue RuntimeError => e
raise unless e.message == 'User must be associated to rubric before LLM generation'
render json: { error: 'rubric has no owning user' }, status: :unprocessable_entity
end Prevention
- Create rubrics in user context so user_id is always populated when AI features are used.
- Hide AI generation UI for account-owned rubrics.
- Assert rubric.user in specs covering the LLM flow.
When it happens
Trigger: Calling generate_criteria_via_llm or regenerate_criteria_via_llm on a rubric whose user_id is nil — e.g. an account-level rubric, a rubric created without user_context, or a rubric where ownership was never set.
Common situations: Admin/account rubrics opened in an editor that exposes the LLM button; rubrics imported/migrated without an owner; specs or scripts constructing Rubric.new without user assignment.
Related errors
- Cannot find criterion with id #
- Cannot regenerate criteria with learning outcomes attached
- LLM generation is only available for rubrics associated…
- The AI response was not in the expected format. Please try…
- AI response appears truncated - the response may have…
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/42a9cf34c737c07c.
Report an issue: GitHub.
Appendix: source
Thrown at app/services/rubric_llm_service.rb:193
def resolve_generate_options(generate_options)
DEFAULT_GENERATE_OPTIONS.merge(generate_options.symbolize_keys)
end
def resolve_regenerate_options(generate_options, regenerate_options)
resolved = resolve_generate_options(generate_options)
resolved.merge(
additional_user_prompt: regenerate_options.symbolize_keys[:additional_user_prompt].presence ||
resolved[:additional_prompt_info].presence ||
"No specific expectations, just improve it."
)
end
def validate_rubric_and_association_object(association_object)
unless association_object.is_a?(AbstractAssignment)
raise "LLM generation is only available for rubrics associated with an Assignment"
end
raise "User must be associated to rubric before LLM generation" unless @rubric.user
end
def call_llm_with_prefill(llm_config, prompt, root_account_uuid)
response = nil
time = Benchmark.measure do
response = CedarClient.conversation(
messages:
[{ role: "User", text: prompt },
{ role: "Assistant", text: "{" }],
model: llm_config.model_id,
feature_slug: GENERATE_FEATURE_SLUG,
root_account_uuid:,
current_user: @rubric.user
).response
end
[response, time]
end
View on GitHub (pinned to 1c9f0bb801)