Added a validator to prevent changes that result in an empty or whitespace-only string
This commit is contained in:
@@ -5,7 +5,7 @@ from audita.core.config import AuditaConfig
|
||||
from audita.core.errors import AuditaLLMError
|
||||
from audita.core.schemas import parse_glossary_yaml, parse_transcript_json
|
||||
from audita.framework.models import CorrectionProposal, ModuleRunSpec
|
||||
from audita.validators import GrammarOnlyValidator
|
||||
from audita.validators import GrammarOnlyValidator, NonEmptySegmentValidator
|
||||
from audita.validators.base import ValidationContext
|
||||
from audita.validators.llm import MeaningReversalValidator, SpokenFormPlausibilityValidator, SpokenWordValidator
|
||||
from audita.validators.prompts import (
|
||||
@@ -472,6 +472,84 @@ def test_grammar_only_validator_rejects_word_level_changes(tmp_path):
|
||||
)
|
||||
|
||||
|
||||
def test_non_empty_segment_validator_rejects_empty_and_whitespace_only_segments(tmp_path):
|
||||
transcript = parse_transcript_json(
|
||||
"""
|
||||
[
|
||||
{"id": 1, "speaker": "A", "start": 0.0, "end": 1.0, "text": "uh"},
|
||||
{"id": 2, "speaker": "A", "start": 1.0, "end": 2.0, "text": "um"}
|
||||
]
|
||||
"""
|
||||
)
|
||||
proposals = [
|
||||
CorrectionProposal(
|
||||
proposal_index=0,
|
||||
module_instance="spoken_word",
|
||||
module_key="spoken_word",
|
||||
id=1,
|
||||
original_text="uh",
|
||||
corrected_text="",
|
||||
confidence=0.95,
|
||||
),
|
||||
CorrectionProposal(
|
||||
proposal_index=1,
|
||||
module_instance="spoken_word",
|
||||
module_key="spoken_word",
|
||||
id=2,
|
||||
original_text="um",
|
||||
corrected_text=" ",
|
||||
confidence=0.95,
|
||||
),
|
||||
]
|
||||
|
||||
result = NonEmptySegmentValidator("non_empty_segment_guard").validate(
|
||||
_context(proposals=proposals, transcript=transcript, llm_client=None, tmp_path=tmp_path)
|
||||
)
|
||||
|
||||
assert [decision.approved for decision in result.decisions] == [False, False]
|
||||
assert all(decision.reason == "correction would leave the segment empty" for decision in result.decisions)
|
||||
|
||||
|
||||
def test_non_empty_segment_validator_allows_punctuation_only_and_unpreviewable_proposals(tmp_path):
|
||||
transcript = parse_transcript_json(
|
||||
"""
|
||||
[
|
||||
{"id": 1, "speaker": "A", "start": 0.0, "end": 1.0, "text": "uh"},
|
||||
{"id": 2, "speaker": "A", "start": 1.0, "end": 2.0, "text": "There were gestures at the temple."}
|
||||
]
|
||||
"""
|
||||
)
|
||||
proposals = [
|
||||
CorrectionProposal(
|
||||
proposal_index=0,
|
||||
module_instance="spoken_word",
|
||||
module_key="spoken_word",
|
||||
id=1,
|
||||
original_text="uh",
|
||||
corrected_text=".",
|
||||
confidence=0.95,
|
||||
),
|
||||
CorrectionProposal(
|
||||
proposal_index=1,
|
||||
module_instance="spoken_word",
|
||||
module_key="spoken_word",
|
||||
id=2,
|
||||
original_text="rank",
|
||||
corrected_text="Hrank",
|
||||
confidence=0.95,
|
||||
),
|
||||
]
|
||||
|
||||
result = NonEmptySegmentValidator("non_empty_segment_guard").validate(
|
||||
_context(proposals=proposals, transcript=transcript, llm_client=None, tmp_path=tmp_path)
|
||||
)
|
||||
|
||||
assert [(decision.proposal_index, decision.approved, decision.reason) for decision in result.decisions] == [
|
||||
(0, True, None),
|
||||
(1, True, None),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("validator", "payload", "message_fragment"),
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user