Overview
PostProcessor allows you to modify or enhance AI-generated responses before they’re sent to users. Use postprocessors to add disclaimers, format output, inject dynamic content, or apply branding.
Response postprocessing for formatting, branding, and enhancement. Use with LuaAgent.
Streaming Support: PostProcessors now execute on both streaming and non-streaming requests. For streaming, post-processors run after the stream completes and emit a
postprocess-complete event. See Channel Compatibility for details.Use Cases
Disclaimers
Add legal or informational disclaimers
Formatting
Apply consistent formatting and styling
Branding
Add company branding or signatures
Dynamic Content
Inject user-specific information
Constructor
new PostProcessor(config)
Creates a new response postprocessor.PostProcessorConfig
required
Postprocessor configuration object
Configuration Parameters
Required Fields
string
required
Postprocessor description for documentation
function
required
Function that processes AI responsesSignature:
(user: UserDataInstance, message: string, response: string, channel: string) => Promise<PostProcessorResponse>Parameters:user- User data instance with profile and custom datamessage- Original user message (string)response- AI-generated response to modifychannel- Channel identifier (e.g., ‘whatsapp’, ‘web’, ‘api’)
Recommended: Use the Lua Runtime API instead of the function parameters:
- User:
User.get()to retrieve the current user - Channel:
Lua.request.channelfor the current channel - Webhook:
Lua.request.webhook?.payloadfor raw webhook data (WhatsApp, Slack, Teams, etc.)
Optional Fields
string
Unique postprocessor name. Defaults to
'unnamed-postprocessor' if not provided.Examples: 'add-disclaimer', 'format-response'number
default:"0"
Execution priority. Lower numbers run first. Use this to control the order when you have multiple postprocessors (e.g. translate before adding disclaimers).
boolean
default:"false"
When
true, the postprocessor runs asynchronously — the agent’s response is sent to the user immediately and the postprocessor runs in the background. Use for non-blocking side effects (analytics, audit logs) where the user shouldn’t wait.When false (default), the response is held until the postprocessor returns, allowing it to mutate the text before delivery.PostProcessorResponse
Your execute function must return:The response object only contains
modifiedResponse. The modified response becomes the input for the next postprocessor in the chain.Complete Examples
Add Legal Disclaimer
Add Company Branding
Format Response
Add User-Specific Context
Add Call-to-Action
Translation Wrapper
Sentiment Adjuster
Link Enricher
Using with LuaAgent
Postprocessors are added to your agent configuration:Postprocessors execute in order of their priority value (lowest first). Priority is set when creating the postprocessor via the API. If not specified, default priority is 100.
Execution Flow
Best Practices
✅ Chain Postprocessors Thoughtfully
✅ Chain Postprocessors Thoughtfully
Order matters - structure flows logically
✅ Preserve Original Meaning
✅ Preserve Original Meaning
Don’t alter the core message
✅ Handle Errors Gracefully
✅ Handle Errors Gracefully
Fall back to original response on errors
✅ Keep Processing Fast
✅ Keep Processing Fast
Postprocessors should be quick (< 50ms)Avoid heavy computations or external API calls when possible.
Testing Postprocessors
Common Patterns
Conditional Processing
Regex Replacements
Markdown Formatting
Related APIs
PreProcessor
Process messages before agent
LuaAgent
Agent configuration
User API
Access user data
Data API
Store and retrieve data
See Also
- PreProcessor - Processing incoming messages
- LuaAgent - Adding postprocessors to your agent
- Workflows Concept

