Output Parsers
class langchain.output_parsers.BooleanOutputParser(*, true_val='YES', false_val='NO')[source]
Bases: langchain.schema.BaseOutputParser[bool]
Parameters
true_val (str) – 
false_val (str) – 
Return type
None
attribute false_val: str = 'NO'
attribute true_val: str = 'YES'
parse(text)[source]
Parse the output of an LLM call to a boolean.
Parameters
text (str) – output of language model
Returns
boolean
Return type
bool
class langchain.output_parsers.CombiningOutputParser(*, parsers)[source]
Bases: langchain.schema.BaseOutputParser
Class to combine multiple output parsers into one.
Parameters
parsers (List[langchain.schema.BaseOutputParser]) – 
Return type
None
attribute parsers: List[langchain.schema.BaseOutputParser] [Required]
get_format_instructions()[source]
Instructions on how the LLM output should be formatted.
Return type
str
parse(text)[source]
Parse the output of an LLM call.
Parameters
text (str) – 
Return type
Dict[str, Any]
class langchain.output_parsers.CommaSeparatedListOutputParser[source]
Bases: langchain.output_parsers.list.ListOutputParser
Parse out comma separated lists.
Return type
None
get_format_instructions()[source]
Instructions on how the LLM output should be formatted.
Return type
str
parse(text)[source]
Parse the output of an LLM call.
Parameters
text (str) – 
Return type
List[str]
class langchain.output_parsers.DatetimeOutputParser(*, format='%Y-%m-%dT%H:%M:%S.%fZ')[source]
Bases: langchain.schema.BaseOutputParser[datetime.datetime]
Parameters
format (str) – 
Return type
None
attribute format: str = '%Y-%m-%dT%H:%M:%S.%fZ'
get_format_instructions()[source]
Instructions on how the LLM output should be formatted.
Return type
str
parse(response)[source]
Parse the output of an LLM call.
A method which takes in a string (assumed output of a language model )
and parses it into some structure.
Parameters
text – output of language model
response (str) – 
Returns
structured output
Return type
datetime.datetime
class langchain.output_parsers.EnumOutputParser(*, enum)[source]
Bases: langchain.schema.BaseOutputParser
Parameters
enum (Type[enum.Enum]) – 
Return type
None
attribute enum: Type[enum.Enum] [Required]
get_format_instructions()[source]
Instructions on how the LLM output should be formatted.
Return type
str
parse(response)[source]
Parse the output of an LLM call.
A method which takes in a string (assumed output of a language model )
and parses it into some structure.
Parameters
text – output of language model
response (str) – 
Returns
structured output
Return type
Any
class langchain.output_parsers.GuardrailsOutputParser(*, guard=None, api=None, args=None, kwargs=None)[source]
Bases: langchain.schema.BaseOutputParser
Parameters
guard (Any) – 
api (Optional[Callable]) – 
args (Any) – 
kwargs (Any) – 
Return type
None
attribute api: Optional[Callable] = None
attribute args: Any = None
attribute guard: Any = None
attribute kwargs: Any = None
classmethod from_rail(rail_file, num_reasks=1, api=None, *args, **kwargs)[source]
Parameters
rail_file (str) – 
num_reasks (int) – 
api (Optional[Callable]) – 
args (Any) – 
kwargs (Any) – 
Return type
langchain.output_parsers.rail_parser.GuardrailsOutputParser
classmethod from_rail_string(rail_str, num_reasks=1, api=None, *args, **kwargs)[source]
Parameters
rail_str (str) – 
num_reasks (int) – 
api (Optional[Callable]) – 
args (Any) – 
kwargs (Any) – 
Return type
langchain.output_parsers.rail_parser.GuardrailsOutputParser
get_format_instructions()[source]
Instructions on how the LLM output should be formatted.
Return type
str
parse(text)[source]
Parse the output of an LLM call.
A method which takes in a string (assumed output of a language model )
and parses it into some structure.
Parameters
text (str) – output of language model
Returns
structured output
Return type
Dict
class langchain.output_parsers.ListOutputParser[source]
Bases: langchain.schema.BaseOutputParser
Class to parse the output of an LLM call to a list.
Return type
None
abstract parse(text)[source]
Parse the output of an LLM call.
Parameters
text (str) – 
Return type
List[str]
class langchain.output_parsers.OutputFixingParser(*, parser, retry_chain)[source]
Bases: langchain.schema.BaseOutputParser[langchain.output_parsers.fix.T]
Wraps a parser and tries to fix parsing errors.
Parameters
parser (langchain.schema.BaseOutputParser[langchain.output_parsers.fix.T]) – 
retry_chain (langchain.chains.llm.LLMChain) – 
Return type
None
attribute parser: langchain.schema.BaseOutputParser[langchain.output_parsers.fix.T] [Required]
attribute retry_chain: langchain.chains.llm.LLMChain [Required]
classmethod from_llm(llm, parser, prompt=PromptTemplate(input_variables=['completion', 'error', 'instructions'], output_parser=None, partial_variables={}, template='Instructions:\n--------------\n{instructions}\n--------------\nCompletion:\n--------------\n{completion}\n--------------\n\nAbove, the Completion did not satisfy the constraints given in the Instructions.\nError:\n--------------\n{error}\n--------------\n\nPlease try again. Please only respond with an answer that satisfies the constraints laid out in the Instructions:', template_format='f-string', validate_template=True))[source]
Parameters
llm (langchain.base_language.BaseLanguageModel) – 
parser (langchain.schema.BaseOutputParser[langchain.output_parsers.fix.T]) – 
prompt (langchain.prompts.base.BasePromptTemplate) – 
Return type
langchain.output_parsers.fix.OutputFixingParser[langchain.output_parsers.fix.T]
get_format_instructions()[source]
Instructions on how the LLM output should be formatted.
Return type
str
parse(completion)[source]
Parse the output of an LLM call.
A method which takes in a string (assumed output of a language model )
and parses it into some structure.
Parameters
text – output of language model
completion (str) – 
Returns
structured output
Return type
langchain.output_parsers.fix.T
class langchain.output_parsers.PydanticOutputParser(*, pydantic_object)[source]
Bases: langchain.schema.BaseOutputParser[langchain.output_parsers.pydantic.T]
Parameters
pydantic_object (Type[langchain.output_parsers.pydantic.T]) – 
Return type
None
attribute pydantic_object: Type[langchain.output_parsers.pydantic.T] [Required]
get_format_instructions()[source]
Instructions on how the LLM output should be formatted.
Return type
str
parse(text)[source]
Parse the output of an LLM call.
A method which takes in a string (assumed output of a language model )
and parses it into some structure.
Parameters
text (str) – output of language model
Returns
structured output
Return type
langchain.output_parsers.pydantic.T
class langchain.output_parsers.RegexDictParser(*, regex_pattern="{}:\\s?([^.'\\n']*)\\.?", output_key_to_format, no_update_value=None)[source]
Bases: langchain.schema.BaseOutputParser
Class to parse the output into a dictionary.
Parameters
regex_pattern (str) – 
output_key_to_format (Dict[str, str]) – 
no_update_value (Optional[str]) – 
Return type
None
attribute no_update_value: Optional[str] = None
attribute output_key_to_format: Dict[str, str] [Required]
attribute regex_pattern: str = "{}:\\s?([^.'\\n']*)\\.?"
parse(text)[source]
Parse the output of an LLM call.
Parameters
text (str) – 
Return type
Dict[str, str]
class langchain.output_parsers.RegexParser(*, regex, output_keys, default_output_key=None)[source]
Bases: langchain.schema.BaseOutputParser
Class to parse the output into a dictionary.
Parameters
regex (str) – 
output_keys (List[str]) – 
default_output_key (Optional[str]) – 
Return type
None
attribute default_output_key: Optional[str] = None
attribute output_keys: List[str] [Required]
attribute regex: str [Required]
parse(text)[source]
Parse the output of an LLM call.
Parameters
text (str) – 
Return type
Dict[str, str]
class langchain.output_parsers.ResponseSchema(*, name, description, type='string')[source]
Bases: pydantic.main.BaseModel
Parameters
name (str) – 
description (str) – 
type (str) – 
Return type
None
attribute description: str [Required]
attribute name: str [Required]
attribute type: str = 'string'
class langchain.output_parsers.RetryOutputParser(*, parser, retry_chain)[source]
Bases: langchain.schema.BaseOutputParser[langchain.output_parsers.retry.T]
Wraps a parser and tries to fix parsing errors.
Does this by passing the original prompt and the completion to another
LLM, and telling it the completion did not satisfy criteria in the prompt.
Parameters
parser (langchain.schema.BaseOutputParser[langchain.output_parsers.retry.T]) – 
retry_chain (langchain.chains.llm.LLMChain) – 
Return type
None
attribute parser: langchain.schema.BaseOutputParser[langchain.output_parsers.retry.T] [Required]
attribute retry_chain: langchain.chains.llm.LLMChain [Required]
classmethod from_llm(llm, parser, prompt=PromptTemplate(input_variables=['completion', 'prompt'], output_parser=None, partial_variables={}, template='Prompt:\n{prompt}\nCompletion:\n{completion}\n\nAbove, the Completion did not satisfy the constraints given in the Prompt.\nPlease try again:', template_format='f-string', validate_template=True))[source]
Parameters
llm (langchain.base_language.BaseLanguageModel) – 
parser (langchain.schema.BaseOutputParser[langchain.output_parsers.retry.T]) – 
prompt (langchain.prompts.base.BasePromptTemplate) – 
Return type
langchain.output_parsers.retry.RetryOutputParser[langchain.output_parsers.retry.T]
get_format_instructions()[source]
Instructions on how the LLM output should be formatted.
Return type
str
parse(completion)[source]
Parse the output of an LLM call.
A method which takes in a string (assumed output of a language model )
and parses it into some structure.
Parameters
text – output of language model
completion (str) – 
Returns
structured output
Return type
langchain.output_parsers.retry.T
parse_with_prompt(completion, prompt_value)[source]
Optional method to parse the output of an LLM call with a prompt.
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) – output of language model
prompt – prompt value
prompt_value (langchain.schema.PromptValue) – 
Returns
structured output
Return type
langchain.output_parsers.retry.T
class langchain.output_parsers.RetryWithErrorOutputParser(*, parser, retry_chain)[source]
Bases: langchain.schema.BaseOutputParser[langchain.output_parsers.retry.T]
Wraps a parser and tries to fix parsing errors.
Does this by passing the original prompt, the completion, AND the error
that was raised to another language model and telling it that the completion
did not work, and raised the given error. Differs from RetryOutputParser
in that this implementation provides the error that was raised back to the
LLM, which in theory should give it more information on how to fix it.
Parameters
parser (langchain.schema.BaseOutputParser[langchain.output_parsers.retry.T]) – 
retry_chain (langchain.chains.llm.LLMChain) – 
Return type
None
attribute parser: langchain.schema.BaseOutputParser[langchain.output_parsers.retry.T] [Required]
attribute retry_chain: langchain.chains.llm.LLMChain [Required]
classmethod from_llm(llm, parser, prompt=PromptTemplate(input_variables=['completion', 'error', 'prompt'], output_parser=None, partial_variables={}, template='Prompt:\n{prompt}\nCompletion:\n{completion}\n\nAbove, the Completion did not satisfy the constraints given in the Prompt.\nDetails: {error}\nPlease try again:', template_format='f-string', validate_template=True))[source]
Parameters
llm (langchain.base_language.BaseLanguageModel) – 
parser (langchain.schema.BaseOutputParser[langchain.output_parsers.retry.T]) – 
prompt (langchain.prompts.base.BasePromptTemplate) – 
Return type
langchain.output_parsers.retry.RetryWithErrorOutputParser[langchain.output_parsers.retry.T]
get_format_instructions()[source]
Instructions on how the LLM output should be formatted.
Return type
str
parse(completion)[source]
Parse the output of an LLM call.
A method which takes in a string (assumed output of a language model )
and parses it into some structure.
Parameters
text – output of language model
completion (str) – 
Returns
structured output
Return type
langchain.output_parsers.retry.T
parse_with_prompt(completion, prompt_value)[source]
Optional method to parse the output of an LLM call with a prompt.
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) – output of language model
prompt – prompt value
prompt_value (langchain.schema.PromptValue) – 
Returns
structured output
Return type
langchain.output_parsers.retry.T
class langchain.output_parsers.StructuredOutputParser(*, response_schemas)[source]
Bases: langchain.schema.BaseOutputParser
Parameters
response_schemas (List[langchain.output_parsers.structured.ResponseSchema]) – 
Return type
None
attribute response_schemas: List[langchain.output_parsers.structured.ResponseSchema] [Required]
classmethod from_response_schemas(response_schemas)[source]
Parameters
response_schemas (List[langchain.output_parsers.structured.ResponseSchema]) – 
Return type
langchain.output_parsers.structured.StructuredOutputParser
get_format_instructions()[source]
Instructions on how the LLM output should be formatted.
Return type
str
parse(text)[source]
Parse the output of an LLM call.
A method which takes in a string (assumed output of a language model )
and parses it into some structure.
Parameters
text (str) – output of language model
Returns
structured output
Return type
Any