Skip to content

feat: STT prompt injection configurable via STT_PROMPT_INJECTION#25

Open
ysslang wants to merge 1 commit intogrinev:mainfrom
ysslang:fix/stt-prompt-injection
Open

feat: STT prompt injection configurable via STT_PROMPT_INJECTION#25
ysslang wants to merge 1 commit intogrinev:mainfrom
ysslang:fix/stt-prompt-injection

Conversation

@ysslang
Copy link
Contributor

@ysslang ysslang commented Mar 1, 2026

Description

This PR addresses an issue where Speech-to-Text (STT) transcriptions often contain homophone or phonetic errors, causing the LLM to misinterpret user intent, especially in Chinese/multilingual scenarios.

By introducing a new environment variable STT_PROMPT_INJECTION, a system prompt is dynamically injected before the transcribed text when communicating with the LLM provider. This instructs the model to anticipate phonetic inaccuracies and infer intent based on context.

Changes Made

  • Added STT_PROMPT_INJECTION to config.stt schema in src/config.ts.
  • Updated .env.example with usage instructions.
  • Modified src/bot/handlers/voice.ts to conditionally prefix textForLLM while keeping the original UI transcription message untouched.

Configuration Behaviors

  • Missing / false / 0: (Default) Feature disabled. STT output is untouched (backward compatible).
  • true / 1: Feature enabled using the built-in English system prompt.
  • Any other string: Feature enabled using the string provided as a custom system prompt.

@grinev
Copy link
Owner

grinev commented Mar 1, 2026

@ysslang thanks for this PR. I think it is useful feature.
I have a few change requests before merge:

  1. Please remove the hardcoded default prompt from the code.
    The default text should be defined in .env.example, so users can uncomment it and use it as-is or edit it.
    In config, keep only the prompt text value. In code, wrap it as [Note: ].
  2. Please rename STT_PROMPT_INJECTION to something like SST_NOTE_PROMT.
    The phrase “prompt injection” sounds risky/security-related, but this feature is just a helper note for STT quality.
  3. Please add a debug log when the note is added to the LLM prompt, so we can clearly see that [Note: ...] was applied.
  4. About tests: after simplifying SST_NOTE_PROMT logic, please add only necessary tests.
    At minimum, we should cover:
    • note is added when SST_NOTE_PROMT is set
    • note is not added when it is empty or disabled
  5. Please update README with the new env variable and short behavior description.

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.

2 participants