Skip to content

refactor(validation): enforce exactly-one-set constraint on model fields in class types.Part #682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ygicp
Copy link

@ygicp ygicp commented Apr 14, 2025

Add a Pydantic V2 @model_validator to the existing genai.types.Part model to enforce data integrity.

This validator ensures that exactly one of the specified optional fields (e.g., field_a, field_b, field_c) has a value other than None. If zero or more than one field is set during validation, a ValueError is now raised.

This refactoring improves the robustness of the model by explicitly enforcing the intended single-choice rule.

…lds in class `types.Part`

Add a Pydantic V2 @model_validator to the existing genai.types.Part model to enforce data integrity.

This validator ensures that exactly one of the specified optional fields (e.g., field_a, field_b, field_c) has a value other than None. If zero or more than one field is set during validation, a ValueError is now raised.

This refactoring improves the robustness of the model by explicitly enforcing the intended single-choice rule.
@MarkDaoust MarkDaoust added do not merge Indicates a pull request not ready for merge, due to either quality or timing. and removed do not merge Indicates a pull request not ready for merge, due to either quality or timing. labels May 5, 2025
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.

2 participants