Menu

Turning spoken commands into safe actions: regex first, the language model second
📰

Turning spoken commands into safe actions: regex first, the language model second

DEV Community: nlp·the bomber·3 days ago
#5vMB2nl7
#devtonlp#devto#dev#command#const
Reading 0:00
15s threshold

Introduction

I built a tiny voice‑controlled home automation server for my own website. The goal was simple: speak a command, have the server execute a safe action (turn a light on, start a backup, etc.). The tricky part is making sure the spoken text can’t be turned into an arbitrary shell command. My solution is a two‑step filter – a strict regular‑expression whitelist first, then a language‑model (LLM) to fill in the details.

Why regex first?

Regular expressions give me a deterministic gate. Anything that doesn’t match a known pattern is rejected before it ever reaches the LLM. This prevents prompt injection attacks where a user tries to sneak a malicious instruction into the natural‑language prompt.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.