langchain-ai/langchain · error · ValueError

Arguments 'observation' & 'llm_output' are required if 'send

Error message

Arguments 'observation' & 'llm_output' are required if 'send_to_llm' is True

What it means

Raised in the `OutputParserException.__init__` in `langchain_core.exceptions`. `OutputParserException` can optionally carry the LLM's raw output and an observation back to the model so an agent can retry with feedback (`send_to_llm=True`). Claiming you want that feedback loop without supplying the actual `observation` and `llm_output` would make the retry prompt meaningless, so the constructor validates the triple immediately.

Source

Thrown at libs/core/langchain_core/exceptions.py:62

                previous output was improperly structured, in the hopes that it will
                update the output to the correct format.

        Raises:
            ValueError: If `send_to_llm` is `True` but either observation or
                `llm_output` are not provided.
        """
        if isinstance(error, str):
            error = create_message(
                message=error, error_code=ErrorCode.OUTPUT_PARSING_FAILURE
            )

        super().__init__(error)
        if send_to_llm and (observation is None or llm_output is None):
            msg = (
                "Arguments 'observation' & 'llm_output'"
                " are required if 'send_to_llm' is True"
            )
            raise ValueError(msg)
        self.observation = observation
        self.llm_output = llm_output
        self.send_to_llm = send_to_llm


class ContextOverflowError(LangChainException):
    """Exception raised when input exceeds the model's context limit.

    This exception is raised by chat models when the input tokens exceed
    the maximum context window supported by the model.
    """


class ErrorCode(Enum):
    """Error codes."""

    INVALID_PROMPT_INPUT = "INVALID_PROMPT_INPUT"
    INVALID_TOOL_RESULTS = "INVALID_TOOL_RESULTS"  # Used in JS; not Py (yet)

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. Pass both kwargs: `raise OutputParserException(msg, observation=err_detail, llm_output=raw_text, send_to_llm=True)`.
  2. If you do not need the retry-with-feedback loop, drop the flag: `raise OutputParserException(msg)`.
  3. Set defaults in your parser harness so observation/llm_output are always derived from the failure site.

Example fix

# before
raise OutputParserException("Failed to parse action", send_to_llm=True)

# after
raise OutputParserException(
    "Failed to parse action",
    observation="Output did not match expected JSON schema",
    llm_output=raw_model_text,
    send_to_llm=True,
)
Defensive patterns

Strategy: validation

Validate before calling

def raise_parse_error(msg, *, observation=None, llm_output=None, send_to_llm=False):
    if send_to_llm and (observation is None or llm_output is None):
        raise ValueError("observation and llm_output required for send_to_llm")
    raise OutputParserException(msg, observation=observation, llm_output=llm_output, send_to_llm=send_to_llm)

Prevention

When it happens

Trigger: Raising `OutputParserException("bad output", send_to_llm=True)` without `observation` or `llm_output` kwargs. Common when copying a plain-exception raise pattern (`raise ValueError(msg)`) into a parser that supports LLM feedback.

Common situations: Writing custom output parsers / structured output tools that wrap parse failures; upgrading a generic exception to OutputParserException and forgetting the extra fields; AgentExecutor/ParsingTool usage that inspects these attributes.

Related errors


AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14). Data as JSON: /api/errors/e36c2c89d89958f7. Report an issue: GitHub.