Node Details

  • Name: fewShotPromptTemplate
  • Type: FewShotPromptTemplate
  • Version: 1.0
  • Category: Prompts

Base Classes

  • FewShotPromptTemplate
  • BasePromptTemplate

Parameters

Inputs

  1. Examples (Required)
    • Type: string (JSON)
    • Description: Array of example objects with key-value pairs
    • Example:
      [
        { "word": "happy", "antonym": "sad" },
        { "word": "tall", "antonym": "short" }
      ]
      
  2. Example Prompt (Required)
    • Type: PromptTemplate
    • Description: Template for formatting individual examples
  3. Prefix (Optional)
    • Type: string
    • Description: Text appearing before the examples
    • Example: “Give the antonym of every input”
  4. Suffix (Required)
    • Type: string
    • Description: Text after examples, containing input variable
    • Example: “Word: \nAntonym:”
  5. Example Separator (Optional)
    • Type: string
    • Default: “\n\n”
    • Description: String used to separate examples
  6. Template Format (Optional)
    • Type: options
    • Options: [“f-string”, “jinja-2”]
    • Default: “f-string”
    • Description: Format style for template strings

Functionality

  1. Example Processing
    • JSON parsing
    • Example formatting
    • Template application
    • Separator handling
  2. Template Management
    • Format selection
    • Variable extraction
    • Context building
    • Structure validation

Use Cases

  1. Pattern Teaching
    • Response formatting
    • Style demonstration
    • Behavior guidance
    • Context setting
  2. Complex Tasks
    • Multi-step processes
    • Format standardization
    • Response structuring
    • Pattern recognition

Integration Notes

  • Uses @langchain/core/prompts
  • Supports multiple example formats
  • Handles variable extraction
  • Manages template formatting

Best Practices

  1. Example Design
    • Clear demonstrations
    • Consistent formatting
    • Diverse examples
    • Progressive complexity
  2. Template Structure
    • Compatible formats
    • Clear separators
    • Proper variables
    • Consistent style
  3. Performance Optimization
    • Efficient examples
    • Minimal redundancy
    • Clear instructions
    • Optimal spacing