Home / Function/ _process_llm_result() — langchain Function Reference

_process_llm_result() — langchain Function Reference

Architecture documentation for the _process_llm_result() function in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  e6ecd33c_18e0_06b4_0790_97d70ddc6b59["_process_llm_result()"]
  781ec1fc_a277_bc9a_9bc4_a35f09bdb247["LLMMathChain"]
  e6ecd33c_18e0_06b4_0790_97d70ddc6b59 -->|defined in| 781ec1fc_a277_bc9a_9bc4_a35f09bdb247
  d79e2fc7_c6d7_6239_3d65_7e4132af490a["_call()"]
  d79e2fc7_c6d7_6239_3d65_7e4132af490a -->|calls| e6ecd33c_18e0_06b4_0790_97d70ddc6b59
  9f5d2acc_7bd4_b52e_b0a0_63401395b8e4["_evaluate_expression()"]
  e6ecd33c_18e0_06b4_0790_97d70ddc6b59 -->|calls| 9f5d2acc_7bd4_b52e_b0a0_63401395b8e4
  style e6ecd33c_18e0_06b4_0790_97d70ddc6b59 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/llm_math/base.py lines 222–243

    def _process_llm_result(
        self,
        llm_output: str,
        run_manager: CallbackManagerForChainRun,
    ) -> dict[str, str]:
        run_manager.on_text(llm_output, color="green", verbose=self.verbose)
        llm_output = llm_output.strip()
        text_match = re.search(r"^```text(.*?)```", llm_output, re.DOTALL)
        if text_match:
            expression = text_match.group(1)
            output = self._evaluate_expression(expression)
            run_manager.on_text("\nAnswer: ", verbose=self.verbose)
            run_manager.on_text(output, color="yellow", verbose=self.verbose)
            answer = "Answer: " + output
        elif llm_output.startswith("Answer:"):
            answer = llm_output
        elif "Answer:" in llm_output:
            answer = "Answer: " + llm_output.split("Answer:")[-1]
        else:
            msg = f"unknown format from LLM: {llm_output}"
            raise ValueError(msg)
        return {self.output_key: answer}

Subdomains

Called By

Frequently Asked Questions

What does _process_llm_result() do?
_process_llm_result() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/llm_math/base.py.
Where is _process_llm_result() defined?
_process_llm_result() is defined in libs/langchain/langchain_classic/chains/llm_math/base.py at line 222.
What does _process_llm_result() call?
_process_llm_result() calls 1 function(s): _evaluate_expression.
What calls _process_llm_result()?
_process_llm_result() is called by 1 function(s): _call.

Analyze Your Own Codebase

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

Try Supermodel Free