Skip to contents

This object is used to send feedback to a LLM when a LLM reply does not succesfully pass an extraction or validation function (as handled by send_prompt() and passed with tidyprompt() and prompt_wrap()). The feedback text is sent back to the LLM. The extraction or validation function should then return this object with the feedback text that should be sent to the LLM.

Usage

llm_feedback(text, tool_result = FALSE)

Arguments

text

A character string containing the feedback text. This will be sent back to the LLM after not passing an extractor or validator function

tool_result

A logical indicating whether the feedback is a tool result. If TRUE, it will be handled differently by send_prompt(), by presenting the text as a 'system' message. This ensures it will not be filtered out when cleaning the context window in send_prompt()

Value

An object of class "llm_feedback" containing the feedback text

See also

Other prompt_wrap: llm_break(), prompt_wrap()

Other prompt_evaluation: llm_break(), send_prompt()

Examples

# Example usage within a validation function similar to the one in 'answer_as_integer()':
validation_fn <- function(x, min = 0, max = 100) {
  if (x != floor(x)) { # Not a whole number
    return(llm_feedback(
      "You must answer with only an integer (use no other characters)."
    ))
  }
  if (!is.null(min) && x < min) {
    return(llm_feedback(glue::glue(
      "The number should be greater than or equal to {min}."
    )))
  }
  if (!is.null(max) && x > max) {
    return(llm_feedback(glue::glue(
      "The number should be less than or equal to {max}."
    )))
  }
  return(TRUE)
}

# This validation_fn would be part of a prompt_wrap()