Repository navigation
Conversation
…ON strings
Gemini sometimes returns a list field of the structured output, the AgentOutput action list typically, JSON-encoded as a string. ChatGoogle validated it as is, so the call failed with "Input should be a valid list" and the agent retried the step. On a ValidationError, ChatGoogle now decodes string fields that start with "[" or "{" (with the same control-character fallback as ChatAnthropic's _repair_serialized_fields) and validates again, in the native JSON, text and fallback JSON branches.
Fixes browser-use#5914
There was a problem hiding this comment.
2 issues found across 2 files
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
Fix all with cubic | Re-trigger cubic
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/ci/test_google_serialized_structured_output.py">
<violation number="1" location="tests/ci/test_google_serialized_structured_output.py:53">
P3: Every test only covers string fields that start with `[`, but `_validate_output` also decodes `{`-prefixed dict fields. Add a case where a dict-typed field (e.g., a nested object) arrives JSON-encoded as a string, so a regression in the dict decode path can't slip through.</violation>
</file>
<file name="browser_use/llm/google/chat.py">
<violation number="1" location="browser_use/llm/google/chat.py:251">
P3: `_validate_output` runs on any `ValidationError` and decodes every top-level string that starts with `[` or `{`, not just the fields that actually failed validation. A legitimately string-valued field (e.g., `thinking`) that happens to be bracket-leading and valid JSON gets decoded into a list/object when the real failure is elsewhere; the second `ValidationError` then reports the wrong field, masking the actual problem. Scope the repair to the failed field locations from the first `ValidationError` (`e.errors()` + `e.error_count()` locations, or decode only fields the schema declares as non-string).</violation>
</file>
The repair decoded every top-level string starting with [ or {, so a valid string field that happens to hold JSON (a bracket-leading thinking, say) was turned into a list or object and failed the second validation, even when the stringified action alone was the problem. It now decodes only the top-level fields named in the first ValidationError's locations. Tests cover that case and an object field arriving as a string.
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
Fix all with cubic | Re-trigger cubic
Covers the case the rejected-key set is built for: two fields JSON-encoded as strings at once.
…ir-serialized-fields
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
|
@gregpr07 could you review this when you get a chance? ChatGoogle decodes the structured-output fields Gemini returns as JSON strings. It's up to date with main, CI is green and the bot reviews are handled. |
Fixes #5914
Gemini sometimes returns a list field of the structured output, the
AgentOutputactionlist typically, JSON-encoded as a string.ChatGooglevalidated it as is, so the call failed withInput should be a valid listand the agent retried the step.ChatGooglenow validates through a small_validate_output: on aValidationErrorit decodes the top-level fields that validation rejected, when they are strings starting with[or{, with the same control-character fallbackChatAnthropic._repair_serialized_fieldsuses, and validates again. Fields that validated are left alone, so a string field that happens to hold JSON (a bracket-leadingthinking) stays a string. It covers all three structured-output branches (native JSON withresponse.parsed, native JSON parsed from text, and the fallback JSON mode). A payload that validates the first time is untouched, and a value that still does not decode fails as before.ChatAnthropicand the Bedrock client each carry the same loop, which decodes every bracket-leading field, not only the rejected ones. I kept this change toChatGooglesince several open PRs touch those files. Happy to move the three into one shared helper, with this narrower rule, in a follow-up if you want that.Testing:
tests/ci/test_google_serialized_structured_output.py(new, offline, stubbed client returning realGenerateContentResponseobjects): a stringifiedactionis decoded in each of the three branches, including one with a raw newline inside the JSON string; an object field arriving as a string is decoded; a valid bracket-leading string field next to a stringifiedactionis kept as a string; an undecodable string still raisesModelProviderError. The six decode cases fail onmain.tests/ci/models/test_llm_google.py,tests/ci/test_llm_retries.py,tests/ci/test_anthropic_serialized_tool_input.py,browser_use/llm/tests/test_gemini_image.pyplus the new file: all pass, 1 skipped (needsGOOGLE_API_KEY).pre-commit runon the changed files: all hooks pass. Merges clean with fix(llm/google): retry SDK-raised errors with retryable status codes #5651, the other open PR onllm/google/chat.py.parsed OK, action type: list,requests: 1.