From 8c80c942dd403254b78cfc9a936500ef1179a8e6 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Tue, 21 Apr 2026 10:46:00 -0500 Subject: [PATCH] Updated the LLM prompt to enforce acoustic/phoenetic similarity requirements for proposed corrections --- src/audita/prompts.py | 11 +++++++++-- tests/test_prompts.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 tests/test_prompts.py diff --git a/src/audita/prompts.py b/src/audita/prompts.py index 9f2f8d0..7e3c143 100644 --- a/src/audita/prompts.py +++ b/src/audita/prompts.py @@ -15,14 +15,22 @@ def build_glossary_correction_messages(section: TranscriptSection, glossary: Glo system = ( "You are Audita, a careful transcript correction assistant. " "Identify only transcription errors that are strongly supported by the glossary. " + "A valid correction must be acoustically plausible: the original transcript text " + "should sound similar to the proposed correction when spoken aloud. " "Do not make generic grammar, spelling, capitalization, or style edits. " + "Do not substitute an unrelated glossary term just because it could fit the topic. " "Do not rewrite unchanged transcript segments. " "Preserve speaker names, timestamps, and meaning." ) user = ( "Review this transcript section and return only corrections that should be applied.\n\n" "Rules:\n" - "- Correct domain-specific names, aliases, jargon, deities, locations, NPCs, players, and similar terms when the glossary supports the correction.\n" + "- Correct domain-specific names, aliases, jargon, deities, locations, NPCs, players, and similar terms only when both the glossary and surrounding transcript context support the correction.\n" + "- The correction must be likely to fix a transcription error: the original words should be phonetically or acoustically similar to the corrected words in spoken English.\n" + "- Appropriate example: correcting \"gestures\" to \"Jesters\" can be valid if \"Jesters\" appears in the glossary and nearby context supports that inference.\n" + "- Inappropriate example: correcting \"Lyra\" to \"Jesters\" should be omitted because those words are not similar in spoken English, even if \"Jesters\" appears in the glossary.\n" + "- Do not replace one clear glossary term, character name, location, or ordinary word with a different glossary term unless it is a plausible mishearing.\n" + "- Assign high confidence only when the correction is supported by glossary evidence, local context, and spoken-word similarity; otherwise omit the correction.\n" "- Use the exact segment_index, speaker, start, end, and original_text from the input segment.\n" "- corrected_text must contain the full corrected text for that segment.\n" "- confidence must be between 0.0 and 1.0.\n" @@ -31,4 +39,3 @@ def build_glossary_correction_messages(section: TranscriptSection, glossary: Glo f"Transcript section:\n{section_json}" ) return [{"role": "system", "content": system}, {"role": "user", "content": user}] - diff --git a/tests/test_prompts.py b/tests/test_prompts.py new file mode 100644 index 0000000..b9b77f7 --- /dev/null +++ b/tests/test_prompts.py @@ -0,0 +1,34 @@ +from audita.chunking import chunk_transcript +from audita.prompts import build_glossary_correction_messages +from audita.schemas import parse_glossary_yaml, parse_transcript_json + + +def test_prompt_requires_acoustically_plausible_transcription_errors(): + transcript = parse_transcript_json( + """ + [ + {"speaker": "Eric", "start": 0.0, "end": 1.0, "text": "The gestures are nearby."} + ] + """ + ) + glossary = parse_glossary_yaml( + """ + glossary: + - name: "Jesters" + category: faction + summary: "The Jesters are a local faction." + - name: "Lyra" + category: npc + summary: "Lyra is a hostile NPC." + """ + ) + section = chunk_transcript(transcript, max_section_tokens=16000)[0] + + messages = build_glossary_correction_messages(section, glossary) + prompt_text = "\n".join(message["content"] for message in messages) + + assert "acoustically plausible" in prompt_text + assert "phonetically or acoustically similar" in prompt_text + assert '"gestures" to "Jesters"' in prompt_text + assert '"Lyra" to "Jesters"' in prompt_text + assert "should be omitted" in prompt_text