← Back to docs

Using the rules.py file

Advanced

Hard-coded answers and guardrails

The rules file gives you three Python hooks to control bot behaviour:

pre_filter(message, context)

Runs before the LLM. Return a string to short-circuit (great for opening hours, refund policy, etc). Return None to let the LLM answer.

post_filter(message, response, context)

Runs after the LLM. Use this to sanitise output, append disclaimers, or redact info.

system_prompt(context)

Returns the bot's personality. Edit this to set tone, language style, and behaviour rules.

def pre_filter(message, context):
    if "refund" in message.lower():
        return "Our refund policy: 30 days, no questions asked."
    return None