Skip to content

Strip Russian translate command before the LLM - #56

Merged
initcore0 merged 1 commit into
mainfrom
fix/strip-russian-translate-command
Jun 24, 2026
Merged

Strip Russian translate command before the LLM#56
initcore0 merged 1 commit into
mainfrom
fix/strip-russian-translate-command

Conversation

@initcore0

Copy link
Copy Markdown
Owner

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)

raw        = "Всем привет! Пожалуйста, переведи на английский!"
afterStrip = "Всем привет! Пожалуйста, переведи на английский!"   ← strip was a no-op
LLM returned = "Hello everyone! Please translate this into English!"

whisper renders the command in Russian, but MetaInstructionStripper only 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).
  • +6 tests incl. both exact transcripts from the bug. 171 → 177.

swift test 177/177 · ./build.sh clean. (Temporary debug NSLog removed.)

🤖 Generated with Claude Code

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>
@initcore0
initcore0 merged commit 4568528 into main Jun 24, 2026
3 checks passed
@initcore0
initcore0 deleted the fix/strip-russian-translate-command branch June 24, 2026 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant