Skip to main content

scorebook.utils.build_prompt

Module for building prompt strings using Jinja2 templating.

Provides functionality to render prompts from templates with custom filters and global variables, using strict undefined handling for better error detection.

build_prompt

def build_prompt(prompt_template: str,
prompt_args: Dict[str, Any],
filters: Optional[Dict[str, Any]] = None,
globals_dict: Optional[Dict[str, Any]] = None) -> str

Build a prompt string from a template and arguments.

Arguments:

  • prompt_template - Jinja2 template string
  • prompt_args - Dictionary of arguments to pass to the template
  • filters - Dictionary of Jinja2 filters. Defaults to default_jinja_filters().
  • globals_dict - Dictionary of global functions/variables. Defaults to default_jinja_globals().

Returns:

  • str - Rendered prompt string