You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: action field returned as JSON string instead of list when done-text contains newlines (Claude Sonnet) #4510
Agent crashes on the final done step when the done-text contains
newlines (multi-line summaries, markdown tables).
Steps to reproduce:
Use ChatAnthropic with claude-sonnet-4-6
Run a task that produces a long multi-line summary (e.g. "log in and
describe all sections you see")
Agent navigates and clicks correctly, but crashes on the done step
Error: Input should be a valid list [type=list_type] or JSONDecodeError: Expecting ',' delimiter
Root cause: content_block.input['action'] is returned as a JSON string
instead of a list. The string contains literal chr(10) newlines inside
a JSON string value, which breaks json.loads().
Fix applied in our project: escape chr(10/13/9) before json.loads():
cleaned = action_str.replace(chr(10), chr(92)+'n')
_input['action'] = json.loads(cleaned)
Failing Python Code
frombrowser_useimportAgentfrombrowser_use.llm.anthropic.chatimportChatAnthropicagent=Agent(
task="Log into https://example.com with password 'test123'. ""Then describe all sections, menus and features you see ""in detail with a structured summary.",
llm=ChatAnthropic(model="claude-sonnet-4-6"),
max_steps=15,
)
history=awaitagent.run()
# Crashes at the done step when the summary contains newlines
LLM Model
claude-sonnet-4-6 via ChatAnthropic
Operating System & Browser Versions
Windows 11 + Chromium via CDP (browser-use automatic)
Full DEBUG Log Output
INFO [Agent] Task: Go to https://example.com/, log in, describe sections.
INFO [Agent] Step 3: done action with multi-line text
pydantic_core.ValidationError: 1 validation error for AgentOutput
action
Input should be a valid list [type=list_type]
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 3 column 45
We found a workaround that fixes the issue completely.
Root cause: The action string contains literal newline characters (chr(10))
inside the JSON string value. These are not valid in JSON strings, so
json.loads() fails with "Expecting ',' delimiter".
Fix applied in browser_use/llm/anthropic/chat.py, before model_validate():
if isinstance(_input, dict) and 'action' in _input and isinstance(_input['action'], str):
action_str = _input['action']
_parsed = False
# Stage 1: standard json.loads
try:
_input['action'] = json.loads(action_str)
_parsed = True
except (json.JSONDecodeError, TypeError):
pass
# Stage 2: escape literal control chars
if not _parsed:
try:
_BS = chr(92)
cleaned = action_str
cleaned = cleaned.replace(chr(10), _BS + 'n')
cleaned = cleaned.replace(chr(13), _BS + 'r')
cleaned = cleaned.replace(chr(9), _BS + 't')
_input['action'] = json.loads(cleaned)
_parsed = True
except (json.JSONDecodeError, TypeError):
pass
# Stage 3: synthetic done action as last resort
if not _parsed:
import re as _re
_m = _re.search(r'"done"\s*:\s*\{\s*"text"\s*:\s*"(.+)', action_str, _re.DOTALL)
raw_text = _m.group(1).rstrip('}' + chr(34) + ' ' + chr(9) + chr(10) + chr(13)) if _m else action_str
_input['action'] = [{'done': {'text': raw_text}}]
After this fix: agent completes successfully, done action returns full result.
Hi, I've been looking into this and traced the root cause.
Proposed approach: In browser_use/llm/anthropic/chat.py, before model_validate() is called, check if _input is a dict with an 'action' key whose value is a str. If so, sanitize the string by replacing literal newlines (\n, \r, \t) with their escaped equivalents before passing to json.loads(). This prevents the 'Expecting , delimiter' parse failure when Claude Sonnet includes newlines in done-text within the action JSON string.
I'll open a draft PR shortly. Happy to adjust based on your preference.
Activity
JNassar77 commentedon Mar 24, 2026
We found a workaround that fixes the issue completely.
Root cause: The action string contains literal newline characters (chr(10))
inside the JSON string value. These are not valid in JSON strings, so
json.loads() fails with "Expecting ',' delimiter".
Fix applied in browser_use/llm/anthropic/chat.py, before model_validate():
After this fix: agent completes successfully, done action returns full result.
majiayu000 commentedon Mar 25, 2026
Hi, I've been looking into this and traced the root cause.
Proposed approach: In browser_use/llm/anthropic/chat.py, before model_validate() is called, check if _input is a dict with an 'action' key whose value is a str. If so, sanitize the string by replacing literal newlines (\n, \r, \t) with their escaped equivalents before passing to json.loads(). This prevents the 'Expecting , delimiter' parse failure when Claude Sonnet includes newlines in done-text within the action JSON string.
I'll open a draft PR shortly. Happy to adjust based on your preference.
Fix JSONDecodeError when done-text contains literal newlines
fix anthropic action field double-serialization (browser-use#4529)