prompt-echo 0.1.0

Detect Whisper prompt-regurgitation hallucination on silent audio
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 11.58 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 255.92 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 15s Average build duration of successful builds.
  • all releases: 15s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • y0sif

prompt-echo

Detect Whisper prompt-regurgitation hallucination on silent audio.

The problem

Whisper-family models (OpenAI whisper-1, gpt-4o-*-transcribe, and most Whisper-derived APIs) condition decoding on an optional prompt parameter. When the audio carries no speech, the model has nothing to anchor decoding to and falls back to its strongest prior — the prompt itself — emitting it verbatim (or in long contiguous chunks) as the "transcription."

Without filtering, those echoes are typed at the cursor, which for a multi-hundred-character prompt can take tens of seconds at a configured key delay.

The solution

Two conservative heuristics, neither of which false-positives on real speech:

  1. Substring check: after normalisation (lowercase, strip punctuation, collapse whitespace), the entire response is a substring of the prompt.
  2. Word-run check: the longest contiguous word-run shared between response and prompt spans at least 6 words and covers at least 70% of the response.

Short responses (fewer than 8 normalised characters or 6 words) are never flagged — they could plausibly be a real utterance that happens to overlap the prompt's vocabulary.

Example

use prompt_echo::is_prompt_echo;

let prompt = "John Doe speaking. Professional, culinary register.";

// Echo detected — the model regurgitated the prompt on silence:
assert!(is_prompt_echo("John Doe speaking. Professional, culinary register.", prompt));

// Real speech not flagged:
assert!(!is_prompt_echo("I'm baking sourdough tonight", prompt));

When NOT to use this

Do not use this with streaming backends that do not accept a prompt parameter. The heuristics assume the API accepts a prompt and that prompt regurgitation is a known failure mode on silent audio. For prompt-less backends, false positives from vocabulary overlap are possible (the heuristics are designed conservatively, but the library's purpose is prompt-echo detection).

Installation

cargo add prompt-echo

License

MIT