LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • MCP Adapters
    • Overview
    • Agents
    • Callbacks
    • Chains
    • Chat models
    • Embeddings
    • Evaluation
    • Globals
    • Hub
    • Memory
    • Output parsers
    • Retrievers
    • Runnables
    • LangSmith
    • Storage
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    MCP Adapters
    OverviewAgentsCallbacksChainsChat modelsEmbeddingsEvaluationGlobalsHubMemoryOutput parsersRetrieversRunnablesLangSmithStorage
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-classicagentsoutput_parsers
    Module●Since v1.0

    output_parsers

    Parsing utils to go from string to AgentAction or Agent Finish.

    AgentAction means that an action should be taken. This contains the name of the tool to use, the input to pass to that tool, and a log variable (which contains a log of the agent's thinking).

    AgentFinish means that a response should be given. This contains a return_values dictionary. This usually contains a single output key, but can be extended to contain more. This also contains a log variable (which contains a log of the agent's thinking).

    Classes

    class
    JSONAgentOutputParser

    Parses tool invocations and final answers in JSON format.

    Expects output to be in one of two formats.

    If the output signals that an action should be taken, should be in the below format. This will result in an AgentAction being returned.

    {"action": "search", "action_input": "2+2"}
    

    If the output signals that a final answer should be given, should be in the below format. This will result in an AgentFinish being returned.

    {"action": "Final Answer", "action_input": "4"}
    
    class
    OpenAIFunctionsAgentOutputParser

    Parses a message into agent action/finish.

    Is meant to be used with OpenAI models, as it relies on the specific function_call parameter from OpenAI to convey what tools to use.

    If a function_call parameter is passed, then that is used to get the tool and tool input.

    If one is not passed, then the AIMessage is assumed to be the final output.

    class
    ReActJsonSingleInputOutputParser

    Parses ReAct-style LLM calls that have a single tool input in json format.

    Expects output to be in one of two formats.

    If the output signals that an action should be taken, should be in the below format. This will result in an AgentAction being returned.

    Thought: agent thought here
    Action:
    

    { "action": "search", "action_input": "what is the temperature in SF" }

    If the output signals that a final answer should be given, should be in the below format. This will result in an AgentFinish being returned.

    Thought: agent thought here
    Final Answer: The temperature is 100 degrees
    
    class
    ReActSingleInputOutputParser

    Parses ReAct-style LLM calls that have a single tool input.

    Expects output to be in one of two formats.

    If the output signals that an action should be taken, should be in the below format. This will result in an AgentAction being returned.

    Thought: agent thought here
    Action: search
    Action Input: what is the temperature in SF?
    

    If the output signals that a final answer should be given, should be in the below format. This will result in an AgentFinish being returned.

    Thought: agent thought here
    Final Answer: The temperature is 100 degrees
    
    class
    SelfAskOutputParser

    Parses self-ask style LLM calls.

    Expects output to be in one of two formats.

    If the output signals that an action should be taken, should be in the below format. This will result in an AgentAction being returned.

    Thoughts go here...
    Follow up: what is the temperature in SF?
    

    If the output signals that a final answer should be given, should be in the below format. This will result in an AgentFinish being returned.

    Thoughts go here...
    So the final answer is: The temperature is 100 degrees
    
    class
    ToolsAgentOutputParser

    Parses a message into agent actions/finish.

    If a tool_calls parameter is passed, then that is used to get the tool names and tool inputs.

    If one is not passed, then the AIMessage is assumed to be the final output.

    class
    XMLAgentOutputParser

    Parses tool invocations and final answers from XML-formatted agent output.

    This parser extracts structured information from XML tags to determine whether an agent should perform a tool action or provide a final answer. It includes built-in escaping support to safely handle tool names and inputs containing XML special characters.

    Modules

    module
    react_json_single_input
    module
    openai_functions
    module
    openai_tools
    module
    json
    module
    xml
    module
    react_single_input
    module
    self_ask
    module
    tools
    View source on GitHub