Functionality
The Replace Words in Response node acts as a text transformer, finding and replacing specified patterns in your LLM responses. This can be useful for:- Response Formatting: Standardize output formats and styling
- Content Filtering: Remove or modify unwanted content patterns
- Brand Consistency: Ensure consistent terminology in responses
- Data Transformation: Convert units or standardize numerical formats
- Response Sanitization: Clean up or modify AI-generated content
Node Properties
For each replacement rule you add, you can configure:- Find:
- Text to Find: The pattern or text to search for in the response
- Use Regex: Toggle to enable regular expression pattern matching
- Case Sensitive: Toggle to make the pattern matching case sensitive
- Replace:
- Replacement Text: The text to insert in place of matched content
You can add multiple replacement rules using the “Add a Replacement” button. Rules are applied sequentially in the order they are defined.
Usage Examples
Scenario: Response Standardization
Let’s say you want to ensure consistent terminology in AI responses:- Add a Replace Words in Response node after your LLM node
- Add multiple replacements:
- Find: “AI assistant”, Replace: “Virtual Assistant”
- Find: “artificial intelligence”, Replace: “AI”
- Find: “I think”, Replace: “Based on the available information”
- Enable “Case sensitive” where appropriate
- This helps maintain consistent branding and professional tone in responses
Scenario: Response Sanitization
Let’s say you want to remove or mask sensitive information that the LLM might inadvertently include:- Add a Replace Words in Response node after your LLM node
- Enable “Use regex”
- Configure a replacement:
- Find:
/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}/
- Replace: “[REDACTED EMAIL]”
- Find:
- This will replace any email addresses in the response with “[REDACTED EMAIL]“
Tips and Best Practices
- Place this node immediately after LLM nodes to process their outputs
- Order your replacements carefully as they are applied sequentially
- Use regex for complex pattern matching needs
- Test replacements with various response types to ensure desired outcomes
- Consider case sensitivity requirements for your use case
- Monitor replaced content to ensure accuracy
- Keep replacement rules simple and focused for better maintenance
- Regularly review and update rules as LLM response patterns evolve