Add automatic validation system for Score results#78
Open
Conversation
…figuration - Added a validation section to the Score class, allowing automatic validation of prediction results against specified rules in YAML. - Introduced validation constraints including valid classes, regex patterns, and string length limits. - Enhanced the Score.Result class with validation methods to ensure compliance with defined rules. - Created comprehensive tests for various validation scenarios, ensuring robust functionality and error handling. - Updated documentation to reflect new validation features and usage patterns.
…uration - Added support for case-sensitive comparisons in the validation of `valid_classes` within the Score class. - Updated the validation logic to handle both case-sensitive and case-insensitive scenarios based on a new `case_sensitive` flag. - Expanded documentation to clarify the behavior of case sensitivity in validation rules. - Implemented comprehensive tests to verify the functionality of case-sensitive and case-insensitive validation, ensuring robust error handling.
Contributor
Author
✨ Enhancement: Case-Insensitive Validation AddedBased on feedback, I've enhanced the validation system with case-insensitive comparison for 🔧 What ChangedNew validation:
value:
valid_classes: ["Yes", "No", "Maybe"]
case_sensitive: false # Default: case-insensitiveDefault Behavior (Case-Insensitive):
Optional Case-Sensitive Mode: validation:
value:
valid_classes: ["Yes", "No"]
case_sensitive: true # Requires exact case match📈 Benefits
🧪 Test CoverageAdded 4 comprehensive test cases:
📝 Example UsageSimple case-insensitive (most common): validation:
value:
valid_classes: ["Yes", "No"] # Matches any case variationStrict case-sensitive when needed: validation:
value:
valid_classes: ["YES", "NO"]
case_sensitive: true # Only exact matchesThis enhancement makes the validation system much more user-friendly while maintaining full flexibility for cases where exact case matching is required. Total test coverage now: 25 passing tests 🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements comprehensive automatic validation for Score results based on YAML configuration rules. This ensures consistent, reliable classification outputs across the entire Plexus system by validating results against predefined constraints before they're returned.
Key Features
🔍 Automatic Validation
__getattribute__method interception⚙️ Validation Rules
["Yes", "No", "Maybe"])"^NQ - (?\!Other$).*")🎯 Field-Specific Validation
YAML Configuration
Technical Implementation
🏗️ Core Components Added
FieldValidation: Validation rules for individual fieldsValidationConfig: Groups field validations togetherValidationError: Descriptive error messages with field contextScore.Result.validate(): Validation logic with comprehensive error handling🔄 Method Interception
__getattribute__to wrap allpredict()calls automaticallypredict()method signatures for compatibility:predict(context, model_input)predict(model_input)predict(*, context, model_input)⚡ Performance
Examples
Basic Usage
Advanced Pattern Matching
Mixed Constraints
Error Handling
Validation failures throw descriptive
Score.ValidationErrorwith:Example error:
Test Coverage
📋 Comprehensive Testing
🧪 Test Categories
Benefits
✅ Quality Assurance
🛠️ Developer Experience
🔧 Maintainability
Files Changed
plexus/scores/Score.py: Core validation implementation (+260 lines)tests/test_score_validation.py: Comprehensive test suite (+448 lines)plexus/docs/score-yaml-format.md: Documentation updates (+38 lines)Compatibility Notes
🔀 Method Signature Handling
The implementation includes sophisticated compatibility handling for different
predict()method signatures found in the codebase. This adds some complexity but ensures zero breaking changes.Note: This compatibility layer can be simplified once predict() signatures are standardized across the codebase (tracked in #77).
🚀 Production Ready
Usage
This validation system provides immediate quality assurance for Score results while maintaining full backward compatibility and requiring zero changes to existing code.
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com