-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1085 from guardrails-ai/feat/validation-summary
Add Validation failure information to Validation Outcome
- Loading branch information
Showing
5 changed files
with
89 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# TODO Temp to update once generated class is in | ||
from typing import Iterator, List | ||
|
||
from guardrails.classes.generic.arbitrary_model import ArbitraryModel | ||
from guardrails.classes.validation.validation_result import FailResult | ||
from guardrails.classes.validation.validator_logs import ValidatorLogs | ||
from guardrails_api_client import ValidationSummary as IValidationSummary | ||
|
||
|
||
class ValidationSummary(IValidationSummary, ArbitraryModel): | ||
@staticmethod | ||
def _generate_summaries_from_validator_logs( | ||
validator_logs: List[ValidatorLogs], | ||
) -> Iterator["ValidationSummary"]: | ||
""" | ||
Generate a list of ValidationSummary objects from a list of | ||
ValidatorLogs objects. Using an iterator to allow serializing | ||
the summaries to other formats. | ||
""" | ||
for log in validator_logs: | ||
validation_result = log.validation_result | ||
is_fail_result = isinstance(validation_result, FailResult) | ||
failure_reason = validation_result.error_message if is_fail_result else None | ||
error_spans = validation_result.error_spans if is_fail_result else [] | ||
yield ValidationSummary( | ||
validatorName=log.validator_name, | ||
validatorStatus=log.validation_result.outcome, # type: ignore | ||
propertyPath=log.property_path, | ||
failureReason=failure_reason, | ||
errorSpans=error_spans, # type: ignore | ||
) | ||
|
||
@staticmethod | ||
def from_validator_logs( | ||
validator_logs: List[ValidatorLogs], | ||
) -> List["ValidationSummary"]: | ||
summaries = [] | ||
for summary in ValidationSummary._generate_summaries_from_validator_logs( | ||
validator_logs | ||
): | ||
summaries.append(summary) | ||
return summaries | ||
|
||
@staticmethod | ||
def from_validator_logs_only_fails( | ||
validator_logs: List[ValidatorLogs], | ||
) -> List["ValidationSummary"]: | ||
summaries = [] | ||
for summary in ValidationSummary._generate_summaries_from_validator_logs( | ||
validator_logs | ||
): | ||
if summary.failure_reason: | ||
summaries.append(summary) | ||
return summaries |
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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