Home / Function/ _run_llm_or_chain() — langchain Function Reference

_run_llm_or_chain() — langchain Function Reference

Architecture documentation for the _run_llm_or_chain() function in runner_utils.py from the langchain codebase.

Function python LangChainCore Runnables calls 2 called by 1

Entity Profile

Dependency Diagram

graph TD
  385c1e91_d947_1192_8746_ee1dd66ceb54["_run_llm_or_chain()"]
  8253c602_7d0c_9195_a7e1_3e9b19304131["runner_utils.py"]
  385c1e91_d947_1192_8746_ee1dd66ceb54 -->|defined in| 8253c602_7d0c_9195_a7e1_3e9b19304131
  0522e7ee_f1e6_b6f7_6738_1dad72cfffba["run_on_dataset()"]
  0522e7ee_f1e6_b6f7_6738_1dad72cfffba -->|calls| 385c1e91_d947_1192_8746_ee1dd66ceb54
  916eedb8_7d10_72b9_9829_105f8ada65ab["_run_llm()"]
  385c1e91_d947_1192_8746_ee1dd66ceb54 -->|calls| 916eedb8_7d10_72b9_9829_105f8ada65ab
  732636c1_f8cb_78e1_d81d_6611b0b6e364["_run_chain()"]
  385c1e91_d947_1192_8746_ee1dd66ceb54 -->|calls| 732636c1_f8cb_78e1_d81d_6611b0b6e364
  style 385c1e91_d947_1192_8746_ee1dd66ceb54 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/smith/evaluation/runner_utils.py lines 965–1019

def _run_llm_or_chain(
    example: Example,
    config: RunnableConfig,
    *,
    llm_or_chain_factory: MCF,
    input_mapper: Callable[[dict], Any] | None = None,
) -> dict | str | LLMResult | ChatResult:
    """Run the Chain or language model synchronously.

    Args:
        example: The example to run.
        config: The configuration for the run.
        llm_or_chain_factory: The Chain or language model constructor to run.
        input_mapper: Optional function to map the input to the expected format.

    Returns:
        The outputs of the model or chain.
    """
    chain_or_llm = (
        "LLM" if isinstance(llm_or_chain_factory, BaseLanguageModel) else "Chain"
    )
    result = None
    try:
        if isinstance(llm_or_chain_factory, BaseLanguageModel):
            output: Any = _run_llm(
                llm_or_chain_factory,
                example.inputs or {},
                config["callbacks"],
                tags=config["tags"],
                input_mapper=input_mapper,
                metadata=config.get("metadata"),
            )
        else:
            chain = llm_or_chain_factory()
            output = _run_chain(
                chain,
                example.inputs or {},
                config["callbacks"],
                tags=config["tags"],
                input_mapper=input_mapper,
                metadata=config.get("metadata"),
            )
        result = output
    except Exception as e:  # noqa: BLE001
        error_type = type(e).__name__
        logger.warning(
            "%s failed for example %s with inputs %s\nError Type: %s, Message: %s",
            chain_or_llm,
            example.id,
            example.inputs,
            error_type,
            e,
        )
        result = EvalError(Error=e)
    return result

Domain

Subdomains

Called By

Frequently Asked Questions

What does _run_llm_or_chain() do?
_run_llm_or_chain() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/smith/evaluation/runner_utils.py.
Where is _run_llm_or_chain() defined?
_run_llm_or_chain() is defined in libs/langchain/langchain_classic/smith/evaluation/runner_utils.py at line 965.
What does _run_llm_or_chain() call?
_run_llm_or_chain() calls 2 function(s): _run_chain, _run_llm.
What calls _run_llm_or_chain()?
_run_llm_or_chain() is called by 1 function(s): run_on_dataset.

Analyze Your Own Codebase

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

Try Supermodel Free