LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-coreoutput_parsersbaseBaseOutputParser
    Class●Since v0.1

    BaseOutputParser

    Copy
    BaseOutputParser(
        self,
        *args: Any = (),
        **kwargs: Any = {},
    )

    Bases

    BaseLLMOutputParserRunnableSerializable[LanguageModelOutput, T]

    Attributes

    Methods

    Inherited fromRunnableSerializable

    Attributes

    Aname: str
    —

    The name of the function.

    Amodel_config

    Methods

    Mto_json
    —

    Convert the graph to a JSON-serializable format.

    View source on GitHub
    M
    configurable_fields
    Mconfigurable_alternatives
    —

    Configure alternatives for Runnable objects that can be set at runtime.

    Inherited fromSerializable

    Attributes

    Alc_secrets: dict[str, str]
    —

    A map of constructor argument names to secret ids.

    Alc_attributes: dict
    —

    List of attribute names that should be included in the serialized kwargs.

    Amodel_config

    Methods

    Mis_lc_serializable
    —

    Return True as this class is serializable.

    Mget_lc_namespace
    —

    Get the namespace of the LangChain object.

    Mlc_id
    —

    Return a unique identifier for this class for serialization purposes.

    Mto_json
    —

    Convert the graph to a JSON-serializable format.

    Mto_json_not_implemented
    —

    Serialize a "not implemented" object.

    Inherited fromRunnable

    Attributes

    Aname: str
    —

    The name of the function.

    Ainput_schema: type[BaseModel]
    —

    The type of input this Runnable accepts specified as a Pydantic model.

    Aoutput_schema: type[BaseModel]
    —

    Output schema.

    Aconfig_specs: list[ConfigurableFieldSpec]

    Methods

    Mget_nameMget_input_schemaMget_input_jsonschema
    —

    Get a JSON schema that represents the input to the Runnable.

    Mget_output_schemaMget_output_jsonschema
    —
    attribute
    InputType: Any

    Return the input type for the parser.

    attribute
    OutputType: type[T]

    Return the output type for the parser.

    This property is inferred from the first type argument of the class.

    method
    invoke
    method
    ainvoke
    method
    parse_result

    Parse a list of candidate model Generation objects 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.

    method
    parse

    Parse a single string model output into some structure.

    method
    aparse_result

    Parse a list of candidate model Generation objects 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.

    method
    aparse

    Async parse a single string model output into some structure.

    method
    parse_with_prompt

    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.

    method
    get_format_instructions

    Instructions on how the LLM output should be formatted.

    method
    dict

    Return dictionary representation of output parser.

    Base class to parse the output of an LLM call.

    Output parsers help structure language model responses.

    Example:

    # Implement a simple boolean output parser
    
    class BooleanOutputParser(BaseOutputParser[bool]):
        true_val: str = "YES"
        false_val: str = "NO"
    
        def parse(self, text: str) -> bool:
            cleaned_text = text.strip().upper()
            if cleaned_text not in (
                self.true_val.upper(),
                self.false_val.upper(),
            ):
                raise OutputParserException(
                    f"BooleanOutputParser expected output value to either be "
                    f"{self.true_val} or {self.false_val} (case-insensitive). "
                    f"Received {cleaned_text}."
                )
            return cleaned_text == self.true_val.upper()
    
        @property
        def _type(self) -> str:
            return "boolean_output_parser"

    Get a JSON schema that represents the output of the Runnable.

    Mconfig_schema
    —

    The type of config this Runnable accepts specified as a Pydantic model.

    Mget_config_jsonschema
    —

    Get a JSON schema that represents the config of the Runnable.

    Mget_graph
    Mget_prompts
    —

    Return a list of prompts used by this Runnable.

    Mpipe
    —

    Pipe Runnable objects.

    Mpick
    —

    Pick keys from the output dict of this Runnable.

    Massign
    —

    Merge the Dict input with the output produced by the mapping argument.

    Mbatch
    Mbatch_as_completed
    —

    Run invoke in parallel on a list of inputs.

    Mabatch
    Mabatch_as_completed
    —

    Run ainvoke in parallel on a list of inputs.

    Mstream
    Mastream
    Mastream_log
    —

    Stream all output from a Runnable, as reported to the callback system.

    Mastream_events
    —

    Generate a stream of events.

    Mtransform
    Matransform
    Mbind
    —

    Bind arguments to a Runnable, returning a new Runnable.

    Mwith_config
    Mwith_listeners
    —

    Bind lifecycle listeners to a Runnable, returning a new Runnable.

    Mwith_alisteners
    —

    Bind async lifecycle listeners to a Runnable.

    Mwith_types
    —

    Bind input and output types to a Runnable, returning a new Runnable.

    Mwith_retry
    —

    Create a new Runnable that retries the original Runnable on exceptions.

    Mmap
    —

    Map a function to multiple iterables.

    Mwith_fallbacks
    —

    Add fallbacks to a Runnable, returning a new Runnable.

    Mas_tool
    —

    Create a BaseTool from a Runnable.