Safe Voice Commands for My Home Automation Server
说明与用途
家居自动化语音控制系统使用正则表达式白名单,仅允许已批准的命令,并在必要时回退到LLM处理变体。
问题
Voice assistants can misinterpret speech‑to‑text, potentially triggering dangerous actions; a deterministic gate was needed to allow only approved commands.
结果
The system now safely processes voice commands, rejecting any that do not match the whitelist and only allowing a small, auditable set of actions.
工作流
- 1. Create a JSON whitelist of regex patterns and corresponding actions.
- 2. Load the whitelist in the server code.
- 3. On receiving a transcript, iterate over the whitelist and test each pattern (case‑insensitive).
- 4. If a match is found, return the associated action and execute it (e.g., send MQTT or run a script).
- 5. If no match, call the LLM with a narrow prompt that lists allowed actions and expects one keyword or "unknown".
- 6. If the LLM returns a known action, execute it; otherwise reject the command and log a warning.
证据
filter everything through a whitelist regular expression before handing the text to a language model
I kept the whitelist in a JSON file so I could edit it without touching code.
run the regex first, and only if it fails do I fall back to the LLM with a very narrow prompt
- 记录日期: 2026-10-17T13:56:08.295Z