OutputParserException
langchain_core.exceptions.OutputParserException
Stack trace
langchain_core.exceptions.OutputParserException: Could not parse tool result content: `{"action": "open", "target": "file.txt"}`
File "/app/main.py", line 42, in run_tool
result = tool.parse_result(raw_output) # <-- raises OutputParserException
File "/usr/local/lib/python3.9/site-packages/langchain_core/tool.py", line 88, in parse_result
raise OutputParserException(f"Could not parse tool result content: `{output}`") Why it happens
The computer use tool expects the LLM or tool output to strictly follow a predefined structured format such as JSON or a Pydantic schema. If the output contains extra text, markdown fences, or deviates from the expected schema, the parser raises OutputParserException. This often happens when the prompt or tool instructions do not enforce strict output formatting.
Detection
Catch OutputParserException when parsing tool results and log the raw output string to identify formatting mismatches before retrying or fallback handling.
Causes & fixes
The tool output includes markdown fences or extra explanatory text around the JSON result.
Modify the prompt to instruct the model to return only raw JSON without markdown fences, or use a parser that strips fences automatically.
The output JSON keys do not exactly match the expected schema field names (case-sensitive mismatch).
Align the expected schema field names with the output keys exactly, or update the prompt to produce matching keys.
Using a base LLM model that ignores strict output format instructions and adds extra text.
Switch to an instruction-tuned model like gpt-4o-mini or claude-3-5-haiku-20241022 that reliably follows output format instructions.
Code: broken vs fixed
from langchain_core.tools import ComputerUseTool
tool = ComputerUseTool()
raw_output = tool.run("open file.txt")
result = tool.parse_result(raw_output) # Raises OutputParserException here
print(result) import os
from langchain_core.tools import ComputerUseTool
from langchain_core.output_parsers import JsonOutputParser
os.environ["LANGCHAIN_API_KEY"] = os.environ.get("LANGCHAIN_API_KEY", "your_api_key_here")
tool = ComputerUseTool()
raw_output = tool.run("open file.txt")
parser = JsonOutputParser() # Added parser that strips fences and retries
result = parser.parse(raw_output)
print(result) # Now prints parsed dict without error Workaround
Wrap the parse call in try/except OutputParserException, then extract JSON substring manually using regex and parse with json.loads() as a fallback.
Prevention
Use structured output formats enforced at the API level, such as OpenAI's response_format or Anthropic's tool use, to guarantee schema-valid responses and avoid parser errors.