Skip to content

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.

As the class `Part` requires only one element to be set and others be None, adding a model_Validator that checks that.
@ygicp ygicp changed the title Update types.py refactor(validation): enforce exactly-one-set constraint on model fields Apr 14, 2025
@ygicp ygicp changed the title refactor(validation): enforce exactly-one-set constraint on model fields enforce exactly-one-set constraint on model fields in class types.Part Apr 14, 2025
@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
@janasangeetha
Copy link
Collaborator

Same as #682

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.

3 participants