Added new deterministic validators to catch early failures

This commit is contained in:
2026-04-25 14:14:43 -05:00
parent 619c615d21
commit a255ff28b7
9 changed files with 286 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
from pathlib import Path
from audita.core.chunking import chunk_transcript
from audita.core.config import AuditaConfig
from audita.core.config import AuditaConfig, ConfigOverrides
from audita.core.errors import AuditaLLMError
from audita.core.schemas import parse_glossary_yaml, parse_source_transcript_json, parse_transcript_json
from audita.framework.models import ModuleContext, ModuleRunSpec
@@ -418,8 +418,8 @@ def test_process_transcript_result_rejects_below_threshold_proposals_before_llm_
]
assert result.report.skipped_corrections[0].reason == "proposal confidence below threshold"
assert result.report.skipped_corrections[0].source == "validator:proposal_confidence_guard"
assert result.report.modules[0].validators[0].rejected_count == 1
assert result.report.modules[0].validators[1].candidate_count == 0
assert result.report.modules[0].validators[2].rejected_count == 1
assert result.report.modules[0].validators[3].candidate_count == 0
def test_process_transcript_result_runs_spoken_word_module_with_full_validator_chain(tmp_path):
@@ -498,6 +498,8 @@ def test_process_transcript_result_runs_spoken_word_module_with_full_validator_c
"spoken_word:meaning_reversal_review",
]
assert [validator["name"] for validator in result.report.modules[0].to_dict()["validators"]] == [
"identical_text_guard",
"original_text_present_guard",
"proposal_confidence_guard",
"protected_glossary_guard",
"non_empty_segment_guard",
@@ -558,7 +560,7 @@ def test_process_transcript_result_rejects_spoken_word_below_threshold_before_ll
assert result.transcript[0].text == "I, uh, I think we should go."
assert [call["stage_name"] for call in client.calls] == ["spoken_word:proposal"]
assert result.report.skipped_corrections[0].reason == "proposal confidence below threshold"
assert result.report.modules[0].validators[1].candidate_count == 0
assert result.report.modules[0].validators[3].candidate_count == 0
def test_process_transcript_result_runs_grammar_module_with_full_validator_chain(tmp_path):
@@ -626,6 +628,8 @@ def test_process_transcript_result_runs_grammar_module_with_full_validator_chain
"grammar:meaning_reversal_review",
]
assert [validator["name"] for validator in result.report.modules[0].to_dict()["validators"]] == [
"identical_text_guard",
"original_text_present_guard",
"proposal_confidence_guard",
"protected_glossary_guard",
"non_empty_segment_guard",
@@ -752,7 +756,7 @@ def test_process_transcript_result_rejects_grammar_below_threshold_before_later_
assert result.transcript[0].text == "hello world"
assert [call["stage_name"] for call in client.calls] == ["grammar:proposal"]
assert result.report.skipped_corrections[0].reason == "proposal confidence below threshold"
assert result.report.modules[0].validators[1].candidate_count == 0
assert result.report.modules[0].validators[3].candidate_count == 0
def test_process_transcript_result_grammar_module_still_rejects_homophone_style_proposals(tmp_path):
@@ -864,11 +868,100 @@ def test_process_transcript_result_rejects_spoken_word_whole_segment_deletion_be
assert result.report.skipped_corrections[0].source == "validator:non_empty_segment_guard"
assert result.report.skipped_corrections[0].reason == "correction would leave the segment empty"
assert [validator["name"] for validator in result.report.modules[0].to_dict()["validators"]] == [
"identical_text_guard",
"original_text_present_guard",
"proposal_confidence_guard",
"protected_glossary_guard",
"non_empty_segment_guard",
"spoken_word_review",
"meaning_reversal_review",
]
assert result.report.modules[0].validators[2].rejected_count == 1
assert result.report.modules[0].validators[3].candidate_count == 0
assert result.report.modules[0].validators[4].rejected_count == 1
assert result.report.modules[0].validators[5].candidate_count == 0
def test_process_transcript_result_rejects_identical_text_before_later_validators(tmp_path):
transcript = parse_source_transcript_json(
"""
[
{"speaker": "Eric", "start": 0.0, "end": 1.0, "text": "hello world"}
]
"""
)
config = AuditaConfig.from_sources(
env={},
overrides=ConfigOverrides(work_dir=tmp_path / "work", work_dir_retention="always"),
)
client = FakeStructuredLLMClient(
[
{
"corrections": [
{
"id": 1,
"original_text": "hello",
"corrected_text": "hello",
"confidence": 0.95,
}
]
}
]
)
result = process_transcript_result(
transcript,
_glossary(),
config,
module_keys=["grammar"],
llm_client=client,
)
assert result.transcript[0].text == "hello world"
assert [call["stage_name"] for call in client.calls] == ["grammar:proposal"]
assert result.report.skipped_corrections[0].source == "validator:identical_text_guard"
assert result.report.skipped_corrections[0].reason == "proposal original_text and corrected_text are identical"
assert result.report.modules[0].validators[0].rejected_count == 1
assert result.report.modules[0].validators[1].candidate_count == 0
def test_process_transcript_result_rejects_missing_original_text_before_later_validators(tmp_path):
transcript = parse_source_transcript_json(
"""
[
{"speaker": "Eric", "start": 0.0, "end": 1.0, "text": "hello world"}
]
"""
)
config = AuditaConfig.from_sources(
env={},
overrides=ConfigOverrides(work_dir=tmp_path / "work", work_dir_retention="always"),
)
client = FakeStructuredLLMClient(
[
{
"corrections": [
{
"id": 1,
"original_text": "goodbye",
"corrected_text": "farewell",
"confidence": 0.95,
}
]
}
]
)
result = process_transcript_result(
transcript,
_glossary(),
config,
module_keys=["grammar"],
llm_client=client,
)
assert result.transcript[0].text == "hello world"
assert [call["stage_name"] for call in client.calls] == ["grammar:proposal"]
assert result.report.skipped_corrections[0].source == "validator:original_text_present_guard"
assert result.report.skipped_corrections[0].reason == "proposal original_text does not match segment text"
assert result.report.modules[0].validators[0].approved_count == 1
assert result.report.modules[0].validators[1].rejected_count == 1
assert result.report.modules[0].validators[2].candidate_count == 0