Skip to contents

This object is used to break a extraction and validation loop in a prompt_wrap() evaluated by send_prompt(). When an extraction or validation function returns this object, the loop will be broken and no further extraction or validation functions are applied; instead, send_prompt() will be able to return the result at that point. This may be useful in scenarios where it is determined the LLM is unable to provide a response to a prompt.

Usage

llm_break(object_to_return = NULL, success = FALSE)

Arguments

object_to_return

The object to return as the response result from send_prompt() when this object is returned from an extraction or validation function.

success

A logical indicating whether the send_prompt() loop break should nonetheless be considered as a successful completion of the extraction and validation process. If FALSE, the object_to_return must be NULL (as the response result of send_prompt() will always be 'NULL' when the evaluation was unsuccessful); if FALSE, send_prompt() will also print a warning about the unsuccessful evaluation. If TRUE, the object_to_return will be returned as the response result of send_prompt() (and send_prompt()) will print no warning about unsuccessful evaluation).

Value

An object of class "llm_break"

See also

Other prompt_wrap: llm_feedback(), prompt_wrap()

Other prompt_evaluation: llm_feedback(), send_prompt()

Examples

# Example usage within an extraction function similar to the one in 'quit_if()':
extraction_fn <- function(x) {
  quit_detect_regex <- "NO ANSWER"

  if (grepl(quit_detect_regex, x)) {
      return(llm_break(
        object_to_return = NULL,
        success = TRUE
      ))
  }

  return(x)
}

# This extraction_fn would be part of a prompt_wrap()