Home / Function/ coerce_to_runnable() — langchain Function Reference

coerce_to_runnable() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  2b95cefe_5d3f_5288_5f51_922e3bc09b21["coerce_to_runnable()"]
  5f3c1f1c_6f8a_e293_7cb5_97c21b4bf214["base.py"]
  2b95cefe_5d3f_5288_5f51_922e3bc09b21 -->|defined in| 5f3c1f1c_6f8a_e293_7cb5_97c21b4bf214
  97a4943d_9d5f_c665_3f02_a5d84c319b03["__or__()"]
  97a4943d_9d5f_c665_3f02_a5d84c319b03 -->|calls| 2b95cefe_5d3f_5288_5f51_922e3bc09b21
  2e4fe9d5_b539_d456_e27d_b1028fa603d1["__ror__()"]
  2e4fe9d5_b539_d456_e27d_b1028fa603d1 -->|calls| 2b95cefe_5d3f_5288_5f51_922e3bc09b21
  5537c44a_82ac_f065_29d0_a67f9339ea97["__init__()"]
  5537c44a_82ac_f065_29d0_a67f9339ea97 -->|calls| 2b95cefe_5d3f_5288_5f51_922e3bc09b21
  9d86dd04_96aa_b6dc_117b_e4ec34cb6dfb["__or__()"]
  9d86dd04_96aa_b6dc_117b_e4ec34cb6dfb -->|calls| 2b95cefe_5d3f_5288_5f51_922e3bc09b21
  522ab7ce_4289_77ed_49e2_9ac1dd8ca4da["__ror__()"]
  522ab7ce_4289_77ed_49e2_9ac1dd8ca4da -->|calls| 2b95cefe_5d3f_5288_5f51_922e3bc09b21
  04c68bd7_a799_fa32_24ea_66ec86d1d211["__init__()"]
  04c68bd7_a799_fa32_24ea_66ec86d1d211 -->|calls| 2b95cefe_5d3f_5288_5f51_922e3bc09b21
  style 2b95cefe_5d3f_5288_5f51_922e3bc09b21 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/runnables/base.py lines 6176–6200

def coerce_to_runnable(thing: RunnableLike) -> Runnable[Input, Output]:
    """Coerce a `Runnable`-like object into a `Runnable`.

    Args:
        thing: A `Runnable`-like object.

    Returns:
        A `Runnable`.

    Raises:
        TypeError: If the object is not `Runnable`-like.
    """
    if isinstance(thing, Runnable):
        return thing
    if is_async_generator(thing) or inspect.isgeneratorfunction(thing):
        return RunnableGenerator(thing)
    if callable(thing):
        return RunnableLambda(cast("Callable[[Input], Output]", thing))
    if isinstance(thing, dict):
        return cast("Runnable[Input, Output]", RunnableParallel(thing))
    msg = (
        f"Expected a Runnable, callable or dict."
        f"Instead got an unsupported type: {type(thing)}"
    )
    raise TypeError(msg)

Subdomains

Frequently Asked Questions

What does coerce_to_runnable() do?
coerce_to_runnable() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/base.py.
Where is coerce_to_runnable() defined?
coerce_to_runnable() is defined in libs/core/langchain_core/runnables/base.py at line 6176.
What calls coerce_to_runnable()?
coerce_to_runnable() is called by 6 function(s): __init__, __init__, __or__, __or__, __ror__, __ror__.

Analyze Your Own Codebase

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

Try Supermodel Free