langchain.output_parsers.retry.RetryOutputParser¶
- class langchain.output_parsers.retry.RetryOutputParser(*, parser: BaseOutputParser[T], retry_chain: LLMChain)[source]¶
Bases:
BaseOutputParser[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.
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 parser: langchain.schema.output_parser.BaseOutputParser[langchain.output_parsers.retry.T] [Required]¶
The parser to use to parse the output.
- param retry_chain: langchain.chains.llm.LLMChain [Required]¶
The LLMChain to use to retry the completion.
- dict(**kwargs: Any) Dict¶
Return dictionary representation of output parser.
- classmethod from_llm(llm: BaseLanguageModel, parser: BaseOutputParser[T], prompt: BasePromptTemplate = 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)) RetryOutputParser[T][source]¶
- invoke(input: str | langchain.schema.messages.BaseMessage, config: langchain.schema.runnable.RunnableConfig | None = None) T¶
- parse(completion: str) T[source]¶
Parse a single string model output into some structure.
- Parameters
text – String output of a language model.
- Returns
Structured output.
- parse_result(result: List[Generation]) 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 – A list of Generations to be parsed. The Generations are assumed to be different candidate outputs for a single model input.
- Returns
Structured output.
- parse_with_prompt(completion: str, prompt_value: PromptValue) T[source]¶
Parse the output of an LLM call using a wrapped parser.
- Parameters
completion – The chain completion to parse.
prompt_value – The prompt to use to parse the completion.
- Returns
The parsed completion.
- to_json() Union[SerializedConstructor, SerializedNotImplemented]¶
- to_json_not_implemented() SerializedNotImplemented¶
- property lc_attributes: Dict¶
Return a list of attribute names that should be included in the serialized kwargs. These attributes must be accepted by the constructor.
- property lc_namespace: List[str]¶
Return the namespace of the langchain object. eg. [“langchain”, “llms”, “openai”]
- property lc_secrets: Dict[str, str]¶
Return a map of constructor argument names to secret ids. eg. {“openai_api_key”: “OPENAI_API_KEY”}
- property lc_serializable: bool¶
Return whether or not the class is serializable.