Debugging your rules.py
Power user
Debugging your rules
When a rule isn't firing, work through this checklist.
1. Did you save?
Sounds obvious. Open Dashboard → Rules, scroll to the bottom, and confirm there's a green "Saved" indicator. The bot doesn't pick up unsaved changes.
2. Test from a clean session
If you're testing in Test bots or the live widget, the bot may be answering from session context. Open an incognito window and start a brand new conversation.
3. Check the order
Rules run top-to-bottom. The first return wins. If two rules could match the same message, only the upper one fires.
4. Print to debug
You can use print() inside respond() — output goes to the bot's log. View it in Dashboard → Bot status → View logs.
def respond(message, context):
msg = message.lower()
print(f"[rule] received: {msg!r}")
if "hours" in msg:
print("[rule] hours rule matched")
return "Mon-Fri 9-6."
print("[rule] no rule matched, falling through to LLM")
return None
5. Watch out for case sensitivity
"Hours" won't match if "hours" in msg. Always lowercase the input first:
msg = message.lower().strip()
6. Watch out for whitespace and punctuation
"hours?" includes a ?. "hours " has a trailing space. Strip and normalise:
import string
msg = message.lower().strip()
clean = msg.translate(str.maketrans("", "", string.punctuation))
7. Common syntax errors
- Missing colon after
def respond(...)— Python won't parse it. - Mismatched indentation — use 4 spaces, not tabs, and don't mix.
- Quotes — don't use curly quotes (" "). Use straight ASCII quotes (").
- Always return something — even if it's
None. Falling off the end without a return raises an error.
8. Test in isolation
Want to be sure your regex or condition is correct? Strip the rule down to one test case:
def respond(message, context):
return f"DEBUG echo: you said {message!r}"
Save, send messages — every reply will be that debug string. You know rules are running. Then build back up.
9. Still stuck?
Open a support ticket from Dashboard → Support and paste your rules.py. We'll look at it.