{"record":{"id":"e36c2c89d89958f7","repo":"langchain-ai/langchain","slug":"arguments-observation-llm-output-are-require","errorCode":null,"errorMessage":"Arguments 'observation' & 'llm_output' are required if 'send_to_llm' is True","messagePattern":"Arguments 'observation' & 'llm_output' are required if 'send_to_llm' is True","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/exceptions.py","lineNumber":62,"sourceCode":"                previous output was improperly structured, in the hopes that it will\n                update the output to the correct format.\n\n        Raises:\n            ValueError: If `send_to_llm` is `True` but either observation or\n                `llm_output` are not provided.\n        \"\"\"\n        if isinstance(error, str):\n            error = create_message(\n                message=error, error_code=ErrorCode.OUTPUT_PARSING_FAILURE\n            )\n\n        super().__init__(error)\n        if send_to_llm and (observation is None or llm_output is None):\n            msg = (\n                \"Arguments 'observation' & 'llm_output'\"\n                \" are required if 'send_to_llm' is True\"\n            )\n            raise ValueError(msg)\n        self.observation = observation\n        self.llm_output = llm_output\n        self.send_to_llm = send_to_llm\n\n\nclass ContextOverflowError(LangChainException):\n    \"\"\"Exception raised when input exceeds the model's context limit.\n\n    This exception is raised by chat models when the input tokens exceed\n    the maximum context window supported by the model.\n    \"\"\"\n\n\nclass ErrorCode(Enum):\n    \"\"\"Error codes.\"\"\"\n\n    INVALID_PROMPT_INPUT = \"INVALID_PROMPT_INPUT\"\n    INVALID_TOOL_RESULTS = \"INVALID_TOOL_RESULTS\"  # Used in JS; not Py (yet)","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/exceptions.py#L44-L80","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass both kwargs: `raise OutputParserException(msg, observation=err_detail, llm_output=raw_text, send_to_llm=True)`.","If you do not need the retry-with-feedback loop, drop the flag: `raise OutputParserException(msg)`.","Set defaults in your parser harness so observation/llm_output are always derived from the failure site."],"exampleFix":"# before\nraise OutputParserException(\"Failed to parse action\", send_to_llm=True)\n\n# after\nraise OutputParserException(\n    \"Failed to parse action\",\n    observation=\"Output did not match expected JSON schema\",\n    llm_output=raw_model_text,\n    send_to_llm=True,\n)","handlingStrategy":"validation","validationCode":"def raise_parse_error(msg, *, observation=None, llm_output=None, send_to_llm=False):\n    if send_to_llm and (observation is None or llm_output is None):\n        raise ValueError(\"observation and llm_output required for send_to_llm\")\n    raise OutputParserException(msg, observation=observation, llm_output=llm_output, send_to_llm=send_to_llm)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat send_to_llm, observation, llm_output as an all-or-nothing triple.","Centralize exception construction in one parser helper so kwargs are always consistent."],"tags":["exceptions","output-parsing","agents","validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}