Class ArgumentsRewriteNoteTemplates

java.lang.Object
dev.langchain4j.internal.ArgumentsRewriteNoteTemplates

public final class ArgumentsRewriteNoteTemplates extends Object
Renders and checks the template of the arguments rewrite note of ToolInputGuardrailsConfig: the one place that knows the names of its variables.
Since:
1.25.0
  • Method Details

    • render

      public static UnaryOperator<String> render(PromptTemplate template, String changedArguments)
      Renders the note, once: the date and time variables of the template keep their value for every result the note is put into. The variables are filled in one pass, so {{arguments}} or {{result}} in the arguments or in the result stay as they are. The text may be empty: a template with no text of its own around {{result}} gives the text of the result as is, also when it is empty.
      Parameters:
      template - the template of the note
      changedArguments - the changed arguments, as a JSON object
      Returns:
      the function that gives the text the LLM gets for the text of a result of the tool
    • ensureValid

      public static PromptTemplate ensureValid(PromptTemplate template)
      Checks that the template renders with the variables of the note, and that the text it renders contains the result of the tool, so that a bad template fails before a tool runs rather than after it.
      Parameters:
      template - the template to check
      Returns:
      the template
      Throws:
      IllegalArgumentException - if the template is null, uses a variable other than {{arguments}}, {{result}} and the date and time variables of PromptTemplate, cannot be rendered, or leaves out {{result}}