The Replace Words in Prompt node allows you to define multiple find-and-replace rules to modify your prompts. Each replacement can use either plain text or regex patterns, with support for case-sensitive matching.
Functionality
The Replace Words in Prompt node acts as a text transformer, finding and replacing specified patterns in your prompts. This can be useful for:
- Variable Substitution: Replace placeholders with actual values
- Content Standardization: Ensure consistent terminology across prompts
- Text Sanitization: Remove or replace unwanted content patterns
- Dynamic Content: Modify prompts based on workflow context
- Prompt Templating: Maintain templates with replaceable sections
Node Properties
For each replacement rule you add, you can configure:
- Find:
- Text to Find: The pattern or text to search for in the prompt
- 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: Acronym Expansion
Let’s say you want to expand industry-specific acronyms to make prompts more clear:
- Add a Replace Words in Prompt node before your LLM node
- Add multiple replacements:
- Find: “ML”, Replace: “Machine Learning”
- Find: “NLP”, Replace: “Natural Language Processing”
- Find: “CV”, Replace: “Computer Vision”
- Enable “Case sensitive” for each to avoid replacing lowercase instances
- This will convert technical text like “ML and NLP techniques in CV” to “Machine Learning and Natural Language Processing techniques in Computer Vision”
Scenario: Content Redaction
Let’s say you want to redact sensitive information from prompts:
- Add a Replace Words in Prompt node before your LLM node
- Enable “Use regex”
- Configure a replacement:
- Find:
\b\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b
- Replace: “[REDACTED CREDIT CARD]”
- This will replace credit card numbers like “4111-1111-1111-1111” or “4111 1111 1111 1111” with “[REDACTED CREDIT CARD]“
Tips and Best Practices
- Order your replacements carefully as they are applied sequentially
- Use regex for complex pattern matching needs
- Test replacements with various prompt inputs to ensure desired outcomes
- Consider case sensitivity requirements for your use case
- Verify that replacements don’t introduce unintended side effects
- Keep replacement rules simple and focused for better maintenance
Responses are generated using AI and may contain mistakes.