langchain.output_parsers.regex_dict.RegexDictParser¶

class langchain.output_parsers.regex_dict.RegexDictParser(*, regex_pattern: str = "{}:\\s?([^.'\\n']*)\\.?", output_key_to_format: Dict[str, str], no_update_value: Optional[str] = None)[source]¶

Bases: BaseOutputParser

Parse the output of an LLM call into a Dictionary using a regex.

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 no_update_value: Optional[str] = None¶

The default key to use for the output.

param output_key_to_format: Dict[str, str] [Required]¶

The keys to use for the output.

param regex_pattern: str = "{}:\\s?([^.'\\n']*)\\.?"¶

The regex pattern to use to parse the output.

dict(**kwargs: Any) Dict¶

Return dictionary representation of output parser.

get_format_instructions() str¶

Instructions on how the LLM output should be formatted.

invoke(input: str | langchain.schema.messages.BaseMessage, config: langchain.schema.runnable.RunnableConfig | None = None) T¶
parse(text: str) Dict[str, str][source]¶

Parse the output of an LLM call.

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: 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 – String output of a language model.

  • prompt – Input PromptValue.

Returns

Structured output

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.

model Config¶

Bases: object

extra = 'ignore'¶