Bug: ChatGoogle does not repair an action list Gemini returns as a JSON string, so the step fails validation and retries

Author: HardMax71Created Sep 25, 2026Updated Sep 25, 2026

Browser Use Version

0.13.10 and main at d8110c5 (same on 0.13.1)

Bug Description, Steps to Reproduce, Screenshots

With ChatGoogle, Gemini sometimes returns the action list of the agent output JSON-encoded as a string, typically when the done text is long multi-line markdown: {"thinking": ..., "action": "[{\"done\": {...}}]"}. ChatGoogle passes that straight to output_format.model_validate (chat.py#L446, and the text branches at #L416 and #L498), which fails with Input should be a valid list [type=list_type, input_value='[...', input_type=str]. The call ends as a ModelProviderError with status 502 and the agent retries the step (LLM error ... but no fallback_llm configured, then Result failed N/6 times), although the answer is complete.

ChatAnthropic repairs exactly this since #4529 (issue #4510): _repair_serialized_fields decodes string values that start with [ or { after a first validation failure (anthropic/chat.py#L287-L299), and the Bedrock client has the same loop (aws/chat_anthropic.py#L245). ChatGoogle has no equivalent.

The repro below is offline: a stub client returns a real GenerateContentResponse whose parsed payload has the list as a string.

Failing Python Code

python
import asyncio
import json
from importlib.metadata import version
from types import SimpleNamespace

from google.genai import types

from browser_use.agent.views import AgentOutput
from browser_use.llm.exceptions import ModelProviderError
from browser_use.llm.google.chat import ChatGoogle
from browser_use.llm.messages import UserMessage
from browser_use.tools.service import Tools

ACTION = [{"done": {"text": "## Status\nShipment A1 delivered.\n| a | b |", "success": True, "files_to_display": []}}]
PAYLOAD = {
    "thinking": "done",
    "evaluation_previous_goal": "ok",
    "memory": "m",
    "next_goal": "finish",
    "action": json.dumps(ACTION),  # the model double-encodes the list
}


async def main() -> None:
    print("browser-use", version("browser-use"), "google-genai", version("google-genai"))
    output_type = AgentOutput.type_with_custom_actions(Tools().registry.create_action_model())

    response = types.GenerateContentResponse(
        candidates=[
            types.Candidate(
                content=types.Content(role="model", parts=[types.Part(text=json.dumps(PAYLOAD))]),
                finish_reason=types.FinishReason.STOP,
            )
        ]
    )
    response.parsed = PAYLOAD

    calls = {"n": 0}

    async def generate_content(**kwargs):
        calls["n"] += 1
        return response

    llm = ChatGoogle(model="gemini-3-flash-preview", api_key="test", max_retries=1)
    llm.get_client = lambda: SimpleNamespace(aio=SimpleNamespace(models=SimpleNamespace(generate_content=generate_content)))
    try:
        out = await llm.ainvoke([UserMessage(content="continue")], output_format=output_type)
        print("parsed OK, action type:", type(out.completion.action).__name__)
    except ModelProviderError as e:
        print(f"ModelProviderError status={e.status_code}: {str(e.message).splitlines()[0]} | {str(e.message).splitlines()[2].strip()[:60]}")
    print("requests:", calls["n"])


asyncio.run(main())

LLM Model

gemini-3-flash-preview

Operating System & Browser Versions

macOS, Python 3.12, google-genai 1.65.0; no browser involved

Full DEBUG Log Output

browser-use 0.13.10 google-genai 1.65.0
ModelProviderError status=502: 1 validation error for AgentOutput | Input should be a valid list [type=list_type, input_value='[
requests: 1

Fix: apply the same repair in ChatGoogle: validate, and on a ValidationError decode string fields that start with [ or { (with the same control-character fallback) and validate again, in all three structured-output branches. PR follows.