Langflow is a powerful tool for building and deploying AI-powered agents and workflows.
feat: add Mustache template support for prompts (#9876)
* Add MustachePromptModal component for handling Mustache template prompts
- Implement MustachePromptModal component with support for editing and validating Mustache templates.
- Integrate with alert store for success, error, and notice alerts.
- Utilize Mustache library for parsing and highlighting template variables.
- Include UI components like Textarea, Badge, and Button for user interaction.
- Add functionality to handle variable checking and prompt validation via API.
* Add support for Mustache templates in prompt components and modals
- Introduced `MustachePromptModal` for handling Mustache-specific prompts.
- Updated `PromptAreaComponent` to conditionally render `MustachePromptModal` based on the `mustache` prop.
- Enhanced `parameterRenderComponent` to recognize and handle "mustache" type templates.
- Modified `varHighlightHTML` utility to optionally add curly braces around variable names.
- Extended `usePostValidatePrompt` API call to include a `mustache` flag.
- Updated component types to include `mustache` and `addCurlyBraces` options.
* Add mustache and @types/mustache dependencies to frontend package files
* Add support for mustache template format in message schema and input mixin
- Updated `format_text` and `from_template_and_variables` methods to accept a `template_format` parameter, allowing for different template formats.
- Modified `ChatPromptTemplate.from_messages` to include `template_format` parameter.
- Added `MUSTACHE_PROMPT` to the `InputTypes` enum in `input_mixin.py`.
* Add 'mustache' boolean field to API request model in base.py
* Add MustachePromptComponent and enhance prompt validation for mustache templates
- Introduce `MustachePromptComponent` class to create prompt templates with dynamic variables using mustache syntax.
- Add `build_prompt`, `_update_template`, `post_code_processing`, and `_get_fallback_input` methods to handle prompt creation and processing.
- Update `validate_prompt` function in `api_utils.py` to support mustache template variable extraction.
- Import `mustache_template_vars` for handling mustache-specific template variables.
* chore: update package dependencies in package.json and package-lock.json
- Bump @types/mustache from 4.2.5 to 4.2.6
- Add @xyflow/react at version 12.3.6
- Update ace-builds from 1.35.0 to 1.41.0
- Add moment-timezone at version 0.5.48
- Update mustache version to 4.2.0
- Add rehype-raw at version 6.1.1
- Remove unused @napi-rs/nice dependencies from package-lock.json
* feat: add 'mustache' to DIRECT_TYPES in constants.py
* fix: update field_type for template in MustachePromptComponent to MUSTACHE_PROMPT
* feat: add MustachePromptAreaComponent for rendering mustache prompts with enhanced styling and functionality
* refactor: update import paths for common components in mustachePromptModal
* feat: integrate MustachePromptAreaComponent into ParameterRenderComponent for mustache prompt rendering
* test: add comprehensive tests for MustachePromptComponent and template processing
- Introduced integration tests for MustachePromptComponent covering various scenarios including basic functionality, multiple variables, missing variables, and complex logic.
- Added unit tests for Message class to validate mustache template processing, including handling of special characters, lists, and conditional logic.
- Ensured robust coverage for edge cases such as empty templates and missing variables.
* test: add unit tests for ParameterRenderComponent and MustachePromptAreaComponent
- Introduced TypeScript tests for ParameterRenderComponent to validate props interface.
- Added comprehensive tests for MustachePromptAreaComponent focusing on mustache variable highlighting and props validation.
- Ensured robust coverage for various input scenarios, including handling of special characters and complex mustache variables.
* test: refine MustachePromptAreaComponent highlighting logic and add validation tests
- Updated the highlighting logic to only support simple mustache variables ({{variable_name}}) and exclude complex syntax.
- Enhanced unit tests to validate that complex mustache variables, variables with spaces, and invalid characters are not highlighted.
- Added tests for various edge cases, including variables starting with numbers and those containing special operators.
- Ensured comprehensive coverage for the MustachePromptAreaComponent's behavior in handling mustache templates.
* feat: implement secure mustache rendering in Message class
- Added a new utility module for mustache template security, including validation and safe rendering functions.
- Updated the Message class to support mustache template formatting using the new secure renderer.
- Ensured that only simple variable substitutions are allowed in mustache templates to enhance security.
* test: enhance MustachePromptComponent tests for variable handling and security
- Updated tests for MustachePromptComponent to ensure only simple variables are processed and complex syntax is rejected.
- Added new tests for validating mustache templates, including checks for invalid variable names and complex syntax.
- Introduced integration tests for mustache security utilities, ensuring robust validation and safe rendering of templates.
- Enhanced coverage for various edge cases, including nested objects and handling of None values.
* feat: add mustache prompt dialog subtitle and update modal reference
- Introduced a new constant for the mustache prompt dialog subtitle to guide users on using double curly brackets for variable introduction.
- Updated the MustachePromptModal to utilize the new subtitle constant, enhancing clarity and user experience.
* refactor: update display name in MustachePromptComponent for clarity
- Changed the display name from "Mustache Prompt" to "Prompt" to simplify the component's identification and improve user experience.
* refactor: move MustachePromptComponent to lfx
- Introduced MustachePromptComponent to create prompt templates with dynamic variables.
- Updated imports and exports in the processing module to include the new component.
- Implemented methods for building prompts and updating templates, enhancing flexibility in prompt generation.
* refactor: update input variable extraction logic in validate_prompt
- Adjusted the order of input variable extraction in the validate_prompt function to ensure correct handling of Mustache templates.
- Enhanced the process_prompt_template function to accept an is_mustache parameter, improving flexibility in template validation.
* refactor: enhance MustachePromptComponent with template validation and async updates
- Updated imports to reflect the new module structure under lfx.
- Added a validation step for Mustache templates to improve security.
- Refactored the post_code_processing method to an async update_frontend_node method for better performance and compatibility with async workflows.
* refactor: enhance Message class template handling with format support
- Updated the from_template_and_variables and from_template methods to accept a template_format parameter, improving flexibility in template processing.
- Ensured backward compatibility with previous versions while enhancing the functionality for template formatting options.
* feat: add 'mustache' to DIRECT_TYPES in constants
- Introduced 'mustache' as a new type in the DIRECT_TYPES list to support enhanced template processing capabilities.
- This addition aligns with recent updates to template handling and validation in the codebase.
* test: add unit tests for MustachePromptComponent
- Introduced comprehensive unit tests for the MustachePromptComponent, covering template variable extraction, handling of multiple variables, dot notation, and rejection of complex syntax.
- Added async tests for the build_prompt method to ensure correct message generation with various templates and variable scenarios.
- Enhanced test coverage to validate the update_frontend_node method's processing of templates.
* refactor: remove MustachePromptComponent and related tests
- Deleted the MustachePromptComponent from the processing module, streamlining the codebase by removing unused components.
- Removed associated unit tests to maintain consistency and reduce clutter in the test suite.
- Updated imports and exports in the processing module to reflect these changes.
* refactor: enhance PromptComponent with mode selection and template validation
- Updated the PromptComponent to include a mode input for selecting variable syntax, allowing for both Mustache and f-string formats.
- Implemented logic in the update_build_config method to adjust the template field type based on the selected mode.
- Added validation for Mustache templates to ensure security during template processing.
- Refactored the build_prompt and update_frontend_node methods to accommodate the new mode functionality and maintain compatibility with async workflows.
* test: add unit tests for PromptComponent template modes
- Introduced comprehensive unit tests for the PromptComponent, covering both f-string and Mustache modes.
- Validated mode switching, template updates, and prompt building for various scenarios, including handling of multiple variables and rejection of complex syntax.
- Ensured robust testing of the update_build_config and update_frontend_node methods to maintain functionality across different template formats.
* feat: add MustachePromptInput class to support Mustache template processing
- Introduced MustachePromptInput as a subclass of PromptInput, enabling the use of Mustache syntax for prompt generation.
- Updated InputTypes to include MustachePromptInput, enhancing the flexibility of input handling in the codebase.
* refactor: update prompt components to support mode selection and enhanced metadata
- Changed the icon for various prompt components from braces to prompts for better visual representation.
- Updated metadata to include a code hash and dependencies for improved tracking and management.
- Introduced a mode input for selecting variable syntax (f-string or Mustache), enhancing flexibility in template processing.
- Refactored prompt component code to accommodate the new mode functionality, ensuring compatibility with async workflows and maintaining robust template validation.
* feat: add "mustache" to LANGFLOW_SUPPORTED_TYPES in constants
* feat: include mustache flag in post_validate_prompt function
* fix: prevent retries on validation errors in usePostValidatePrompt mutation
* fix: simplify mustache variable validation to only allow simple variable names
* fix: update mustache variable regex to only match simple variable names
* fix: enhance template processing and validation for mustache mode
- Improved handling of template variables when switching modes, ensuring old fields are cleaned up.
- Added error handling during template validation to allow component creation even if validation fails.
- Streamlined the process of re-validating and processing templates to maintain compatibility with existing functionality.
* fix: refine input variable extraction for mustache and f-string templates
- Enhanced the validation process to differentiate between mustache and f-string variables.
- Updated the logic to ensure only relevant variables are retained based on the template syntax.
- Improved error messaging for better clarity on invalid input variables.
* chore: update component index
* test: add unit tests for mustache prompt component functionality
- Implemented tests for mode switching between f-string and mustache syntax.
- Verified that old fields are cleaned up when switching modes.
- Added checks for validation errors and ensured component functionality remains intact.
- Included tests for mixed syntax handling and the absence of connection handles for mustache fields.
* test: remove mustache prompt component unit tests
- Deleted the unit tests for the mustache prompt component, which included functionality for mode switching, validation error handling, and mixed syntax scenarios.
- This cleanup is part of a broader refactor to streamline test coverage and focus on essential components.
* chore: update package-lock.json to add new dependencies and remove unused ones
- Added "@radix-ui/react-radio-group" and "use-stick-to-bottom" dependencies.
- Removed "@smakss/react-scroll-direction" dependency.
- Updated various other dependencies to their latest versions for improved stability and performance.
* test: update mustache security tests for variable naming conventions
- Modified tests to use underscore notation for variable names instead of dot notation, ensuring compliance with the updated validation rules.
- Removed tests for dot notation and nested object properties, which are no longer supported.
- Added new tests for rendering with multiple variables and underscore variable names, enhancing coverage for the updated functionality.
* update component index
* test: update mustache template processing tests
- Removed tests for dot notation and nested object properties, aligning with the updated validation rules.
- Modified existing tests to ensure dot notation is rejected, enhancing security checks for mustache templates.
- This update streamlines the test suite to focus on supported variable naming conventions.
* test: remove mustache prompt integration and unit tests
- Deleted integration and unit tests for the MustachePromptComponent, including various scenarios for template processing and variable handling.
- This cleanup is part of an effort to streamline the test suite and focus on essential components, aligning with recent changes in validation rules and functionality.
* test: refine mustache template variable regex in tests
- Updated the regex in the MustachePromptAreaComponent tests to only match simple mustache variables, removing support for complex syntax.
- This change aligns with the recent updates to validation rules and enhances the clarity of the test cases.
* test: update mustache prompt component tests for variable highlighting
- Modified tests to ensure that complex mustache syntax is not highlighted, aligning with the updated validation rules.
- Renamed a test to clarify that dot notation variables should not be highlighted, reflecting the current functionality.
- These changes enhance the accuracy and clarity of the test cases for mustache template processing.
* refactor: update addLegacyComponents function to improve selector checks
- Replaced the expect assertion with a waitForSelector call to ensure the sidebar legacy switch is checked, enhancing reliability in tests.
- Updated import statement for Page from "@playwright/test" for consistency with current practices.
* fix playwright imports
* fix: Add missing newline at end of package.json and correct syntax in test utility functions
* fix: Update placeholder text and prompt dialog subtitle in Mustache component
* feat: Enhance PromptComponent to support Mustache syntax and dynamic template updates
* test: Add tests for double brackets toggle in Prompt component
- Add Playwright E2E tests for double brackets variable extraction
- Add Python unit tests for use_double_brackets BoolInput
- Test single and multiple variable extraction with {{var}} syntax
- Verify toggle persistence and input field creation
* chore: Update starter projects with use_double_brackets field
Update all starter project templates to include the new
use_double_brackets field in Prompt components
* chore: Update package-lock.json to reflect dependency changes
* [autofix.ci] apply automated fixes
* Fix: enhance mustache security by adding triple braces pattern and improving safe rendering documentation
* Fix: add logging for template validation failures in PromptComponent
* Fix: update mustache interface to make 'mustache' optional and ensure default value is false; add mustache security utilities for template validation
* Fix: improve error handling in validate_prompt for mustache template parsing
* Fix: refactor variable extraction in MustachePromptModal for improved regex matching and state management
* chore: update package-lock.json to add peer dependencies and remove unused packages
- Added peer: true to several dependencies to indicate peer dependency requirements.
- Removed unused dependencies related to @napi-rs/nice and its variants.
* feat: add unit tests for MustachePromptAreaComponent and MustachePromptModal
* update package lock
* update package lock
* [autofix.ci] apply automated fixes
* update index
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> G
Gabriel Luiz Freitas Almeida committed
7c19477bc223464b8ff5893de93fb75741d18e78
Parent: 02cacd7
Committed by GitHub <[email protected]>
on 1/8/2026, 2:59:47 PM