Strip Russian translate command before the LLM - #56
Merged
Conversation
Reported: dictating in Russian with translate-to-English on, ending with
"переведи на английский", left the command in the output (e.g.
"Hello everyone! Please translate this into English!").
Root cause (confirmed with a one-shot debug log on the real path): whisper
renders the spoken command in RUSSIAN ("Всем привет! Пожалуйста, переведи на
английский!"). MetaInstructionStripper only matched English phrasings, so the
strip was a no-op and the full text — command included — went to the LLM. The
model then treats the command as content and "executes" it, baking the
instruction into the translated English output. So the fix must strip BEFORE the
LLM (a post-LLM strip wouldn't reliably work — the phrase dissolves into the
translation).
Earlier PRs only fixed the English-input case, which is why this persisted.
- MetaInstructionStripper: add Russian patterns (переведи/переведите/переводи
[это|текст|...] на <язык>; bare "на <язык>"; object-only form) and Russian
politeness lead-ins ("пожалуйста", "будьте добры", "будь добр[а]") + trailing
"пожалуйста". Kept narrow: requires the "на <язык>" directive, so ordinary text
like "учу английский язык" is untouched, and a command with no preceding
content is left intact (never empties the text).
- Tests: +6 covering both real transcripts from the bug, object-word form,
command-only (no-op), and the "mentions a language" non-match. 171 -> 177.
swift test 177/177; ./build.sh clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reported: dictating in Russian with translate-to-English on, ending with «переведи на английский», left the command in the output — e.g.
Hello everyone! Please translate this into English!.Root cause (confirmed via debug log on the real path)
whisper renders the command in Russian, but
MetaInstructionStripperonly matched English → no strip → the whole text reached the LLM, which executed the instruction and baked it into the translation. Earlier PRs only covered English input. The fix strips before the LLM.Changes
MetaInstructionStripper: Russian command patterns (переведи/переведите/переводи … на <язык>, bareна <язык>, object-only) + Russian politeness lead-ins / trailingпожалуйста. Kept narrow (requiresна <язык>; «учу английский язык» untouched; command-only left intact; terminal punctuation preserved).swift test177/177 ·./build.shclean. (Temporary debug NSLog removed.)🤖 Generated with Claude Code