High severity intermediate · Fix: 2-5 min

OutputParserException

langchain.schema.output_parser.OutputParserException

What this error means
The Browser Use action failed because the LLM output did not match the expected structured format required for parsing.

Stack trace

traceback
langchain_core.exceptions.OutputParserException: Could not parse LLM output: `{"url": "https://example.com", "content": "<html>...</html>"}`
  File "/app/browser_use_action.py", line 45, in parse_action
    result = parser.parse(llm_response)  # <-- triggers OutputParserException
  File "/usr/local/lib/python3.9/site-packages/langchain/schema/output_parser.py", line 112, in parse
    raise OutputParserException(f"Could not parse LLM output: `{text}`")
QUICK FIX
Use JsonOutputParser() which handles markdown fences and retries parsing automatically to fix most parse errors immediately.

Why it happens

Browser Use actions rely on the LLM to return output in a strict JSON or structured format. If the LLM returns extra text, markdown fences, or deviates from the expected schema, the output parser raises OutputParserException. This often happens when the prompt does not enforce strict formatting or when the model is not instruction-tuned.

Detection

Catch OutputParserException around the parsing call and log the raw LLM output to detect unexpected formatting before the error crashes the app.

Causes & fixes

1

LLM output includes markdown fences or extra explanatory text around the JSON response

✓ Fix

Update the prompt to instruct the LLM to return only raw JSON without markdown fences or extra text, or use a parser like JsonOutputParser that automatically strips fences.

2

The LLM returns fields or keys that do not match the expected schema exactly

✓ Fix

Ensure the prompt and the Pydantic or JSON schema used for parsing have matching field names and types, including case sensitivity.

3

Using a base LLM model that ignores output format instructions

✓ Fix

Switch to an instruction-tuned model such as 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.schema.output_parser import OutputParserException

llm_response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": prompt}]
)

# This line triggers OutputParserException if output format is wrong
result = parser.parse(llm_response.choices[0].message.content)
print(result)
Fixed - works correctly
python
import os
from langchain.schema.output_parser import OutputParserException
from langchain.output_parsers import JsonOutputParser
from openai import OpenAI

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

llm_response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": prompt}]
)

parser = JsonOutputParser()  # Changed to JsonOutputParser to handle markdown fences
try:
    result = parser.parse(llm_response.choices[0].message.content)
    print(result)  # Successfully parsed output
except OutputParserException as e:
    print(f"Parsing failed: {e}")  # Log and handle parse failure
Replaced generic parser with JsonOutputParser which strips markdown fences and retries parsing, and switched to an instruction-tuned model to ensure output format compliance.

Workaround

Wrap the parse call in try/except OutputParserException, then extract JSON manually from the raw LLM output using regex and parse it with json.loads() as a fallback.

Prevention

Use structured output features like OpenAI's response_format or Anthropic's tool use to enforce schema-valid responses at the API level, avoiding fragile post-processing parsing.

Python 3.9+ · langchain-core >=0.1.0 · tested on 0.2.x
Verified 2026-04 · gpt-4o-mini, claude-3-5-haiku-20241022
Verify ↗

Community Notes

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