langchain.output_parsers.boolean.BooleanOutputParser

Note

BooleanOutputParser implements the standard Runnable Interface. 🏃

class langchain.output_parsers.boolean.BooleanOutputParser[source]

Bases: BaseOutputParser[bool]

Parse the output of an LLM call to a boolean.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param false_val: str = 'NO'

The string value that should be parsed as False.

param true_val: str = 'YES'

The string value that should be parsed as True.

async aparse(text: str) T

Parse a single string model output into some structure.

Parameters

text (str) – String output of a language model.

Returns

Structured output.

Return type

T

async aparse_result(result: List[Generation], *, partial: bool = False) T

Parse a list of candidate model Generations into a specific format.

The return value is parsed from only the first Generation in the result, which

is assumed to be the highest-likelihood Generation.

Parameters
  • result (List[Generation]) – A list of Generations to be parsed. The Generations are assumed to be different candidate outputs for a single model input.

  • partial (bool) –

Returns

Structured output.

Return type

T

get_format_instructions() str

Instructions on how the LLM output should be formatted.

Return type

str

parse(text: str) bool[source]

Parse the output of an LLM call to a boolean.

Parameters

text (str) – output of a language model

Returns

boolean

Return type

bool

parse_result(result: List[Generation], *, partial: bool = False) T

Parse a list of candidate model Generations into a specific format.

The return value is parsed from only the first Generation in the result, which

is assumed to be the highest-likelihood Generation.

Parameters
  • result (List[Generation]) – A list of Generations to be parsed. The Generations are assumed to be different candidate outputs for a single model input.

  • partial (bool) –

Returns

Structured output.

Return type

T

parse_with_prompt(completion: str, prompt: PromptValue) Any

Parse the output of an LLM call with the input prompt for context.

The prompt is largely provided in the event the OutputParser wants to retry or fix the output in some way, and needs information from the prompt to do so.

Parameters
  • completion (str) – String output of a language model.

  • prompt (PromptValue) – Input PromptValue.

Returns

Structured output

Return type

Any