Home / Function/ _aprocess_llm_result() — langchain Function Reference

_aprocess_llm_result() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  799fbded_d007_f93f_f09a_d6af8fab59c4["_aprocess_llm_result()"]
  781ec1fc_a277_bc9a_9bc4_a35f09bdb247["LLMMathChain"]
  799fbded_d007_f93f_f09a_d6af8fab59c4 -->|defined in| 781ec1fc_a277_bc9a_9bc4_a35f09bdb247
  727420b4_69cd_b33e_fef6_19e037b0bff3["_acall()"]
  727420b4_69cd_b33e_fef6_19e037b0bff3 -->|calls| 799fbded_d007_f93f_f09a_d6af8fab59c4
  9f5d2acc_7bd4_b52e_b0a0_63401395b8e4["_evaluate_expression()"]
  799fbded_d007_f93f_f09a_d6af8fab59c4 -->|calls| 9f5d2acc_7bd4_b52e_b0a0_63401395b8e4
  style 799fbded_d007_f93f_f09a_d6af8fab59c4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/llm_math/base.py lines 245–266

    async def _aprocess_llm_result(
        self,
        llm_output: str,
        run_manager: AsyncCallbackManagerForChainRun,
    ) -> dict[str, str]:
        await 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)
            await run_manager.on_text("\nAnswer: ", verbose=self.verbose)
            await 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 _aprocess_llm_result() do?
_aprocess_llm_result() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/llm_math/base.py.
Where is _aprocess_llm_result() defined?
_aprocess_llm_result() is defined in libs/langchain/langchain_classic/chains/llm_math/base.py at line 245.
What does _aprocess_llm_result() call?
_aprocess_llm_result() calls 1 function(s): _evaluate_expression.
What calls _aprocess_llm_result()?
_aprocess_llm_result() is called by 1 function(s): _acall.

Analyze Your Own Codebase

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

Try Supermodel Free