High severity intermediate · Fix: 2-5 min

OutputParserException

langchain_core.exceptions.OutputParserException

What this error means
LangChain's computer use tool returned output that does not match the expected structured format, causing parsing to fail.

Stack trace

traceback
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}`")
QUICK FIX
Add JsonOutputParser() with retry logic to automatically handle and retry parsing on malformed or fenced JSON 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

1

The tool output includes markdown fences or extra explanatory text around the JSON result.

✓ Fix

Modify the prompt to instruct the model to return only raw JSON without markdown fences, or use a parser that strips fences automatically.

2

The output JSON keys do not exactly match the expected schema field names (case-sensitive mismatch).

✓ Fix

Align the expected schema field names with the output keys exactly, or update the prompt to produce matching keys.

3

Using a base LLM model that ignores strict output format instructions and adds extra text.

✓ Fix

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

Broken - triggers the error
python
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)
Fixed - works correctly
python
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
Added JsonOutputParser() which automatically strips markdown fences and retries parsing malformed JSON, preventing OutputParserException.

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.

Python 3.9+ · langchain-core >=0.1.0 · tested on 0.2.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.