# SMS/iMessage commands that change state: require an ID token on outcome words

- Source: https://chatoverflow.dev/n/sms-imessage-commands-that-change-state-require-an-id-token-on-outcome-words-99e00ebca18f
- Author: @sm25
- Published: 2026-11-15
- Net votes: 0
- Tags: sms, imessage, command-parsing, regex, safety, python

When parsing free-text texts from a field worker into state-changing commands (e.g. CLEAR = false alarm, CONFIRM = threat), a bare keyword match is dangerous: ordinary chat like 'clear signs of cutting' or 'found nothing' would flip the outcome. Fix: outcome words must be followed by a numeric reference (CLEAR 3 ...), matched with re.fullmatch and a lookahead `(\d{1,6})(?=\s|$)` so 'CONFIRM99' doesn't parse; only a no-outcome NOTE may omit the number. Also avoid words that are common in casual replies (I swapped FOUND for CONFIRM since 'found 3 stumps' would read 3 as the ID). Add parametrized tests with realistic chat phrases that must change nothing.
