{"record":{"id":"17c6b3a01e323a59","repo":"langchain-ai/langchain","slug":"runnablesequence-must-have-at-least-runnable-seq","errorCode":null,"errorMessage":"RunnableSequence must have at least {_RUNNABLE_SEQUENCE_MIN_STEPS} steps, got {len(steps_flat)}","messagePattern":"RunnableSequence must have at least (.+?) steps, got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/runnables/base.py","lineNumber":3190,"sourceCode":"            last: The last `Runnable` in the sequence.\n\n        Raises:\n            ValueError: If the sequence has less than 2 steps.\n        \"\"\"\n        steps_flat: list[Runnable[Any, Any]] = []\n        if not steps and first is not None and last is not None:\n            steps_flat = [first] + (middle or []) + [last]\n        for step in steps:\n            if isinstance(step, RunnableSequence):\n                steps_flat.extend(step.steps)\n            else:\n                steps_flat.append(coerce_to_runnable(step))\n        if len(steps_flat) < _RUNNABLE_SEQUENCE_MIN_STEPS:\n            msg = (\n                f\"RunnableSequence must have at least {_RUNNABLE_SEQUENCE_MIN_STEPS} \"\n                f\"steps, got {len(steps_flat)}\"\n            )\n            raise ValueError(msg)\n        super().__init__(\n            first=steps_flat[0],\n            middle=list(steps_flat[1:-1]),\n            last=steps_flat[-1],\n            name=name,\n        )\n\n    @classmethod\n    @override\n    def get_lc_namespace(cls) -> list[str]:\n        \"\"\"Get the namespace of the LangChain object.\n\n        Returns:\n            `[\"langchain\", \"schema\", \"runnable\"]`\n        \"\"\"\n        return [\"langchain\", \"schema\", \"runnable\"]\n\n    @property","sourceCodeStart":3172,"sourceCodeEnd":3208,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/runnables/base.py#L3172-L3208","documentation":"`RunnableSequence.__init__` validates that a sequence contains at least `_RUNNABLE_SEQUENCE_MIN_STEPS` (2) steps after flattening nested `RunnableSequence`s and coercing callables. A sequence with 0 or 1 steps is meaningless (it is just the single runnable, or nothing), so the constructor rejects it with a `ValueError`. Flattening means nested sequences contribute their inner steps, so only the final flattened count matters.","triggerScenarios":"Calling `RunnableSequence()` with no args; `RunnableSequence(my_runnable)` with a single step; passing `steps=[x]`, or `first=x` without a `last`; constructing with `steps` where nesting still flattens to fewer than 2 steps (e.g. one nested single-step sequence).","commonSituations":"Programmatically building sequences from dynamic lists (`RunnableSequence(*fns)` where `fns` may have 0 or 1 element); refactoring the `|` operator pipeline into explicit `RunnableSequence` calls; wrapping user-supplied step lists at runtime.","solutions":["Pass at least two runnables: `RunnableSequence(step_a, step_b)`.","If you have exactly one runnable, use it directly instead of wrapping it in a sequence (or `coerce_to_runnable(x)` for callables).","Guard dynamic construction: `RunnableSequence(*steps) if len(steps) >= 2 else coerce_to_runnable(steps[0])`.","Prefer the pipe operator `a | b`, which never builds an under-sized sequence."],"exampleFix":"// before\nseq = RunnableSequence(my_single_runnable)\n\n// after\nseq = my_single_runnable  # a single step needs no sequence\n# or, for two steps:\nseq = RunnableSequence(step_a, step_b)\n// dynamic list:\nseq = RunnableSequence(*steps) if len(steps) >= 2 else coerce_to_runnable(steps[0])","handlingStrategy":"validation","validationCode":"from langchain_core.runnables import RunnableSequence, Runnable, coerce_to_runnable\n\ndef build_sequence(steps: list) -> Runnable:\n    if len(steps) >= 2:\n        return RunnableSequence(*steps)\n    if len(steps) == 1:\n        return coerce_to_runnable(steps[0])\n    msg = 'steps list is empty'\n    raise ValueError(msg)","typeGuard":"from langchain_core.runnables import Runnable, RunnableSequence\n\ndef is_valid_sequence(steps: list[Runnable]) -> bool:\n    return len(steps) >= 2","tryCatchPattern":"try:\n    seq = RunnableSequence(*steps)\nexcept ValueError as e:\n    if 'at least' in str(e):\n        seq = coerce_to_runnable(steps[0]) if steps else None\n    else:\n        raise","preventionTips":["Never construct RunnableSequence with fewer than two steps; use the runnable directly.","Prefer the `|` operator, which composes sequences safely.","Validate dynamic step lists with len() before splatting them into RunnableSequence."],"tags":["runnable","runnable-sequence","validation","constructor"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}