What are PreProcessors?
PreProcessors intercept user messages before they reach your AI agent. They act as a middleware layer, allowing you to filter spam, validate inputs, route messages, or modify content before the agent processes it.Think of it as:
A security checkpoint and enrichment station - messages pass through preprocessors before reaching your agent’s brain.
New in v3.0.0: Message preprocessing for content filtering, routing, and validation.
Why PreProcessors?
PreProcessors handle “meta” tasks that shouldn’t consume your agent’s context window or reasoning capabilities.Content Filtering
Block spam, profanity, or inappropriate content before it costs you tokens.
Input Validation
Ensure messages meet requirements (e.g., “must include an email”) before the agent sees them.
Context Injection
Fetch data from a CRM or database and append it to the user’s message.
Rate Limiting
Prevent abuse by limiting message frequency per user.
PreProcessors vs Skills
| Feature | PreProcessor | Skill |
|---|---|---|
| Timing | Runs before the agent thinks | Runs when the agent decides to call it |
| Decision | Deterministic (code-based) | Probabilistic (LLM-based) |
| Use Case | Security, formatting, required context | Actions, data retrieval, business logic |
| Access | Can block the agent completely | Cannot block, returns data to agent |
How PreProcessors Work
1
User Sends Message
User types a message (e.g., “Check my order status”) via WhatsApp, Web, or API.
2
Pipeline Execution
The system runs your active PreProcessors in order of priority (lowest first).
3
Transformation & Decision
Each preprocessor receives the output of the previous one. It can:
- ✅ Proceed: Pass the (potentially modified) message to the next step.
- ❌ Block: Stop the pipeline and return a response immediately.
4
Agent Handover
If no preprocessor blocks, the final message reaches the AI agent.
Simple Example
Here is a simple profanity filter that runs early in the pipeline.Tip: You can also access the channel via
Lua.request.channel, the user via User.get(), and raw webhook data via Lua.request.webhook?.payload. See the Lua API for details.Advanced Patterns
Context Injection (RAG Lite)
You can use a preprocessor to fetch user data and “inject” it into the message, giving the agent context without it needing to ask tools.Channel-Specific Logic
You can apply different rules based on where the user is chatting from.Execution Pipeline
PreProcessors run in a pipeline. The output of one preprocessor becomes the input of the next.- Priority 10:
RateLimiterchecks if user is spamming. - Priority 20:
ProfanityFilterchecks for bad words. - Priority 50:
ContextInjectoradds user account info. - Agent: Receives a clean, verified, and context-rich message.
Adding to Your Agent
Add preprocessors to yourLuaAgent configuration.

