Interface PromptTemplate


public interface PromptTemplate
Interface for prompt templates with variable substitution.

Prompt templates allow externalized prompt management with support for variables, partials, and versioning.

Usage


 // Load from registry
 PromptTemplate template = PromptRegistry.get("agents/reviewer");

 // Render with variables
 String prompt = template.render(Map.of(
     "task", "Review this code for security issues",
     "context", codeSnippet
 ));

 // Check metadata
 System.out.println("Version: " + template.getSpec().version());
 
  • Method Details

    • getName

      String getName()
      Gets the template name/identifier.
      Returns:
      template name
    • getContent

      String getContent()
      Gets the raw template content before variable substitution.
      Returns:
      raw template content
    • render

      String render(Map<String,Object> variables)
      Renders the template with the given variables.
      Parameters:
      variables - map of variable names to values
      Returns:
      rendered prompt string
    • render

      default String render()
      Renders the template with no variables.
      Returns:
      rendered prompt string
    • getVariables

      Set<String> getVariables()
      Gets the set of variable names used in this template.
      Returns:
      set of variable names
    • getSpec

      PromptSpec getSpec()
      Gets the template metadata.
      Returns:
      metadata
    • hasAllVariables

      default boolean hasAllVariables(Map<String,Object> variables)
      Returns whether all required variables are provided.
      Parameters:
      variables - the provided variables
      Returns:
      true if all required variables are present
    • validateVariables

      default void validateVariables(Map<String,Object> variables)
      Validates that all required variables are provided.
      Parameters:
      variables - the provided variables
      Throws:
      PromptException - if required variables are missing