Home / Function/ parse() — langchain Function Reference

parse() — langchain Function Reference

Architecture documentation for the parse() function in json.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  8a6ae8dc_8433_ec1a_2372_2641f4d84ab5["parse()"]
  e8fcdf66_eb2a_8e8f_0f9a_ab9103e6b8c9["JSONAgentOutputParser"]
  8a6ae8dc_8433_ec1a_2372_2641f4d84ab5 -->|defined in| e8fcdf66_eb2a_8e8f_0f9a_ab9103e6b8c9
  2fd5dd59_5a0d_9cd1_0757_aa1f6aa3ba77["parse()"]
  2fd5dd59_5a0d_9cd1_0757_aa1f6aa3ba77 -->|calls| 8a6ae8dc_8433_ec1a_2372_2641f4d84ab5
  82fe8ecf_d248_3f94_9ae6_6b64c9d27d9d["parse()"]
  82fe8ecf_d248_3f94_9ae6_6b64c9d27d9d -->|calls| 8a6ae8dc_8433_ec1a_2372_2641f4d84ab5
  05105a11_6f92_b96b_fffa_c3c22f0f0f42["parse()"]
  05105a11_6f92_b96b_fffa_c3c22f0f0f42 -->|calls| 8a6ae8dc_8433_ec1a_2372_2641f4d84ab5
  style 8a6ae8dc_8433_ec1a_2372_2641f4d84ab5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/output_parsers/json.py lines 38–53

    def parse(self, text: str) -> AgentAction | AgentFinish:
        try:
            response = parse_json_markdown(text)
            if isinstance(response, list):
                # gpt turbo frequently ignores the directive to emit a single action
                logger.warning("Got multiple action responses: %s", response)
                response = response[0]
            if response["action"] == "Final Answer":
                return AgentFinish({"output": response["action_input"]}, text)
            action_input = response.get("action_input", {})
            if action_input is None:
                action_input = {}
            return AgentAction(response["action"], action_input, text)
        except Exception as e:
            msg = f"Could not parse LLM output: {text}"
            raise OutputParserException(msg) from e

Subdomains

Frequently Asked Questions

What does parse() do?
parse() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/agents/output_parsers/json.py.
Where is parse() defined?
parse() is defined in libs/langchain/langchain_classic/agents/output_parsers/json.py at line 38.
What calls parse()?
parse() is called by 3 function(s): parse, parse, parse.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free