A specialized node for creating structured chat prompts with system messages, human messages, and optional message history, enabling dynamic and context-aware conversations with Language Models.
Name: chatPromptTemplate
Type: ChatPromptTemplate
Version: 2.0
Category: Prompts
ChatPromptTemplate
BasePromptTemplate
System Message (Required)
Type: string
Description: Initial system message that sets the context or role for the AI
Example: "You are a helpful assistant that translates {input_language} to {output_language}."
Human Message (Required)
Type: string
Description: Human message prompt added at the end of the message sequence
Example: “{text}
”
Format Prompt Values (Optional)
Type: JSON
Description: Variables specification for use in prompts
Example:
Messages History (Optional)
Type: Tabs
Default: messageHistoryCode
Description: Additional messages after System Message for few-shot examples
Tabs:
Add Messages (Code)
Type: code
Description: Custom message history using JavaScript code
Message Management
System message handling
Human message formatting
History integration
Variable substitution
Template Processing
Dynamic execution
Code sandboxing
Context building
Error handling
Conversational AI
Customer service
Language translation
Task assistance
Knowledge base queries
Context Management
Role definition
Few-shot learning
Conversation history
Dynamic responses
Uses @langchain/core/prompts
Supports JavaScript execution
Handles JSON parsing
Implements sandboxed environments
System Message Design
Clear instructions
Specific role definition
Consistent context
Appropriate constraints
Message History
Relevant examples
Progressive complexity
Clear structure
Safe code execution
Variable Management
Clear naming
Type consistency
Error handling
Default values
The node takes in the defined parameters (system message, human message, prompt values, and optional message history).
If message history code is provided, it is executed in a sandboxed environment.
The node outputs a ChatPromptTemplate
object that includes:
A system message
Optional message history (if provided and valid)
A human message
This node is used to create structured chat prompts for language models. It’s particularly useful for:
Setting up consistent system instructions across multiple interactions.
Defining a standard format for human inputs.
Incorporating few-shot examples or specific conversation context through the message history feature.
Allowing for dynamic prompt creation by using variables in the system and human messages.
The node uses the @langchain/core/prompts
library to create the chat prompt template.
It supports dynamic execution of JavaScript code for creating custom message histories.
The node handles JSON parsing for prompt values, allowing for variable substitution in the prompts.
Error handling is implemented for invalid JSON or message history code execution.
The message history feature uses a sandboxed VM for executing user-provided code, ensuring safety and isolation.
The node is designed to be flexible, allowing for both simple prompt creation and more complex setups with custom message histories.
It integrates with a database (likely for storing or retrieving additional context), as indicated by the use of DataSource
and IDatabaseEntity
.