Skip to content

fix: add cross-validation for questions/user_answers/correct_answers list lengths - #18

Open
ravimahatonp wants to merge 1 commit into
ChainLearnOfficial:mainfrom
ravimahatonp:fix/feedback-list-length-validation-7
Open

ravimahatonp wants to merge 1 commit into
ChainLearnOfficial:mainfrom
ravimahatonp:fix/feedback-list-length-validation-7

Conversation

@ravimahatonp

Copy link
Copy Markdown

Summary

Closes #7

Problem

GenerateFeedbackRequest accepts questions, user_answers, and correct_answers as independent lists with no cross-validation on their lengths. In feedback_engine.py, zip(user_answers, correct_answers) silently truncates to the shorter list, causing answers to be silently dropped and incorrect score/feedback computation.

Solution

  • Added a @model_validator(mode="after") to GenerateFeedbackRequest that checks len(questions) == len(user_answers) == len(correct_answers).
  • Mismatched lengths now return a clear 422 Unprocessable Entity error with the exact lengths reported (e.g., questions=3, user_answers=1, correct_answers=3).
  • Added 8 targeted unit tests covering matching lengths, each mismatch direction, empty lists, and error message content.

Test Results

All 41 tests pass (33 existing + 8 new), zero regressions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No length validation between questions/user_answers/correct_answers

1 participant