Skip to content

schema_dict_to_pydantic_model TypeError on JSON Schema type arrays → extract falls back to free-text #5904

Open

Description

@michaelkillgta

Description

Standard JSON Schema / OpenAPI nullable fields use "type": ["string", "null"] (and other type unions). In browser_use/tools/extraction/schema_utils.py, _resolve_type does _PRIMITIVE_MAP.get(json_type, str) when json_type is a list, which raises TypeError: unhashable type: 'list'.

extract() in browser_use/tools/service.py catches that TypeError and clears output_schema, falling back to free-text extraction. So Agent(extraction_schema=...) / extract(output_schema=...) never produce validated structured JSON for these common schemas.

The proprietary "nullable": true flag works; the standard type-array form does not.

Environment

  • browser-use==0.13.10
  • Offline unit repro (no live API / no browser)

Repro

from browser_use.tools.extraction.schema_utils import schema_dict_to_pydantic_model

schema = {
    "type": "object",
    "properties": {
        "nickname": {"type": ["string", "null"]},
    },
    "required": [],
}

try:
    schema_dict_to_pydantic_model(schema)
except TypeError as e:
    print(type(e).__name__, e)  # TypeError: unhashable type: 'list'

# Contrast: proprietary nullable flag works
ok = {
    "type": "object",
    "properties": {
        "nickname": {"type": "string", "nullable": True},
    },
}
model = schema_dict_to_pydantic_model(ok)
print(model.model_fields["nickname"].annotation)  # str | None

Observed (browser-use==0.13.10)

  • {"type": ["string", "null"]} → TypeError: unhashable type: 'list'
  • {"type": "string", "nullable": true} → builds str | None OK
  • Callers that catch TypeError silently drop structured extraction

Expected

JSON Schema type arrays (especially nullable unions with "null") should build a Pydantic model, same as "nullable": true.

Suggested fix

When type is a list, map each entry through _PRIMITIVE_MAP, treat "null" as optional (T | None), and handle other unions explicitly. Do not dict.get with a list key.

Impact

Any OpenAPI-exported or JSON-Schema-draft extraction schema with nullables silently loses structured mode; agents get unconstrained free text instead of schema-validated objects.

Happy to open a PR.

Activity

  1. leilei3167 commented on Sep 25, 2026

    @leilei3167
    Contributor

    Looking into this — will open a PR for JSON Schema type array / nullable union handling in _resolve_type.

  2. michaelkillgta commented on Sep 25, 2026

    @michaelkillgta
    Author

    Thanks @leilei3167 — please go ahead with the PR for type-array / nullable handling in _resolve_type. I won’t open a competing one.

  3. github-actions commented on Nov 25, 2026

    @github-actions

    👋 This issue has been automatically marked as stale because it hasn't had activity for 60 days.

    ⚡ We've made significant progress recently! Please test with the latest version of browser-use to see if this issue has been resolved. If the issue persists, please let us know by commenting below.

    To keep this issue open:

    • Add a comment explaining why this is still relevant after testing the latest version
    • Add the pinned label if this is an important long-term issue
    • Reference it in a PR if you're working on a fix

    This will be automatically closed in 14 days if no further activity occurs.

    Thanks for contributing to browser-use! 🤖 If you have questions, join our Discord.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions